Skip to content

Commit

Permalink
Add Global Styles on Personal experiment (#41132)
Browse files Browse the repository at this point in the history
* Code that enables retrieving the experiment assignment on wpcom

* changelog

* Updated the cache key to avoid colissions with the previous experiment

* Fixed code style

* Updated experiment key

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13007748835

Upstream-Ref: Automattic/jetpack@c843f8f
  • Loading branch information
rcrdortiz authored and matticbot committed Jan 28, 2025
1 parent 4bf7f6f commit 40ef392
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 94 deletions.
60 changes: 30 additions & 30 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions jetpack_vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This is an alpha version! The changes listed here are not final.

### Changed
- "Build your audience" task action now has a URL hash
- Added logic for handling Global Styles on Personal experiment assignment
- Added query param to the wordpress.com login url.
- Adds verify email task to newsletter goal launchpad
- Admin Bar: Point the Edit Site menu item to /site-editor.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public function permissions_check() {
*/
public function get_global_styles_info() {
return array(
'globalStylesInUse' => wpcom_global_styles_in_use(),
'shouldLimitGlobalStyles' => wpcom_should_limit_global_styles(),
'globalStylesInUse' => wpcom_global_styles_in_use(),
'shouldLimitGlobalStyles' => wpcom_should_limit_global_styles(),
'globalStylesInPersonalPlan' => wpcom_site_has_global_styles_in_personal_plan(),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
use Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;
use Automattic\Jetpack\Plans;

/**
* Checks if Global Styles on personal are available on the current site either by A/B test assign or feature flag.
*
* @return bool Whether Global Styles are available.
*/
function is_global_styles_on_personal_plan() {
return wpcom_site_has_global_styles_in_personal_plan()
|| ( class_exists( 'WPCOM_Feature_Flags' ) && WPCOM_Feature_Flags::is_enabled( WPCOM_Feature_Flags::GLOBAL_STYLES_ON_PERSONAL_PLAN ) );
}

/**
* Checks if Global Styles should be limited on the given site.
*
Expand Down Expand Up @@ -178,7 +188,7 @@ function wpcom_global_styles_enqueue_block_editor_assets() {
// @TODO Remove this once the global styles are available for all users on the Personal Plan.
$upgrade_url = "$calypso_domain/plans/$site_slug?plan=value_bundle&feature=style-customization";
$plan_name = Plans::get_plan( 'value_bundle' )->product_name_short;
if ( class_exists( 'WPCOM_Feature_Flags' ) && WPCOM_Feature_Flags::is_enabled( WPCOM_Feature_Flags::GLOBAL_STYLES_ON_PERSONAL_PLAN ) ) {
if ( is_global_styles_on_personal_plan() ) {
$plan_name = Plans::get_plan( 'personal-bundle' )->product_name_short;
$upgrade_url = "$calypso_domain/plans/$site_slug?plan=personal-bundle&feature=style-customization";
}
Expand Down Expand Up @@ -508,7 +518,7 @@ function wpcom_display_global_styles_launch_bar() {
// @TODO Remove this once the global styles are available for all users on the Personal Plan.
$gs_upgrade_plan = WPCOM_VALUE_BUNDLE;
$upgrade_url = "https://wordpress.com/plans/$site_slug?plan=value_bundle&feature=style-customization";
if ( class_exists( 'WPCOM_Feature_Flags' ) && WPCOM_Feature_Flags::is_enabled( WPCOM_Feature_Flags::GLOBAL_STYLES_ON_PERSONAL_PLAN ) ) {
if ( is_global_styles_on_personal_plan() ) {
$gs_upgrade_plan = WPCOM_PERSONAL_BUNDLE;
$upgrade_url = "https://wordpress.com/plans/$site_slug?plan=personal-bundle&feature=style-customization";
}
Expand Down Expand Up @@ -724,7 +734,7 @@ function wpcom_site_has_global_styles_feature( $blog_id = 0 ) {
}

// If the GLOBAL_STYLES_ON_PERSONAL_PLAN feature is enabled, we need to check if the site has a Personal plan and add the sticker.
if ( class_exists( 'WPCOM_Feature_Flags' ) && WPCOM_Feature_Flags::is_enabled( 'GLOBAL_STYLES_ON_PERSONAL_PLAN' ) ) {
if ( is_global_styles_on_personal_plan() ) {
if ( wpcom_site_has_personal_plan( $blog_id ) ) {
$note = 'Automated sticker. See paYJgx-5w2-p2';
$user = 'a8c'; // A non-empty string avoids storing the current user as author of the sticker change.
Expand Down Expand Up @@ -760,3 +770,47 @@ function wpcom_global_styles_is_previewing_premium_theme_without_premium_plan( $

return ! $has_premium_plan_or_higher;
}

/**
* Checks whether the site has access to Global Styles with a Personal plan as part of an A/B test.
*
* @param int $blog_id Blog ID.
* @return bool Whether the site has access to Global Styles with a Personal plan.
*/
function wpcom_site_has_global_styles_in_personal_plan( $blog_id = 0 ) {
if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
return false;
}

if ( ! function_exists( '\ExPlat\assign_given_user' ) ) {
return false;
}

if ( ! $blog_id ) {
$blog_id = get_current_blog_id();
}

$cache_key = "global-styles-on-personal-feb-2025-$blog_id";
$found_in_cache = false;
$has_global_styles_in_personal_plan = wp_cache_get( $cache_key, 'a8c_experiments', false, $found_in_cache );
if ( $found_in_cache ) {
return $has_global_styles_in_personal_plan;
}

$owner_id = wpcom_get_blog_owner( $blog_id );
if ( ! $owner_id ) {
return false;
}

$owner = get_userdata( $owner_id );
if ( ! $owner ) {
return false;
}

// Placeholder experiment key, we need to update this to the new experiment key once it's created.
$experiment_assignment = \ExPlat\assign_given_user( 'calypso_plans_global_styles_personal_20240127', $owner );
$has_global_styles_in_personal_plan = 'treatment' === $experiment_assignment;
// Cache the experiment assignment to prevent duplicate DB queries in the frontend.
wp_cache_set( $cache_key, $has_global_styles_in_personal_plan, 'a8c_experiments', MONTH_IN_SECONDS );
return $has_global_styles_in_personal_plan;
}
2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
),
'jetpack-mu-wpcom' => array(
'path' => 'jetpack_vendor/automattic/jetpack-mu-wpcom',
'ver' => '6.2.0-alpha1738036753',
'ver' => '6.2.0-alpha1738057754',
),
'jetpack-password-checker' => array(
'path' => 'jetpack_vendor/automattic/jetpack-password-checker',
Expand Down
Loading

0 comments on commit 40ef392

Please sign in to comment.