diff --git a/projects/js-packages/script-data/changelog/fix-site-specific-features-for-simple-sites b/projects/js-packages/script-data/changelog/fix-site-specific-features-for-simple-sites new file mode 100644 index 0000000000000..8d0bfe4ddc2c9 --- /dev/null +++ b/projects/js-packages/script-data/changelog/fix-site-specific-features-for-simple-sites @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed the site features for Simple sites diff --git a/projects/js-packages/script-data/src/utils.ts b/projects/js-packages/script-data/src/utils.ts index 690b6f4f7c298..667c1618c7b89 100644 --- a/projects/js-packages/script-data/src/utils.ts +++ b/projects/js-packages/script-data/src/utils.ts @@ -57,3 +57,14 @@ export function getMyJetpackUrl( section = '' ) { export function getActiveFeatures() { return getScriptData().site.plan?.features?.active ?? []; } + +/** + * Check if the site has a specific feature. + * + * @param {string} feature - The feature to check. e.g. "republicize". + * + * @return {boolean} Whether the site has the feature. + */ +export function siteHasFeature( feature: string ) { + return getActiveFeatures().includes( feature ); +} diff --git a/projects/packages/plans/changelog/fix-site-specific-features-for-simple-sites b/projects/packages/plans/changelog/fix-site-specific-features-for-simple-sites new file mode 100644 index 0000000000000..8d0bfe4ddc2c9 --- /dev/null +++ b/projects/packages/plans/changelog/fix-site-specific-features-for-simple-sites @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed the site features for Simple sites diff --git a/projects/packages/plans/src/class-current-plan.php b/projects/packages/plans/src/class-current-plan.php index f6e7c6e351c79..cef57d52b3d41 100644 --- a/projects/packages/plans/src/class-current-plan.php +++ b/projects/packages/plans/src/class-current-plan.php @@ -21,6 +21,14 @@ class Current_Plan { */ private static $active_plan_cache; + /** + * Simple Site-specific features available. + * Their calculation can be expensive and slow, so we're caching it for the request. + * + * @var array Site-specific features + */ + private static $simple_site_specific_features = array(); + /** * The name of the option that will store the site's plan. * @@ -374,7 +382,7 @@ function_exists( 'wpcom_feature_exists' ) && return true; } - // As of 05 2023 - all plans support Earn features (minus 'simple-payments') + // As of 05 2023 - all plans support Earn features (minus 'simple-payments'). if ( in_array( $feature, array( 'donations', 'recurring-payments', 'premium-content/container' ), true ) ) { return true; } @@ -390,4 +398,39 @@ function_exists( 'wpcom_feature_exists' ) && return false; } + + /** + * Retrieve site-specific features for Simple sites. + * + * See Jetpack_Gutenberg::get_site_specific_features() + * + * @return array + */ + public static function get_simple_site_specific_features() { + $is_simple_site = defined( 'IS_WPCOM' ) && constant( 'IS_WPCOM' ); + + if ( ! $is_simple_site ) { + return array( + 'active' => array(), + 'available' => array(), + ); + } + + $current_blog_id = get_current_blog_id(); + + // Return the cached value if it exists. + if ( isset( self::$simple_site_specific_features[ $current_blog_id ] ) ) { + return self::$simple_site_specific_features[ $current_blog_id ]; + } + + if ( ! class_exists( '\Store_Product_List' ) ) { + require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php'; + } + + $simple_site_specific_features = \Store_Product_List::get_site_specific_features_data( $current_blog_id ); + + self::$simple_site_specific_features[ $current_blog_id ] = $simple_site_specific_features; + + return $simple_site_specific_features; + } } diff --git a/projects/packages/publicize/changelog/fix-site-specific-features-for-simple-sites b/projects/packages/publicize/changelog/fix-site-specific-features-for-simple-sites new file mode 100644 index 0000000000000..8d0bfe4ddc2c9 --- /dev/null +++ b/projects/packages/publicize/changelog/fix-site-specific-features-for-simple-sites @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed the site features for Simple sites diff --git a/projects/packages/publicize/src/class-publicize-script-data.php b/projects/packages/publicize/src/class-publicize-script-data.php index 8931878b16ab5..ff841f2da2545 100644 --- a/projects/packages/publicize/src/class-publicize-script-data.php +++ b/projects/packages/publicize/src/class-publicize-script-data.php @@ -60,6 +60,11 @@ public static function set_admin_script_data( $data ) { $data['site']['plan'] = Current_Plan::get(); } + // Override features for simple sites. + if ( ( new Host() )->is_wpcom_simple() ) { + $data['site']['plan']['features'] = Current_Plan::get_simple_site_specific_features(); + } + return $data; }