From 7af187e52bc46d5bec76896ac918c41ad4f386ae Mon Sep 17 00:00:00 2001 From: Miguel Torres <1233880+mmtr@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:06:53 +0100 Subject: [PATCH] Duplicate views: Hide "View" switcher (#40595) --- .../update-hide-switcher-duplicated-views | 4 ++++ .../wpcom-admin-interface.php | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/update-hide-switcher-duplicated-views diff --git a/projects/packages/jetpack-mu-wpcom/changelog/update-hide-switcher-duplicated-views b/projects/packages/jetpack-mu-wpcom/changelog/update-hide-switcher-duplicated-views new file mode 100644 index 0000000000000..6c2c108ea3e4b --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/update-hide-switcher-duplicated-views @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Admin menu: Hide dashboard switcher when WP Admin view is enforced diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php index 1e1b3c0d5e033..cabfcca1dfe58 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php @@ -191,6 +191,26 @@ function wpcom_admin_get_user_option_jetpack( $value ) { add_filter( 'get_user_option_jetpack_admin_menu_preferred_views', 'wpcom_admin_get_user_option_jetpack' ); add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 ); +/** + * Hides the "View" switcher on WP Admin screens enforced by the "Remove duplicate views" experiment. + */ +function wpcom_duplicate_views_hide_view_switcher() { + if ( ! function_exists( '\Automattic\Jetpack\Masterbar\get_admin_menu_class' ) || ! function_exists( '\Automattic\Jetpack\Masterbar\should_customize_nav' ) ) { + return; + } + + $admin_menu_class = apply_filters( 'jetpack_admin_menu_class', \Automattic\Jetpack\Masterbar\get_admin_menu_class() ); + if ( \Automattic\Jetpack\Masterbar\should_customize_nav( $admin_menu_class ) ) { + $admin_menu = $admin_menu_class::get_instance(); + + $current_screen = wpcom_admin_get_current_screen(); + if ( in_array( $current_screen, WPCOM_DUPLICATED_VIEW, true ) && wpcom_is_duplicate_views_experiment_enabled() ) { + remove_filter( 'in_admin_header', array( $admin_menu, 'add_dashboard_switcher' ) ); + } + } +} +add_action( 'admin_init', 'wpcom_duplicate_views_hide_view_switcher' ); + /** * Determines whether the admin interface has been recently changed by checking the presence of the `admin-interface-changed` query param. *