Skip to content

Commit

Permalink
Add amp-onboarding-wizard submenu page on amp-options menu
Browse files Browse the repository at this point in the history
  • Loading branch information
thelovekesh committed Sep 12, 2023
1 parent 1e8de9a commit e0ce678
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
7 changes: 6 additions & 1 deletion src/Admin/OnboardingWizardSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 1 addition & 16 deletions src/Admin/OnboardingWizardSubmenuPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] ) );

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 8.0, WP latest

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 7.4, WP latest

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 8.0, WP trunk

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 8.0, WP latest

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 7.4, WP latest

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 7.4, WP 5.3

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 8.1, WP trunk

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 7.4, WP 5.3

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test: PHP 8.2, WP trunk

Failed asserting that false matches expected 10.

Check failure on line 89 in tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

View workflow job for this annotation

GitHub Actions / Unit test (with coverage): PHP 8.0, WP latest

Failed asserting that false matches expected 10.
$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' ] ) );
}

/**
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit e0ce678

Please sign in to comment.