-
Notifications
You must be signed in to change notification settings - Fork 892
Podcast: add product-access gate and grandfather sticker constant #48702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arcangelini
merged 9 commits into
trunk
from
pods-141-add-gate-helper-and-grandfather-sticker-constant
May 17, 2026
+145
−4
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
30c86c3
Podcast: add product-access gate and grandfather sticker constant
robertbpugh 6421e19
Podcast: trim docblock narrative on gate class and tests
robertbpugh 6347c57
Podcast: fix CI failures after jetpack-plans require
robertbpugh 7b6d7b6
Podcast: bump pods-141 changelog significance to minor
robertbpugh c969fde
Podcast: add lockfile-bump changelog entries for the three plugins
robertbpugh 4a928ad
Potential fix for pull request finding
robertbpugh f09730a
Merge remote-tracking branch 'origin/trunk' into pods-141-add-gate-he…
robertbpugh 7d15d7e
Regenerate wpcomsh composer.lock for jetpack-plans dependency
robertbpugh 4fc2452
Regenerate jetpack and mu-wpcom composer locks for jetpack-plans
robertbpugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Podcast: add product-access gate (Podcast_Gate::has_product_access) and grandfather sticker constant. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
| /** | ||
| * Podcast product-access gate. | ||
| * | ||
| * @package automattic/jetpack-podcast | ||
| */ | ||
|
|
||
| namespace Automattic\Jetpack\Podcast; | ||
|
|
||
| use Automattic\Jetpack\Current_Plan; | ||
|
|
||
| /** | ||
| * Premium podcast feature gate. | ||
| * | ||
| * Operates on the current blog. `Current_Plan::supports` reads request-scoped | ||
| * state, so callers that need to gate a different blog must `switch_to_blog` | ||
| * first. | ||
| */ | ||
| class Podcast_Gate { | ||
|
|
||
| const GRANDFATHER_STICKER = 'podcasting-grandfathered'; | ||
|
|
||
| const FEATURE_SLUG = 'podcasting'; | ||
|
|
||
| /** | ||
| * Whether the current blog can use Premium podcast features. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public static function has_product_access(): bool { | ||
| $blog_id = get_current_blog_id(); | ||
| if ( $blog_id <= 0 ) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( | ||
| function_exists( 'wpcom_has_blog_sticker' ) | ||
| && wpcom_has_blog_sticker( self::GRANDFATHER_STICKER, $blog_id ) | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| return (bool) Current_Plan::supports( self::FEATURE_SLUG ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
| /** | ||
| * Tests for the Podcast_Gate product-access helper. | ||
| * | ||
| * @package automattic/jetpack-podcast | ||
| */ | ||
|
|
||
| namespace Automattic\Jetpack\Podcast\Tests; | ||
|
|
||
| use Automattic\Jetpack\Current_Plan; | ||
| use Automattic\Jetpack\Podcast\Podcast_Gate; | ||
| use PHPUnit\Framework\Attributes\CoversClass; | ||
| use WorDBless\BaseTestCase; | ||
| use WorDBless\Options as WorDBless_Options; | ||
|
|
||
| /** | ||
| * @covers \Automattic\Jetpack\Podcast\Podcast_Gate | ||
| */ | ||
| #[CoversClass( Podcast_Gate::class )] | ||
| class Podcast_Gate_Test extends BaseTestCase { | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
| $GLOBALS['jetpack_podcast_test_stickers'] = array(); | ||
| self::reset_active_plan_cache(); | ||
| } | ||
|
|
||
| protected function tearDown(): void { | ||
| unset( $GLOBALS['jetpack_podcast_test_stickers'] ); | ||
| WorDBless_Options::init()->clear_options(); | ||
| self::reset_active_plan_cache(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| /** | ||
| * `Current_Plan::get()` memoizes for the request, leaking option writes between tests. | ||
| */ | ||
| private static function reset_active_plan_cache(): void { | ||
| $property = ( new \ReflectionClass( Current_Plan::class ) )->getProperty( 'active_plan_cache' ); | ||
| // @todo Remove once we drop PHP < 8.1 support. | ||
| if ( PHP_VERSION_ID < 80100 ) { | ||
| $property->setAccessible( true ); | ||
| } | ||
| $property->setValue( null, null ); | ||
| } | ||
|
|
||
| public function test_grandfather_sticker_grants_access(): void { | ||
| $GLOBALS['jetpack_podcast_test_stickers'][ get_current_blog_id() ] = array( Podcast_Gate::GRANDFATHER_STICKER ); | ||
|
|
||
| $this->assertTrue( Podcast_Gate::has_product_access() ); | ||
| } | ||
|
|
||
| public function test_plan_supports_feature_grants_access(): void { | ||
| $plan = Current_Plan::PLAN_DATA['free']; | ||
| $plan['features']['active'] = array( Podcast_Gate::FEATURE_SLUG ); | ||
| update_option( Current_Plan::PLAN_OPTION, $plan, true ); | ||
|
|
||
| $this->assertTrue( Podcast_Gate::has_product_access() ); | ||
| } | ||
|
|
||
| public function test_no_sticker_and_unsupported_plan_denies_access(): void { | ||
| $plan = Current_Plan::PLAN_DATA['free']; | ||
| $plan['features']['active'] = array(); | ||
| update_option( Current_Plan::PLAN_OPTION, $plan, true ); | ||
|
|
||
| $this->assertFalse( Podcast_Gate::has_product_access() ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: other | ||
|
|
||
| Comment: Podcast: composer.lock picks up jetpack-plans transitively from the podcast package; no plugin-level behavior change. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: changed | ||
|
|
||
| Updated composer.lock to pick up jetpack-plans transitively via jetpack-podcast. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: changed | ||
|
|
||
| Updated composer.lock to pick up jetpack-plans transitively via jetpack-podcast. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.