Skip to content

Commit

Permalink
Documented Filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanta94 committed Jul 24, 2024
1 parent 73b4f5e commit 82e2d09
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/Uplink/Admin/Asset_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
7 changes: 7 additions & 0 deletions src/Uplink/Admin/Fields/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
7 changes: 7 additions & 0 deletions src/Uplink/Auth/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions src/Uplink/Resources/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?: '';
Expand Down
2 changes: 1 addition & 1 deletion src/Uplink/View/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
16 changes: 14 additions & 2 deletions src/views/admin/fields/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
use StellarWP\Uplink\Admin\Fields\Field;
?>

<?php do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_before_field', $field->get_slug() ); ?>
<?php
/**
* Fires before the field.
*
* @since TBD
*/
do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_before_field', $field->get_slug() );
?>
<?php if ( $field->should_show_label() ) : ?>
<table class="form-table" role="presentation">
<tr class="stellarwp-uplink-license-key-field">
Expand Down Expand Up @@ -45,5 +52,10 @@ class="regular-text stellarwp-uplink__settings-field"
</tr>
</table>
<?php endif; ?>
<?php do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_after_field', $field->get_slug() ); ?>
<?php
/**
* Fires after the field.
*
* @since TBD
*/
do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_after_field', $field->get_slug() );
18 changes: 16 additions & 2 deletions src/views/admin/fields/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
?>
<div class="stellarwp-uplink" data-js="stellarwp-uplink">
<div class="stellarwp-uplink__settings">
<?php do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_before_form' ); ?>
<?php
/**
* Fires before the form.
*
* @since TBD
*/
do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_before_form' );
?>
<form method="post" action="options.php">
<?php foreach ( $form->get_fields() as $field ) : ?>
<?php $field->render(); ?>
Expand All @@ -25,7 +32,14 @@
<?php submit_button( $form->get_button_text() );?>
<?php endif; ?>
</form>
<?php do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_after_form' ); ?>
<?php
/**
* Fires after the form.
*
* @since TBD
*/
do_action( 'stellarwp/uplink/' . Config::get_hook_prefix(). '/license_field_after_form' );
?>
</div>
</div>
<?php

0 comments on commit 82e2d09

Please sign in to comment.