Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDV: Remove the wpcom_admin_interface hook for the admin_menu hook #40669

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/packages/jetpack-mu-wpcom/changelog/fix-wp-admin-rdv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Exclude the wpcom_admin_interface from the admin_menu action
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function wpcom_replace_edit_profile_menu_to_me( $wp_admin_bar ) {
* @return string Name of the admin bar class.
*/
function wpcom_custom_wpcom_admin_bar_class( $wp_admin_bar_class ) {
if ( ! wpcom_is_using_default_admin_menu() ) {
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
return $wp_admin_bar_class;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ 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 );

add_action(
'admin_menu',
function () {
remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' );
},
PHP_INT_MIN
);

add_action(
'admin_menu',
function () {
add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 );
},
PHP_INT_MAX
);
/**
* Hides the "View" switcher on WP Admin screens enforced by the "Remove duplicate views" experiment.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,11 @@ function current_user_has_wpcom_account() {
return $has_account;
}

/**
* Check if the user has the default (Calypso) Admin menu.
*
* @return bool
*/
function wpcom_is_using_default_admin_menu() {
remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' );
$option = get_option( 'wpcom_admin_interface' ) !== 'wp-admin';
add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 );

return $option;
}

/**
* Adds a Hosting menu.
*/
function wpcom_add_hosting_menu() {
if ( wpcom_is_using_default_admin_menu() ) {
if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
return;
}

Expand Down Expand Up @@ -162,7 +149,7 @@ function wpcom_add_hosting_menu() {
function wpcom_add_jetpack_submenu() {
$is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
$is_atomic_site = ! $is_simple_site;
$uses_wp_admin_interface = ! wpcom_is_using_default_admin_menu();
$uses_wp_admin_interface = get_option( 'wpcom_admin_interface' ) === 'wp-admin';

if ( ! $uses_wp_admin_interface ) {
return;
Expand Down Expand Up @@ -392,7 +379,7 @@ function wpcom_add_plugins_menu() {
global $menu;
$is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
$is_atomic_site = ! $is_simple_site;
$uses_wp_admin_interface = ! wpcom_is_using_default_admin_menu();
$uses_wp_admin_interface = get_option( 'wpcom_admin_interface' ) === 'wp-admin';

if ( $is_simple_site ) {
$has_plugins_menu = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Jetpack_Mu_Wpcom;

if ( wpcom_is_using_default_admin_menu() ) {
if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function wpcom_themes_show_banner() {
* Registers an "Appearance > Theme Showcase" menu.
*/
function wpcom_themes_add_theme_showcase_menu() {
if ( wpcom_is_using_default_admin_menu() ) {
if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions projects/packages/masterbar/changelog/fix-wp-admin-rdv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Exclude the wpcom_admin_interface from the admin_menu action
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function add_tools_menu() {

// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Marketing', 'jetpack-masterbar' ), __( 'Marketing', 'jetpack-masterbar' ), 'publish_posts', 'https://wordpress.com/marketing/tools/' . $this->domain, null, 0 );
if ( $this->is_using_default_admin_menu() ) {
if ( ! $this->use_wp_admin_interface() ) {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Monetize', 'jetpack-masterbar' ), __( 'Monetize', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/earn/' . $this->domain, null, 1 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function () {
);

// Add notices to the settings pages when there is a Calypso page available.
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
if ( $this->use_wp_admin_interface() ) {
add_action( 'current_screen', array( $this, 'add_settings_page_notice' ) );
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public function reregister_menu_items() {
$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->is_using_default_admin_menu() && ! get_option( 'wpcom_is_staging_site' ) ) {
if ( ! $this->use_wp_admin_interface() && ! get_option( 'wpcom_is_staging_site' ) ) {
$this->add_my_mailboxes_menu();
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public function add_users_menu() {
$this->update_submenus( $slug, $submenus_to_update );
}

if ( $this->is_using_default_admin_menu() ) {
if ( ! $this->use_wp_admin_interface() ) {
// The 'Subscribers' menu exists in the Jetpack menu for Classic wp-admin interface, so only add it for non-wp-admin interfaces.
// // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'users.php', esc_attr__( 'Subscribers', 'jetpack-masterbar' ), __( 'Subscribers', 'jetpack-masterbar' ), 'list_users', 'https://wordpress.com/subscribers/' . $this->domain, null );
Expand Down Expand Up @@ -322,7 +322,7 @@ public function get_upsell_nudge() {
*/
public function add_jetpack_menu() {
// This is supposed to be the same as class-admin-menu but with a different position specified for the Jetpack menu.
if ( ! $this->is_using_default_admin_menu() ) {
if ( $this->use_wp_admin_interface() ) {
parent::create_jetpack_menu( 2, false );
} else {
parent::add_jetpack_menu();
Expand Down Expand Up @@ -445,7 +445,7 @@ public function add_options_menu() {

// Hide Settings > Performance when the interface is set to wp-admin.
// This is due to these settings are mostly also available in Jetpack > Settings, in the Performance tab.
if ( ! $this->is_using_default_admin_menu() ) {
if ( $this->use_wp_admin_interface() ) {
$this->hide_submenu_page( 'options-general.php', 'https://wordpress.com/settings/performance/' . $this->domain );
}
}
Expand All @@ -457,7 +457,7 @@ public function add_tools_menu() {
parent::add_tools_menu();

// Link the Tools menu to Available Tools when the interface is set to wp-admin.
if ( ! $this->is_using_default_admin_menu() ) {
if ( $this->use_wp_admin_interface() ) {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Available Tools', 'jetpack-masterbar' ), __( 'Available Tools', 'jetpack-masterbar' ), 'edit_posts', 'tools.php', null, 0 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,21 +756,6 @@ public function use_wp_admin_interface() {
return 'wp-admin' === get_option( 'wpcom_admin_interface' );
}

/**
* Check if the user has the default (Calypso) Admin menu.
*
* @return bool
*/
public function is_using_default_admin_menu() {
remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' );
$option = get_option( 'wpcom_admin_interface' ) !== 'wp-admin';
if ( function_exists( 'wpcom_admin_interface_pre_get_option' ) ) {
add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 );
}

return $option;
}

/**
* Create the desired menu output.
*/
Expand Down
Loading