Skip to content

Commit

Permalink
Memberships: Fix mixed membership products (#37527)
Browse files Browse the repository at this point in the history
Fix mixed membership products
  • Loading branch information
pottedmeat committed Jun 7, 2024
1 parent a9f5009 commit 7855144
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Memberships: fixes paid content access in some cases of mixed products
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function current_visitor_can_access( $attributes, $block ) {
return false;
}

$can_view = false;
$paywall = subscription_service();
$access_level = Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS; // Only paid subscribers should be granted access to the premium content
$tier_ids = \Jetpack_Memberships::get_all_newsletter_plan_ids();
Expand Down Expand Up @@ -128,7 +129,6 @@ function current_visitor_can_access( $attributes, $block ) {
$payload = $paywall->decode_token( $token );
$is_valid_token = ! empty( $payload );

$can_view = false;
if ( $is_valid_token ) {
$subscriptions = (array) $payload['subscriptions'];
}
Expand All @@ -140,8 +140,12 @@ function current_visitor_can_access( $attributes, $block ) {
break;
}
}
} else {
$can_view = $paywall->visitor_can_view_content( $selected_plan_ids, $access_level );
}

$non_tier_ids = array_diff( $selected_plan_ids, $tier_ids );
if ( ! $can_view ) {
// For selected plans that are not tiers, we want to check if the user has any of the selected plans.
$can_view = $paywall->visitor_can_view_content( $non_tier_ids, $access_level );
}

if ( $can_view ) {
Expand Down

0 comments on commit 7855144

Please sign in to comment.