Skip to content

Commit

Permalink
Use single admin page base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Sep 12, 2024
1 parent 9d74be8 commit 3aef4b7
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 43 deletions.
23 changes: 11 additions & 12 deletions src/Admin/GeneralOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,17 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'gtmkit-' . $script_handle . '-script',
'gtmkitSettings',
[
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'tutorials' => $this->get_tutorials(),
'integrations' => Integrations::get_integrations(),
'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() ),
'user_roles' => $this->get_user_roles(),
'notifications' => $this->get_notifications(),
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'tutorials' => $this->get_tutorials(),
'integrations' => Integrations::get_integrations(),
'adminURL' => $this->util->get_admin_page_url(),
'settings' => $this->options->get_all_raw(),
'site_data' => $this->util->get_site_data( $this->options->get_all_raw() ),
'user_roles' => $this->get_user_roles(),
'notifications' => $this->get_notifications(),
]
);
}
Expand Down
19 changes: 9 additions & 10 deletions src/Admin/HelpOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'gtmkit-' . $script_handle . '-script',
'gtmkitSettings',
[
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'tutorials' => $this->get_tutorials(),
'dashboardUrl' => \menu_page_url( 'gtmkit_general', false ),
'integrationsUrl' => \menu_page_url( 'gtmkit_integrations', false ),
'settings' => $this->options->get_all_raw(),
'site_data' => [ 'gtmkit_version' => GTMKIT_VERSION ],
'isPremium' => ( new PremiumConditional() )->is_met(),
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'tutorials' => $this->get_tutorials(),
'adminURL' => $this->util->get_admin_page_url(),
'settings' => $this->options->get_all_raw(),
'site_data' => [ 'gtmkit_version' => GTMKIT_VERSION ],
'isPremium' => ( new PremiumConditional() )->is_met(),
]
);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Admin/IntegrationsOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'nonce' => \wp_create_nonce( 'wp_rest' ),
'isPremium' => ( new PremiumConditional() )->is_met(),
'integrations' => Integrations::get_integrations(),
'dashboardUrl' => \menu_page_url( 'gtmkit_general', false ),
'integrationsUrl' => \menu_page_url( 'gtmkit_integrations', false ),
'templatesUrl' => \menu_page_url( 'gtmkit_templates', false ),
'pluginInstallUrl' => $admin_url . 'plugin-install.php?tab=search&type=term&s=',
'adminPageUrl' => $this->util->get_admin_page_url(),
'pluginInstallUrl' => $this->util->get_plugin_install_url(),
'plugins' => $this->get_plugins(),
'taxonomyOptions' => $taxonomy_options,
'settings' => $this->options->get_all_raw(),
Expand Down
1 change: 1 addition & 0 deletions src/Admin/SetupWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function enqueue_assets( string $hook ): void {
'currentPage' => 'wizard',
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'adminURL' => $this->util->get_admin_page_url(),
'dashboardUrl' => menu_page_url( 'gtmkit_general', false ),
'templatesUrl' => menu_page_url( 'gtmkit_templates', false ),
'helpUrl' => menu_page_url( 'gtmkit_help', false ),
Expand Down
16 changes: 7 additions & 9 deletions src/Admin/TemplatesOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,13 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'gtmkit-' . $script_handle . '-script',
'gtmkitSettings',
[
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'templates' => $this->get_templates(),
'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(),
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'templates' => $this->get_templates(),
'adminURL' => $this->util->get_admin_page_url(),
'settings' => $this->options->get_all_raw(),
]
);
}
Expand Down
15 changes: 7 additions & 8 deletions src/Admin/UpgradesOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'gtmkit-' . $script_handle . '-script',
'gtmkitSettings',
[
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'opportunities' => $this->get_upgrade_opportunities(),
'dashboardUrl' => \menu_page_url( 'gtmkit_general', false ),
'integrationsUrl' => \menu_page_url( 'gtmkit_integrations', false ),
'settings' => $this->options->get_all_raw(),
'rootId' => 'gtmkit-settings',
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'opportunities' => $this->get_upgrade_opportunities(),
'adminURL' => $this->util->get_admin_page_url(),
'settings' => $this->options->get_all_raw(),
]
);
}
Expand Down
27 changes: 27 additions & 0 deletions src/Common/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,31 @@ public function normalize_and_hash_email_address(
}
return $this->normalize_and_hash( $hash_algorithm, $normalized_email, true );
}

/**
* Get admin page base URL
*
* @return string
*/
public function get_admin_page_url(): string {
return $this->get_admin_url() . 'admin.php?page=gtmkit_';
}

/**
* Get the plugin install URL
*
* @return string
*/
public function get_plugin_install_url(): string {
return $this->get_admin_url() . 'plugin-install.php?tab=search&type=term&s=';
}

/**
* Get admin url
*
* @return string
*/
private function get_admin_url(): string {
return is_network_admin() ? network_admin_url() : admin_url();
}
}

0 comments on commit 3aef4b7

Please sign in to comment.