Skip to content

Commit

Permalink
enqueue assets with uplink uri, remove non php 7.1 code.
Browse files Browse the repository at this point in the history
  • Loading branch information
defunctl committed Nov 29, 2023
1 parent 3efbf22 commit f806839
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/Uplink/Admin/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ abstract class Field {
*
* @var string
*/
protected string $path = '';
protected $path = '';

/**
* @since 1.0.0
*
* @return void
*/
abstract public function register_settings();
abstract public function register_settings(): void;

/**
* @param array<string> $args
*
* @return void
*/
public function get_description( array $args = [] ) {
public function get_description( array $args = [] ): void {
if ( empty( $args['description'] ) ) {
return;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public function get_group_name( string $group_modifier = '' ) : string {
*
* @return void
*/
public function field_html( array $args = [] ) {
public function field_html( array $args = [] ): void {
$field = sprintf(
'<div class="%6$s" id="%2$s" data-slug="%2$s" data-plugin="%9$s" data-plugin-slug="%10$s">
<fieldset class="stellarwp-uplink__settings-group">
Expand Down Expand Up @@ -112,7 +112,7 @@ public function add_nonce_field() : string {
*
* @return void
*/
abstract public function render( bool $show_title = true, bool $show_button = true );
abstract public function render( bool $show_title = true, bool $show_button = true ): void;

/**
* @param array<mixed> $context
Expand Down Expand Up @@ -155,11 +155,11 @@ protected function get_plugin() {
* @since 1.0.0
*
* @param string $page Slug title of the admin page whose settings fields you want to show.
* @param string $page Slug title of the admin page whose settings fields you want to show.
* @param string $section Slug title of the settings section whose fields you want to show.
* @param string $plugin_slug Slug title of the settings section whose fields you want to show.
* @param bool $show_title Whether to show the title or not.
*/
public function do_settings_fields( string $page, string $section, string $plugin_slug, bool $show_title = true ) {
public function do_settings_fields( string $page, string $section, string $plugin_slug, bool $show_title = true ): void {
global $wp_settings_fields;

if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
Expand Down
18 changes: 11 additions & 7 deletions src/Uplink/Admin/License_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
use StellarWP\Uplink\Config;
use StellarWP\Uplink\Resources\Collection;
use StellarWP\Uplink\Resources\Plugin;
use StellarWP\Uplink\Uplink;

class License_Field extends Field {

public const LICENSE_FIELD_ID = 'stellarwp_uplink_license';

protected string $path = '/admin-views/fields/settings.php';
/**
* @var string
*/
protected $path = '/admin-views/fields/settings.php';

/**
* @param Plugin $plugin
Expand All @@ -26,7 +30,7 @@ public function get_section_name( Plugin $plugin ) : string {
*
* @return void
*/
public function register_settings() {
public function register_settings(): void {
$collection = Config::get_container()->get( Collection::class );
$plugin = $collection->current();

Expand Down Expand Up @@ -77,7 +81,7 @@ public function get_field_html( Plugin $plugin ) : string {
/**
* @inheritDoc
*/
public function render( bool $show_title = true, bool $show_button = true ) {
public function render( bool $show_title = true, bool $show_button = true ): void {
echo $this->get_content( [
'plugin' => $this->get_plugin(),
'show_title' => $show_title,
Expand All @@ -90,16 +94,16 @@ public function render( bool $show_title = true, bool $show_button = true ) {
*
* @return void
*/
public function enqueue_assets() {
public function enqueue_assets(): void {
$path = Config::get_container()->get( Uplink::UPLINK_ASSETS_URI );
$handle = sprintf( 'stellarwp-uplink-license-admin-%s', Config::get_hook_prefix() );
$path = preg_replace( '/.*\/vendor/', plugin_dir_url( $this->get_plugin()->get_path() ) . 'vendor', dirname( __DIR__, 2 ) );
$js_src = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/admin_js_source', $path . '/assets/js/key-admin.js' );
$js_src = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/admin_js_source', $path . '/js/key-admin.js' );
wp_register_script( $handle, $js_src, [ 'jquery' ], '1.0.0', true );
wp_enqueue_script( $handle );
$action_postfix = Config::get_hook_prefix_underscored();
wp_localize_script( $handle, sprintf( 'stellarwp_config_%s', $action_postfix ), [ 'action' => sprintf( 'pue-validate-key-uplink-%s', $action_postfix ) ] );

$css_src = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/admin_css_source', $path . '/assets/css/main.css' );
$css_src = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/admin_css_source', $path . '/css/main.css' );
wp_enqueue_style( $handle, $css_src );
}
}

0 comments on commit f806839

Please sign in to comment.