Skip to content

Commit

Permalink
Improved the pagespeed of the control panel
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Mar 15, 2024
1 parent 5ddce8a commit 7eae84d
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 72 deletions.
2 changes: 1 addition & 1 deletion assets/admin/settings.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'baa09cc5199cdd5a4c88');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'b0e6f10569c2ee812f9e');
2 changes: 1 addition & 1 deletion assets/admin/settings.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/admin/settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/admin/wizard.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '255eecb819a4fc7efdfc');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'dd644c94009f73f7d662');
2 changes: 1 addition & 1 deletion assets/admin/wizard.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/admin/wizard.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions inc/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ function gtmkit_admin_init(): void {

Analytics::register( $options, $util );
MetaBox::register( $options );
SetupWizard::register();
GeneralOptionsPage::register();
IntegrationsOptionsPage::register();
TemplatesOptionsPage::register();
HelpOptionsPage::register();
SetupWizard::register( $options, $util );
GeneralOptionsPage::register( $options, $util );
IntegrationsOptionsPage::register( $options, $util );
TemplatesOptionsPage::register( $options, $util );
HelpOptionsPage::register( $options, $util );

do_action( 'gtmkit_admin_init', $options, $util );
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Find out about what's new in our [our release post](https://gtmkit.com/gtm-kit-1
* Added a new section for GTM templates that you can use to configure the necessary Tags, Triggers and Variables in Google Tag Manager.
* Added support for the 'new_customer' parameter on the 'purchase' event, which is used for customer acquisition reporting and Google Smart Shopping campaigns.
* Added a debug log for debugging the 'purchase' event without make a purchase.
* Improved the pagespeed of the control panel. The control panel is now loading significantly faster than before.

#### Bugfixes:

Expand Down
30 changes: 26 additions & 4 deletions src/Admin/AbstractOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,39 @@ abstract class AbstractOptionsPage {
*/
protected $option_name = 'gtmkit';

/**
* Plugin options.
*
* @var Options
*/
protected $options;

/**
* Utilities
*
* @var Util
*/
protected $util;

/**
* Constructor.
*
* @param Options $options An instance of Options.
* @param Util $util An instance of Util.
*/
final public function __construct() {
final public function __construct( Options $options, Util $util ) {
$this->options = $options;
$this->util = $util;
}

/**
* Register the options page.
* Register frontend
*
* @param Options $options The Options instance.
* @param Util $util The Util instance.
*/
public static function register(): void {
$page = new static();
public static function register( Options $options, Util $util ): void {
$page = new static( $options, $util );

add_action( 'admin_init', [ $page, 'configure' ] );
add_action( 'admin_menu', [ $page, 'add_admin_page' ] );
Expand Down
53 changes: 0 additions & 53 deletions src/Admin/AdminAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,6 @@ public function rest_init() {
* @return void
*/
public function register_rest_routes(): void {
$this->util->rest_api_server->register_rest_route(
'/get-install-data',
[
'methods' => 'GET',
'callback' => [ $this, 'get_install_data' ],
]
);

$this->util->rest_api_server->register_rest_route(
'/get-options',
[
'methods' => 'GET',
'callback' => [ $this, 'get_options' ],
]
);

$this->util->rest_api_server->register_rest_route(
'/set-options',
[
Expand All @@ -82,14 +66,6 @@ public function register_rest_routes(): void {
]
);

$this->util->rest_api_server->register_rest_route(
'/get-site-data',
[
'methods' => 'GET',
'callback' => [ $this, 'get_site_data' ],
]
);

$this->util->rest_api_server->register_rest_route(
'/send-support-data',
[
Expand All @@ -115,25 +91,6 @@ public function permission_callback() {
return true;
}

/**
* Get install data
*
* @return void
*/
public function get_install_data(): void {
$other_plugin_settings = ( new PluginDataImport() )->get_all();
wp_send_json_success( $other_plugin_settings );
}

/**
* Get options
*
* @return void
*/
public function get_options(): void {
wp_send_json_success( $this->options->get_all_raw() );
}

/**
* Set options
*
Expand All @@ -146,16 +103,6 @@ public function set_options(): void {
wp_send_json_success( $this->options->get_all_raw() );
}

/**
* Get site data
*
* @return void
*/
public function get_site_data(): void {
$site_data = $this->util->get_site_data( $this->options->get_all_raw() );
wp_send_json_success( $site_data );
}

/**
* Send Support Data
*
Expand Down
2 changes: 2 additions & 0 deletions src/Admin/GeneralOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'nonce' => \wp_create_nonce( 'wp_rest' ),
'dashboardUrl' => \menu_page_url( 'gtmkit_general', false ),
'integrationsUrl' => \menu_page_url( 'gtmkit_integrations', false ),
'settings' => $this->options->get_all_raw(),
'site_data' => $this->util->get_site_data( $this->options->get_all_raw() ),
]
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Admin/HelpOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'nonce' => \wp_create_nonce( 'wp_rest' ),
'dashboardUrl' => \menu_page_url( 'gtmkit_general', false ),
'integrationsUrl' => \menu_page_url( 'gtmkit_integrations', false ),
'settings' => $this->options->get_all_raw(),
]
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Admin/IntegrationsOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'edd' => ( \is_plugin_active( 'easy-digital-downloads/easy-digital-downloads.php' ) || \is_plugin_active( 'easy-digital-downloads-pro/easy-digital-downloads.php' ) ),
],
'taxonomyOptions' => $taxonomy_options,
'settings' => $this->options->get_all_raw(),
]
);
}
Expand Down
37 changes: 34 additions & 3 deletions src/Admin/SetupWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,38 @@ final class SetupWizard {
const SLUG = 'gtmkit_setup_wizard';

/**
* Register the setup wizard.
* Plugin options.
*
* @var Options
*/
protected $options;

/**
* Utilities
*
* @var Util
*/
protected $util;

/**
* Constructor.
*
* @param Options $options An instance of Options.
* @param Util $util An instance of Util.
*/
public function __construct( Options $options, Util $util ) {
$this->options = $options;
$this->util = $util;
}

/**
* Register frontend
*
* @param Options $options The Options instance.
* @param Util $util The Util instance.
*/
public static function register(): void {
$page = new SetupWizard();
public static function register( Options $options, Util $util ): void {
$page = new SetupWizard( $options, $util );

add_action( 'admin_init', [ $page, 'maybe_redirect_after_activation' ], 9999 );
add_action( 'admin_menu', [ $page, 'add_dashboard_page' ], 20 );
Expand Down Expand Up @@ -117,6 +145,9 @@ public function enqueue_assets( string $hook ) {
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'dashboardUrl' => menu_page_url( 'gtmkit_general', false ),
'settings' => $this->options->get_all_raw(),
'site_data' => $this->util->get_site_data( $this->options->get_all_raw() ),
'install_data' => ( new PluginDataImport() )->get_all(),
]
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Admin/TemplatesOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'dashboardUrl' => \menu_page_url( 'gtmkit_general', false ),
'integrationsUrl' => \menu_page_url( 'gtmkit_integrations', false ),
'templatesUrl' => \menu_page_url( 'gtmkit_templates', false ),
'settings' => $this->options->get_all_raw(),
]
);
}
Expand Down

0 comments on commit 7eae84d

Please sign in to comment.