Skip to content

Commit

Permalink
Admin Menu: Keep Plugins submenus when they link to WP Admin (#18917)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtr authored Feb 24, 2021
1 parent 05d2988 commit 3eaa2c3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,13 @@ public function add_plugins_menu( $wp_admin = false ) {
$menu_slug = $wp_admin ? 'plugins.php' : 'https://wordpress.com/plugins/' . $this->domain;

remove_menu_page( 'plugins.php' );
remove_submenu_page( 'plugins.php', 'plugins.php' );
remove_submenu_page( 'plugins.php', 'plugin-install.php' );
remove_submenu_page( 'plugins.php', 'plugin-editor.php' );

// Keep submenus when links point to WP Admin.
if ( ! $wp_admin ) {
remove_submenu_page( 'plugins.php', 'plugins.php' );
remove_submenu_page( 'plugins.php', 'plugin-install.php' );
remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
}

$count = '';
if ( ! is_multisite() && current_user_can( 'update_plugins' ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,14 @@ public function add_appearance_menu( $wp_admin_themes = false, $wp_admin_customi
// Customize on Atomic sites is always done on Jetpack sites.
parent::add_appearance_menu( $wp_admin_themes, true );
}

/**
* Adds Plugins menu.
*
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso).
*/
public function add_plugins_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// Plugins on Jetpack sites are always managed on Calypso.
parent::add_plugins_menu( false );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,14 @@ public function should_link_to_wp_admin() {

return $result;
}

/**
* Adds Plugins menu.
*
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso).
*/
public function add_plugins_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// Plugins on Simple sites are always managed on Calypso.
parent::add_plugins_menu( false );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ public function test_add_plugins_menu() {
$this->assertEquals( $plugins_menu_item, $menu[65] );
$this->assertEmpty( $submenu['plugins.php'] );
$this->assertArrayNotHasKey( $slug, $submenu );

// Reset.
$menu = static::$menu_data;
$submenu = static::$submenu_data;

// Check submenu are kept when using WP Admin links.
static::$admin_menu->add_plugins_menu( true );
$this->assertNotEmpty( $submenu['plugins.php'] );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,18 @@ public function test_add_appearance_menu() {
);
$this->assertContains( $customize_submenu_item, $submenu[ $slug ] );
}

/**
* Tests add_plugins_menu
*
* @covers ::add_plugins_menu
*/
public function test_add_plugins_menu() {
global $menu;

static::$admin_menu->add_plugins_menu( true );

// Check Plugins menu always links to Calypso.
$this->assertContains( 'https://wordpress.com/plugins/' . static::$domain, $menu[65] );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,18 @@ public function test_add_gutenberg_menus() {
);
$this->assertSame( $menu[61], $fse_menu );
}

/**
* Tests add_plugins_menu
*
* @covers ::add_plugins_menu
*/
public function test_add_plugins_menu() {
global $menu;

static::$admin_menu->add_plugins_menu( true );

// Check Plugins menu always links to Calypso.
$this->assertContains( 'https://wordpress.com/plugins/' . static::$domain, $menu[65] );
}
}

0 comments on commit 3eaa2c3

Please sign in to comment.