From 82e2d09856ad8f61056db7a79d927e75e06b417a Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 24 Jul 2024 18:54:00 +0300 Subject: [PATCH] Documented Filters --- src/Uplink/Admin/Asset_Manager.php | 16 ++++++++++++++++ src/Uplink/Admin/Fields/Form.php | 7 +++++++ src/Uplink/Auth/Authorizer.php | 7 +++++++ src/Uplink/Resources/License.php | 11 +++++++++++ src/Uplink/View/Provider.php | 2 +- src/views/admin/fields/field.php | 16 ++++++++++++++-- src/views/admin/fields/form.php | 18 ++++++++++++++++-- 7 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/Uplink/Admin/Asset_Manager.php b/src/Uplink/Admin/Asset_Manager.php index a97da5d0..a288220b 100644 --- a/src/Uplink/Admin/Asset_Manager.php +++ b/src/Uplink/Admin/Asset_Manager.php @@ -24,13 +24,29 @@ public function __construct( string $assets_path ) { * @return void */ public function register_assets(): void { + /** + * Filters the JS source for the admin. + * + * @since TBD + * + * @param string $js_src The JS source. + */ $js_src = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/admin_js_source', $this->assets_path . '/js/key-admin.js' ); + wp_register_script( $this->handle, $js_src, [ 'jquery' ], '1.0.0', true ); $action_postfix = Config::get_hook_prefix_underscored(); wp_localize_script( $this->handle, sprintf( 'stellarwp_config_%s', $action_postfix ), [ 'action' => sprintf( 'pue-validate-key-uplink-%s', $action_postfix ) ] ); + /** + * Filters the CSS source for the admin. + * + * @since TBD + * + * @param string $css_src The CSS source. + */ $css_src = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/admin_css_source', $this->assets_path . '/css/main.css' ); + wp_register_style( $this->handle, $css_src ); } diff --git a/src/Uplink/Admin/Fields/Form.php b/src/Uplink/Admin/Fields/Form.php index 69159e89..4e8670e0 100644 --- a/src/Uplink/Admin/Fields/Form.php +++ b/src/Uplink/Admin/Fields/Form.php @@ -85,6 +85,13 @@ public function get_render_html(): string { $args = [ 'form' => $this ]; $html = $this->view->render( self::VIEW, $args ); + /** + * Filters the form HTML. + * + * @since TBD + * + * @param string $html The form HTML. + */ return apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/license_form_html', $html ); } diff --git a/src/Uplink/Auth/Authorizer.php b/src/Uplink/Auth/Authorizer.php index d1ea15bc..78609fd4 100644 --- a/src/Uplink/Auth/Authorizer.php +++ b/src/Uplink/Auth/Authorizer.php @@ -17,6 +17,13 @@ final class Authorizer { * @return bool */ public function can_auth(): bool { + /** + * Filters if the current user can perform an action. + * + * @since TBD + * + * @param bool $can_auth Whether the current user can perform an action. + */ return (bool) apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/auth/can_auth', is_super_admin() diff --git a/src/Uplink/Resources/License.php b/src/Uplink/Resources/License.php index d5abee7a..ea8fc185 100644 --- a/src/Uplink/Resources/License.php +++ b/src/Uplink/Resources/License.php @@ -159,6 +159,17 @@ public function get_key( $type = 'any' ) { * @param Resource $resource The resource instance. */ $key = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_get_key', $this->key, $this->resource ); + + /** + * Filter the license key. + * + * Accepts the resource's slug dynamically. + * + * @since TBD + * + * @param string|null $key The license key. + * @param Resource $resource The resource instance. + */ $key = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/' . $this->resource->get_slug() . '/license_get_key', $key, $this->resource ); return $key ?: ''; diff --git a/src/Uplink/View/Provider.php b/src/Uplink/View/Provider.php index e7fc711c..a5ecfdc9 100644 --- a/src/Uplink/View/Provider.php +++ b/src/Uplink/View/Provider.php @@ -13,7 +13,7 @@ final class Provider extends Abstract_Provider { public function register() { $this->container->singleton( WordPress_View::class, - new WordPress_View( __DIR__ . '/../../views', '.php' ) + new WordPress_View( __DIR__ . '/../../views' ) ); $this->container->bind( View::class, $this->container->get( WordPress_View::class ) ); diff --git a/src/views/admin/fields/field.php b/src/views/admin/fields/field.php index 5f2a667a..bfba4f05 100644 --- a/src/views/admin/fields/field.php +++ b/src/views/admin/fields/field.php @@ -8,7 +8,14 @@ use StellarWP\Uplink\Admin\Fields\Field; ?> -get_slug() ); ?> +get_slug() ); +?> should_show_label() ) : ?> @@ -45,5 +52,10 @@ class="regular-text stellarwp-uplink__settings-field" -get_slug() ); ?> get_slug() ); diff --git a/src/views/admin/fields/form.php b/src/views/admin/fields/form.php index 4248d297..fcc28cfa 100644 --- a/src/views/admin/fields/form.php +++ b/src/views/admin/fields/form.php @@ -16,7 +16,14 @@ ?>