From c98bbfd5b12c3c4f6d6fdb25d240917c0fa6d89c Mon Sep 17 00:00:00 2001 From: Bogdan Ungureanu Date: Fri, 20 Dec 2024 19:45:00 +0200 Subject: [PATCH] Fix/rdv regressions on treatment (#40690) * RDV: Fix regressions for Duplicate views * RDV: Fix regressions for Duplicate views * Add docblock. * Select Calypso Stats menu for post stats and fix the upsell upgrade nudge styling. * Linting --- .../fix-rdv-regressions-on-treatment | 4 ++ .../src/class-jetpack-mu-wpcom.php | 2 +- .../wpcom-admin-bar/wpcom-admin-bar.php | 6 +- .../wpcom-admin-interface.php | 63 ++++++++++++++++++- .../wpcom-sidebar-notice.php | 6 +- 5 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/fix-rdv-regressions-on-treatment diff --git a/projects/packages/jetpack-mu-wpcom/changelog/fix-rdv-regressions-on-treatment b/projects/packages/jetpack-mu-wpcom/changelog/fix-rdv-regressions-on-treatment new file mode 100644 index 0000000000000..5ce69e6f92aaf --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/fix-rdv-regressions-on-treatment @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed several regressions for Stats, Blaze and notices for RDV experiment diff --git a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php index 89597cf7ce895..22b6eec4e9fc2 100644 --- a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php +++ b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php @@ -452,7 +452,7 @@ public static function load_verbum_comments_admin() { * Load Odyssey Stats in Simple sites. */ public static function load_wpcom_simple_odyssey_stats() { - if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) { + if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' || wpcom_is_duplicate_views_experiment_enabled() ) { require_once __DIR__ . '/features/wpcom-simple-odyssey-stats/wpcom-simple-odyssey-stats.php'; } } diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php index 575a7e3218f49..a8c7fdf75b1b8 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php @@ -263,7 +263,11 @@ 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 ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) { + remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' ); + $is_wp_admin = get_option( 'wpcom_admin_interface' ) === 'wp-admin'; + add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 ); + + if ( $is_wp_admin ) { return $wp_admin_bar_class; } 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 91e2394b86a7b..dc66f5af8145c 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 @@ -8,6 +8,7 @@ use Automattic\Jetpack\Connection\Client; use Automattic\Jetpack\Connection\Manager as Jetpack_Connection; use Automattic\Jetpack\Jetpack_Mu_Wpcom; +use Automattic\Jetpack\Status; use Automattic\Jetpack\Status\Host; /** @@ -118,8 +119,6 @@ function ( $location ) { const WPCOM_DUPLICATED_VIEW = array( 'edit.php', - 'admin.php?page=stats', - 'tools.php?page=advertising', 'edit.php?post_type=jetpack-portfolio', 'edit.php?post_type=jetpack-testimonial', 'edit-comments.php', @@ -548,3 +547,63 @@ function wpcom_dismiss_removed_calypso_screen_notice() { wp_die(); } add_action( 'wp_ajax_wpcom_dismiss_removed_calypso_screen_notice', 'wpcom_dismiss_removed_calypso_screen_notice' ); + +/** + * Enable the Blaze dashboard (WP-Admin) for users that have the RDV experiment enabled. + * + * @param bool $activation_status The activation status - use WP-Admin or Calypso. + * @return mixed|true + */ +function wpcom_enable_blaze_dashboard_for_experiment( $activation_status ) { + if ( ! wpcom_is_duplicate_views_experiment_enabled() ) { + return $activation_status; + } + + return true; +} + +add_filter( 'jetpack_blaze_dashboard_enable', 'wpcom_enable_blaze_dashboard_for_experiment' ); + +/** + * Make the Jetpack Stats page to point to the Calypso Stats Admin menu - temporary. This is needed because WP-Admin pages are rolled-out individually. + * + * This should be removed when the sites are fully untangled (or with the Jetpack Stats). + * + * This is enabled only for the stats page for users that are part of the remove duplicate views experiment. + * + * @param string $file The parent_file of the page. + * + * @return mixed + */ +function wpcom_select_calypso_admin_menu_stats_for_jetpack_post_stats( $file ) { + global $_wp_real_parent_file, $pagenow; + + $is_on_stats_page = 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'stats' === $_GET['page']; + + if ( ! $is_on_stats_page || ! wpcom_is_duplicate_views_experiment_enabled() ) { + return $file; + } + + remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' ); + $is_using_wp_admin = 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' ); + } + + if ( $is_using_wp_admin ) { + return $file; + } + + if ( ! wpcom_get_custom_admin_menu_class() ) { + return $file; + } + + /** + * Not ideal... We shouldn't be doing this. + */ + $_wp_real_parent_file['jetpack'] = 'https://wordpress.com/stats/day/' . ( new Status() )->get_site_suffix(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + return $file; +} + +add_filter( 'parent_file', 'wpcom_select_calypso_admin_menu_stats_for_jetpack_post_stats' ); diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php index 90b1dd2898ff6..ada1b6fc1383d 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php @@ -10,7 +10,11 @@ use Automattic\Jetpack\Connection\Manager as Connection_Manager; use Automattic\Jetpack\Jetpack_Mu_Wpcom; -if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) { +remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' ); +$is_wp_admin = get_option( 'wpcom_admin_interface' ) === 'wp-admin'; +add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 ); + +if ( ! $is_wp_admin ) { return; }