From 613a079ecbaa97debde2885e1b52e0df6021a584 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Thu, 9 Jan 2025 17:05:59 +0000 Subject: [PATCH] wrap the removal of My Mailboxes in a call to wpcom_is_duplicate_views_experiment_enabled so it's hidden behind the experiment --- .../masterbar/src/admin-menu/class-admin-menu.php | 8 ++++++++ .../src/admin-menu/class-atomic-admin-menu.php | 7 +++++++ .../src/admin-menu/class-wpcom-admin-menu.php | 3 +++ .../tests/php/test-class-atomic-admin-menu.php | 13 +++++++++++++ 4 files changed, 31 insertions(+) diff --git a/projects/packages/masterbar/src/admin-menu/class-admin-menu.php b/projects/packages/masterbar/src/admin-menu/class-admin-menu.php index b83c44928e18f..3b0085f29391d 100644 --- a/projects/packages/masterbar/src/admin-menu/class-admin-menu.php +++ b/projects/packages/masterbar/src/admin-menu/class-admin-menu.php @@ -115,6 +115,14 @@ public function add_my_home_menu() { $this->update_menu( 'index.php', 'https://wordpress.com/home/' . $this->domain, __( 'My Home', 'jetpack-masterbar' ), 'read', 'dashicons-admin-home' ); } + /** + * Adds My Mailboxes menu. + */ + public function add_my_mailboxes_menu() { + // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. + add_menu_page( __( 'My Mailboxes', 'jetpack-masterbar' ), __( 'My Mailboxes', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/mailboxes/' . $this->domain, null, 'dashicons-email', 4.64424 ); + } + /** * Adds Stats menu. */ 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 71461b1ac951f..1cf7d674010fd 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 @@ -78,6 +78,13 @@ public function reregister_menu_items() { $this->add_my_home_menu(); $this->remove_gutenberg_menu(); + // We don't need the `My Mailboxes` when the interface is set to wp-admin or the site is a staging site, + if ( ! $this->use_wp_admin_interface() && ! get_option( 'wpcom_is_staging_site' ) ) { + if ( function_exists( 'wpcom_is_duplicate_views_experiment_enabled' ) && ! wpcom_is_duplicate_views_experiment_enabled() ) { + $this->add_my_mailboxes_menu(); + } + } + // Not needed outside of wp-admin. if ( ! $this->is_api_request ) { $this->add_site_card_menu(); 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 563f9dcf48a09..abb81c70088f5 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 @@ -45,6 +45,9 @@ public function reregister_menu_items() { parent::reregister_menu_items(); $this->add_my_home_menu(); + if ( function_exists( 'wpcom_is_duplicate_views_experiment_enabled' ) && ! wpcom_is_duplicate_views_experiment_enabled() ) { + $this->add_my_mailboxes_menu(); + } $this->remove_gutenberg_menu(); // Not needed outside of wp-admin. 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 a685d3f0b0f06..38e99769a1b84 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 @@ -264,6 +264,19 @@ public function test_add_upgrades_menu() { } } + /** + * Tests add_my_mailboxes_menu + * + * @covers Automattic\Jetpack\Masterbar\Atomic_Admin_Menu::add_my_mailboxes_menu + */ + public function test_add_my_mailboxes_menu() { + global $menu; + + static::$admin_menu->add_my_mailboxes_menu(); + + $this->assertSame( 'https://wordpress.com/mailboxes/' . static::$domain, $menu['4.64424'][2] ); + } + /** * Tests add_options_menu *