Skip to content

Commit e0ce678

Browse files
committed
Add amp-onboarding-wizard submenu page on amp-options menu
1 parent 1e8de9a commit e0ce678

3 files changed

Lines changed: 8 additions & 19 deletions

File tree

src/Admin/OnboardingWizardSubmenu.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ public static function get_registration_action() {
3939
* Runs on instantiation.
4040
*/
4141
public function register() {
42+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not needed here.
43+
if ( ! isset( $_GET['page'] ) || self::SCREEN_ID !== $_GET['page'] ) {
44+
return;
45+
}
46+
4247
add_submenu_page(
43-
'',
48+
'amp-options',
4449
__( 'AMP Onboarding Wizard', 'amp' ),
4550
__( 'AMP Onboarding Wizard', 'amp' ),
4651
'manage_options',

src/Admin/OnboardingWizardSubmenuPage.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,6 @@ public static function get_registration_action() {
114114
public function register() {
115115
add_action( 'admin_head-' . $this->screen_handle(), [ $this, 'override_template' ] );
116116
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
117-
add_filter( 'admin_title', [ $this, 'override_title' ] );
118-
}
119-
120-
/**
121-
* Overrides the admin title on the wizard screen. Without this filter, the title portion would be empty.
122-
*
123-
* @param string $admin_title The unfiltered admin title.
124-
* @return string If on the wizard screen, the admin title with the page title prepended.
125-
*/
126-
public function override_title( $admin_title ) {
127-
if ( $this->screen_handle() !== get_current_screen()->id ) {
128-
return $admin_title;
129-
}
130-
131-
return esc_html__( 'AMP Onboarding Wizard', 'amp' ) . $admin_title;
132117
}
133118

134119
/**
@@ -182,7 +167,7 @@ public function render() {
182167
* @return string
183168
*/
184169
public function screen_handle() {
185-
return sprintf( 'admin_page_%s', OnboardingWizardSubmenu::SCREEN_ID );
170+
return sprintf( 'amp_page_%s', OnboardingWizardSubmenu::SCREEN_ID );
186171
}
187172

188173
/**

tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public function test_register() {
8888

8989
$this->assertEquals( 10, has_action( 'admin_head-admin_page_amp-onboarding-wizard', [ $this->onboarding_wizard_submenu_page, 'override_template' ] ) );
9090
$this->assertEquals( 10, has_action( 'admin_enqueue_scripts', [ $this->onboarding_wizard_submenu_page, 'enqueue_assets' ] ) );
91-
$this->assertEquals( 10, add_filter( 'admin_title', [ $this->onboarding_wizard_submenu_page, 'override_title' ] ) );
9291
}
9392

9493
/**
@@ -128,7 +127,7 @@ public function test_render() {
128127
* @covers ::screen_handle()
129128
*/
130129
public function test_screen_handle() {
131-
$this->assertEquals( $this->onboarding_wizard_submenu_page->screen_handle(), 'admin_page_amp-onboarding-wizard' );
130+
$this->assertEquals( $this->onboarding_wizard_submenu_page->screen_handle(), 'amp_page_amp-onboarding-wizard' );
132131
}
133132

134133
/** @return array */

0 commit comments

Comments
 (0)