Skip to content

Commit

Permalink
Remove Browse Sites from sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
lupus2k committed Jul 25, 2024
1 parent 95f790f commit 3b591df
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 3b591df

Please sign in to comment.