Skip to content

Commit

Permalink
Fix: My Jetpack Social plan showing no paid plan with Jetpack legacy …
Browse files Browse the repository at this point in the history
…plans (#38516)

* Update social paid plan check for Jetpack legacy plans

* changelog

* Check for legacy plans when determing status for other products as well
  • Loading branch information
CodeyGuyDylan authored Jul 25, 2024
1 parent aff1ef3 commit 95f790f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Include Jetpack Legacy plans when checking if user has social included with plan
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
15 changes: 12 additions & 3 deletions projects/packages/my-jetpack/src/products/class-social.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ public static function get_wpcom_product_slug() {
* @return boolean
*/
public static function has_paid_plan_for_product() {
$plans_with_social = array(
'jetpack_social',
'jetpack_complete',
'jetpack_business',
'jetpack_premium',
'jetpack_personal',
);
// For atomic sites, do a feature check to see if the republicize feature is available
// This feature is available by default on all Jetpack sites
if ( ( new Host() )->is_woa_site() ) {
Expand All @@ -160,11 +167,13 @@ public static function has_paid_plan_for_product() {
if ( is_wp_error( $purchases_data ) ) {
return false;
}

if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
foreach ( $purchases_data as $purchase ) {
// Social is available as standalone bundle and as part of the Complete plan.
if ( strpos( $purchase->product_slug, 'jetpack_social' ) !== false || str_starts_with( $purchase->product_slug, 'jetpack_complete' ) ) {
return true;
foreach ( $plans_with_social 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 95f790f

Please sign in to comment.