From 3b591dfc9d13c8977128ae49a2390c53d5fb57dd Mon Sep 17 00:00:00 2001 From: LuPuS2k Date: Thu, 25 Jul 2024 13:47:25 -0300 Subject: [PATCH] Remove Browse Sites from sidebar --- .../admin-menu/class-atomic-admin-menu.php | 16 -------- .../src/admin-menu/class-wpcom-admin-menu.php | 15 -------- .../php/test-class-atomic-admin-menu.php | 35 ------------------ .../test-class-atomic-admin-menu.php | 37 ------------------- .../masterbar/test-class-wpcom-admin-menu.php | 37 ------------------- 5 files changed, 140 deletions(-) diff --git a/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php b/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php index b2db5e2021d30..1bca10c709fd5 100644 --- a/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php +++ b/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php @@ -85,7 +85,6 @@ public function reregister_menu_items() { // Not needed outside of wp-admin. if ( ! $this->is_api_request ) { - $this->add_browse_sites_link(); $this->add_site_card_menu(); $this->add_new_site_link(); } @@ -194,21 +193,6 @@ function_exists( 'wpcom_site_has_feature' ) && $this->update_submenus( 'plugins.php', $submenus_to_update ); } - /** - * Adds the site switcher link if user has more than one site. - */ - public function add_browse_sites_link() { - $site_count = get_user_option( 'wpcom_site_count' ); - if ( ! $site_count || $site_count < 2 ) { - return; - } - - // Add the menu item. - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. - add_menu_page( __( 'site-switcher', 'jetpack-masterbar' ), __( 'Browse sites', 'jetpack-masterbar' ), 'read', 'https://wordpress.com/sites', null, 'dashicons-arrow-left-alt2', 0 ); - add_filter( 'add_menu_classes', array( $this, 'set_browse_sites_link_class' ) ); - } - /** * Adds a custom element class for Site Switcher menu item. * diff --git a/projects/packages/masterbar/src/admin-menu/class-wpcom-admin-menu.php b/projects/packages/masterbar/src/admin-menu/class-wpcom-admin-menu.php index 764163b0cec5e..7721b5b3fc19a 100644 --- a/projects/packages/masterbar/src/admin-menu/class-wpcom-admin-menu.php +++ b/projects/packages/masterbar/src/admin-menu/class-wpcom-admin-menu.php @@ -50,7 +50,6 @@ public function reregister_menu_items() { // Not needed outside of wp-admin. if ( ! $this->is_api_request ) { - $this->add_browse_sites_link(); $this->add_site_card_menu(); $this->add_new_site_link(); } @@ -102,20 +101,6 @@ public function get_current_user_blog_count() { return is_countable( $blogs ) ? count( $blogs ) : 0; } - /** - * Adds the site switcher link if user has more than one site. - */ - public function add_browse_sites_link() { - if ( $this->get_current_user_blog_count() < 2 ) { - return; - } - - // Add the menu item. - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. - add_menu_page( __( 'site-switcher', 'jetpack-masterbar' ), __( 'Browse sites', 'jetpack-masterbar' ), 'read', 'https://wordpress.com/sites', null, 'dashicons-arrow-left-alt2', 0 ); - add_filter( 'add_menu_classes', array( $this, 'set_browse_sites_link_class' ) ); - } - /** * Adds a custom element class for Site Switcher menu item. * diff --git a/projects/packages/masterbar/tests/php/test-class-atomic-admin-menu.php b/projects/packages/masterbar/tests/php/test-class-atomic-admin-menu.php index c96b71c385b2f..f43d2ee38c6c8 100644 --- a/projects/packages/masterbar/tests/php/test-class-atomic-admin-menu.php +++ b/projects/packages/masterbar/tests/php/test-class-atomic-admin-menu.php @@ -116,41 +116,6 @@ public function test_add_browse_sites_link() { $this->assertArrayNotHasKey( 0, $menu ); } - /** - * Tests add_browse_sites_link. - * - * @covers ::add_browse_sites_link - */ - public function test_add_browse_sites_link_multisite() { - if ( ! is_multisite() ) { - $this->markTestSkipped( 'Only used on multisite' ); - } - - global $menu; - - // No output when user has just one site. - static::$admin_menu->add_browse_sites_link(); - $this->assertArrayNotHasKey( 0, $menu ); - - // Give user a second site. - update_user_option( static::$user_id, 'wpcom_site_count', 2 ); - - static::$admin_menu->add_browse_sites_link(); - - $browse_sites_menu_item = array( - 'Browse sites', - 'read', - 'https://wordpress.com/sites', - 'site-switcher', - 'menu-top toplevel_page_https://wordpress.com/sites', - 'toplevel_page_https://wordpress.com/sites', - 'dashicons-arrow-left-alt2', - ); - $this->assertSame( $menu[0], $browse_sites_menu_item ); - - delete_user_option( static::$user_id, 'wpcom_site_count' ); - } - /** * Tests add_new_site_link. * diff --git a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-atomic-admin-menu.php b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-atomic-admin-menu.php index 2f1b0bd741b33..2bc5a5fce8a71 100644 --- a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-atomic-admin-menu.php +++ b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-atomic-admin-menu.php @@ -109,43 +109,6 @@ public function test_add_browse_sites_link() { $this->assertArrayNotHasKey( 0, $menu ); } - /** - * Tests add_browse_sites_link. - * - * @covers ::add_browse_sites_link - * - * @expectedDeprecated Automattic\Jetpack\Dashboard_Customizations\Atomic_Admin_Menu::add_browse_sites_link - */ - public function test_add_browse_sites_link_multisite() { - if ( ! is_multisite() ) { - $this->markTestSkipped( 'Only used on multisite' ); - } - - global $menu; - - // No output when user has just one site. - static::$admin_menu->add_browse_sites_link(); - $this->assertArrayNotHasKey( 0, $menu ); - - // Give user a second site. - update_user_option( static::$user_id, 'wpcom_site_count', 2 ); - - static::$admin_menu->add_browse_sites_link(); - - $browse_sites_menu_item = array( - 'Browse sites', - 'read', - 'https://wordpress.com/sites', - 'site-switcher', - 'menu-top toplevel_page_https://wordpress.com/sites', - 'toplevel_page_https://wordpress.com/sites', - 'dashicons-arrow-left-alt2', - ); - $this->assertSame( $menu[0], $browse_sites_menu_item ); - - delete_user_option( static::$user_id, 'wpcom_site_count' ); - } - /** * Tests add_new_site_link. * diff --git a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-wpcom-admin-menu.php b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-wpcom-admin-menu.php index c438e2782b57d..173fb4ddddc90 100644 --- a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-wpcom-admin-menu.php +++ b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-wpcom-admin-menu.php @@ -111,43 +111,6 @@ public function test_get_preferred_view() { $this->assertSame( 'default', static::$admin_menu->get_preferred_view( 'plugins.php' ) ); } - /** - * Tests add_browse_sites_link. - * - * @covers ::add_browse_sites_link - */ - public function test_add_browse_sites_link() { - if ( ! function_exists( 'add_user_to_blog' ) ) { - $this->markTestSkipped( 'Only used on multisite' ); - } - $this->setExpectedDeprecated( 'Automattic\Jetpack\Dashboard_Customizations\WPcom_Admin_Menu::get_current_user_blog_count' ); - $this->setExpectedDeprecated( 'Automattic\Jetpack\Dashboard_Customizations\WPcom_Admin_Menu::add_browse_sites_link' ); - global $menu; - - // No output when user has just one site. - static::$admin_menu->add_browse_sites_link(); - $this->assertArrayNotHasKey( 0, $menu ); - - // Give user a second site. - $blog_id = self::factory()->blog->create(); - add_user_to_blog( $blog_id, get_current_user_id(), 'editor' ); - - static::$admin_menu->add_browse_sites_link(); - - $browse_sites_menu_item = array( - 'Browse sites', - 'read', - 'https://wordpress.com/sites', - 'site-switcher', - 'menu-top toplevel_page_https://wordpress.com/sites', - 'toplevel_page_https://wordpress.com/sites', - 'dashicons-arrow-left-alt2', - ); - $this->assertSame( $menu[0], $browse_sites_menu_item ); - - remove_user_from_blog( get_current_user_id(), $blog_id ); - } - /** * Tests add_new_site_link. *