Skip to content

Commit

Permalink
Check for legacy plans when determing status for other products as well
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeyGuyDylan committed Jul 24, 2024
1 parent c8c0205 commit 1ce2184
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
19 changes: 12 additions & 7 deletions projects/packages/my-jetpack/src/products/class-anti-spam.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public static function get_features() {
* @return bool - whether an API key was found
*/
public static function has_paid_plan_for_product() {
$products_with_anti_spam = array(
'jetpack_anti_spam',
'jetpack_complete',
'jetpack_security',
'jetpack_personal',
'jetpack_premium',
'jetpack_business',
);
// Check if the site has an API key for Akismet
$akismet_api_key = apply_filters( 'akismet_get_api_key', defined( 'WPCOM_API_KEY' ) ? constant( 'WPCOM_API_KEY' ) : get_option( 'wordpress_api_key' ) );
$fallback = ! empty( $akismet_api_key );
Expand All @@ -125,13 +133,10 @@ public static function has_paid_plan_for_product() {

if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
foreach ( $purchases_data as $purchase ) {
// Anti-spam is available as standalone bundle and as part of the Security and Complete plans.
if (
strpos( $purchase->product_slug, 'jetpack_anti_spam' ) !== false ||
str_starts_with( $purchase->product_slug, 'jetpack_complete' ) ||
str_starts_with( $purchase->product_slug, 'jetpack_security' )
) {
return true;
foreach ( $products_with_anti_spam as $product ) {
if ( strpos( $purchase->product_slug, $product ) !== false ) {
return true;
}
}
}
}
Expand Down
19 changes: 12 additions & 7 deletions projects/packages/my-jetpack/src/products/class-protect.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,24 @@ public static function get_pricing_for_ui() {
* @return boolean
*/
public static function has_paid_plan_for_product() {
$plans_with_scan = array(
'jetpack_scan',
'jetpack_security',
'jetpack_complete',
'jetpack_premium',
'jetpack_business',
);

$purchases_data = Wpcom_Products::get_site_current_purchases();
if ( is_wp_error( $purchases_data ) ) {
return false;
}
if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
foreach ( $purchases_data as $purchase ) {
// Protect is available as jetpack_scan product and as part of the Security or Complete plan.
if (
strpos( $purchase->product_slug, 'jetpack_scan' ) !== false ||
str_starts_with( $purchase->product_slug, 'jetpack_security' ) ||
str_starts_with( $purchase->product_slug, 'jetpack_complete' )
) {
return true;
foreach ( $plans_with_scan as $plan ) {
if ( strpos( $purchase->product_slug, $plan ) !== false ) {
return true;
}
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions projects/packages/my-jetpack/src/products/class-videopress.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,22 @@ public static function get_manage_url() {
* @return boolean
*/
public static function has_paid_plan_for_product() {
$purchases_data = Wpcom_Products::get_site_current_purchases();
$plans_with_videopress = array(
'jetpack_videopress',
'jetpack_complete',
'jetpack_business',
'jetpack_premium',
);
$purchases_data = Wpcom_Products::get_site_current_purchases();
if ( is_wp_error( $purchases_data ) ) {
return false;
}
if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
foreach ( $purchases_data as $purchase ) {
if ( str_contains( $purchase->product_slug, 'jetpack_videopress' ) || str_starts_with( $purchase->product_slug, 'jetpack_complete' ) ) {
return true;
foreach ( $plans_with_videopress as $plan ) {
if ( strpos( $purchase->product_slug, $plan ) !== false ) {
return true;
}
}
}
}
Expand Down

0 comments on commit 1ce2184

Please sign in to comment.