diff --git a/projects/packages/jetpack-mu-wpcom/changelog/update-global-styles-upgrade-nudge b/projects/packages/jetpack-mu-wpcom/changelog/update-global-styles-upgrade-nudge new file mode 100644 index 0000000000000..2f5a4def492d8 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/update-global-styles-upgrade-nudge @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Render the Global Styles frontend bar separately from the .com launch bar. diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php index cd1bc2fd6ece8..4915adfe8c4ae 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php @@ -210,16 +210,7 @@ function wpcom_global_styles_enqueue_block_editor_assets() { * @return void */ function wpcom_global_styles_enqueue_assets() { - if ( - ! wpcom_global_styles_current_user_can_edit_wp_global_styles() || - ! wpcom_should_limit_global_styles() || - ! wpcom_global_styles_in_use() - ) { - return; - } - - $asset_file = include Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-global-styles-editor/wpcom-global-styles-editor.asset.php'; - + $asset_file = include Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-global-styles-frontend/wpcom-global-styles-frontend.asset.php'; wp_enqueue_script( 'wpcom-global-styles-frontend', plugins_url( 'build/wpcom-global-styles-frontend/wpcom-global-styles-frontend.js', Jetpack_Mu_Wpcom::BASE_FILE ), @@ -227,6 +218,15 @@ function wpcom_global_styles_enqueue_assets() { $asset_file['version'] ?? filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-global-styles-frontend/wpcom-global-styles-frontend.js' ), true ); + wp_add_inline_script( + 'wpcom-global-styles-frontend', + 'const launchBarUserData = ' . wp_json_encode( + array( + 'blogId' => get_current_blog_id(), + ) + ), + 'before' + ); Common\wpcom_enqueue_tracking_scripts( 'wpcom-global-styles-frontend' ); wp_enqueue_style( @@ -236,7 +236,6 @@ function wpcom_global_styles_enqueue_assets() { filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-global-styles-frontend/wpcom-global-styles-frontend.css' ) ); } -add_action( 'wp_enqueue_scripts', 'wpcom_global_styles_enqueue_assets' ); /** * Removes the user styles from a site with limited global styles. @@ -441,18 +440,64 @@ function wpcom_premium_global_styles_is_site_exempt( $blog_id = 0 ) { } /** - * Adds the global style notice banner to the launch bar controls. - * - * @param array $bar_controls List of launch bar controls. + * Returns whether the global style banner should be shown or not. * - * return array The collection of launch bar controls to render. + * @return bool Whether the global styles upgrade banner should be rendered. */ -function wpcom_display_global_styles_launch_bar( $bar_controls ) { - // Do not show the banner if the user can use global styles. +function wpcom_should_show_global_styles_launch_bar() { + $current_user_id = get_current_user_id(); + + if ( ! $current_user_id ) { + return false; + } + + $current_blog_id = get_current_blog_id(); + + if ( ! ( + is_user_member_of_blog( $current_user_id, $current_blog_id ) && + current_user_can( 'manage_options' ) + ) ) { + return false; + } + + if ( has_blog_sticker( 'difm-lite-in-progress' ) ) { + return false; + } + + // The site is being previewed in Calypso or Gutenberg. + if ( + isset( $_GET['iframe'] ) && 'true' === $_GET['iframe'] && ( // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Not a form action + ( isset( $_GET['theme_preview'] ) && 'true' === $_GET['theme_preview'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Not a form action + ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Not a form action + ) || + isset( $_GET['widgetPreview'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Not a form action (Gutenberg < 9.2) + isset( $_GET['widget-preview'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Not a form action (Gutenberg >= 9.2) + ( isset( $_GET['hide_banners'] ) && $_GET['hide_banners'] === 'true' ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Not a form action + ) { + return false; + } + + // Do not show the lanuch banner when previewed in the customizer + if ( is_customize_preview() ) { + return false; + } + + // No banner for agency-managed sites. + if ( ! empty( get_option( 'is_fully_managed_agency_site' ) ) ) { + return false; + } + if ( ! wpcom_should_limit_global_styles() || ! wpcom_global_styles_in_use() ) { - return $bar_controls; + return false; } + return true; +} + +/** + * Renders the global style notice banner to the launch bar. + */ +function wpcom_display_global_styles_launch_bar() { if ( method_exists( '\WPCOM_Masterbar', 'get_calypso_site_slug' ) ) { $site_slug = WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); } else { @@ -474,109 +519,135 @@ function wpcom_display_global_styles_launch_bar( $bar_controls ) { $preview_location = remove_query_arg( 'hide-global-styles' ); } - ob_start(); ?> -