updated plugin Jetpack Protect version 4.0.0
This commit is contained in:
@ -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 @@ class Current_Plan {
|
||||
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 @@ class Current_Plan {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,4 +79,33 @@ class Plans {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Efficiently get the short name of a plan from a slug.
|
||||
*
|
||||
* @param string $plan_slug Plan slug.
|
||||
* @return string|null Short product name or null if not round.
|
||||
*/
|
||||
public static function get_plan_short_name( $plan_slug ) {
|
||||
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
|
||||
if ( ! class_exists( 'Store_Product_List' ) ) {
|
||||
require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php';
|
||||
}
|
||||
|
||||
// Skip additional work like processing of coupons, since we only need the plan's short name.
|
||||
$products = Store_Product_List::get();
|
||||
|
||||
foreach ( $products as $product ) {
|
||||
if ( isset( $product['product_slug'] ) && $product['product_slug'] === $plan_slug ) {
|
||||
return $product['product_name_short'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Fallback to less efficient method for Jetpack environments.
|
||||
$plan = self::get_plan( $plan_slug );
|
||||
return $plan->product_name_short ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user