From e0ce678af237e265ca3fb6e1ff536a0c0ce6183a Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Tue, 12 Sep 2023 19:20:50 +0530 Subject: [PATCH] Add amp-onboarding-wizard submenu page on amp-options menu --- src/Admin/OnboardingWizardSubmenu.php | 7 ++++++- src/Admin/OnboardingWizardSubmenuPage.php | 17 +---------------- .../Admin/OnboardingWizardSubmenuPageTest.php | 3 +-- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/Admin/OnboardingWizardSubmenu.php b/src/Admin/OnboardingWizardSubmenu.php index dbe3a29adc4..deda84e6fbf 100644 --- a/src/Admin/OnboardingWizardSubmenu.php +++ b/src/Admin/OnboardingWizardSubmenu.php @@ -39,8 +39,13 @@ public static function get_registration_action() { * Runs on instantiation. */ public function register() { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not needed here. + if ( ! isset( $_GET['page'] ) || self::SCREEN_ID !== $_GET['page'] ) { + return; + } + add_submenu_page( - '', + 'amp-options', __( 'AMP Onboarding Wizard', 'amp' ), __( 'AMP Onboarding Wizard', 'amp' ), 'manage_options', diff --git a/src/Admin/OnboardingWizardSubmenuPage.php b/src/Admin/OnboardingWizardSubmenuPage.php index edb1a7a7e22..97eafb235d5 100644 --- a/src/Admin/OnboardingWizardSubmenuPage.php +++ b/src/Admin/OnboardingWizardSubmenuPage.php @@ -114,21 +114,6 @@ public static function get_registration_action() { public function register() { add_action( 'admin_head-' . $this->screen_handle(), [ $this, 'override_template' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); - add_filter( 'admin_title', [ $this, 'override_title' ] ); - } - - /** - * Overrides the admin title on the wizard screen. Without this filter, the title portion would be empty. - * - * @param string $admin_title The unfiltered admin title. - * @return string If on the wizard screen, the admin title with the page title prepended. - */ - public function override_title( $admin_title ) { - if ( $this->screen_handle() !== get_current_screen()->id ) { - return $admin_title; - } - - return esc_html__( 'AMP Onboarding Wizard', 'amp' ) . $admin_title; } /** @@ -182,7 +167,7 @@ public function render() { * @return string */ public function screen_handle() { - return sprintf( 'admin_page_%s', OnboardingWizardSubmenu::SCREEN_ID ); + return sprintf( 'amp_page_%s', OnboardingWizardSubmenu::SCREEN_ID ); } /** diff --git a/tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php b/tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php index b24e354f452..140cf0bcbdb 100644 --- a/tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php +++ b/tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php @@ -88,7 +88,6 @@ public function test_register() { $this->assertEquals( 10, has_action( 'admin_head-admin_page_amp-onboarding-wizard', [ $this->onboarding_wizard_submenu_page, 'override_template' ] ) ); $this->assertEquals( 10, has_action( 'admin_enqueue_scripts', [ $this->onboarding_wizard_submenu_page, 'enqueue_assets' ] ) ); - $this->assertEquals( 10, add_filter( 'admin_title', [ $this->onboarding_wizard_submenu_page, 'override_title' ] ) ); } /** @@ -128,7 +127,7 @@ public function test_render() { * @covers ::screen_handle() */ public function test_screen_handle() { - $this->assertEquals( $this->onboarding_wizard_submenu_page->screen_handle(), 'admin_page_amp-onboarding-wizard' ); + $this->assertEquals( $this->onboarding_wizard_submenu_page->screen_handle(), 'amp_page_amp-onboarding-wizard' ); } /** @return array */