Repository navigation
Themes: share one WordPress.com themes data layer between the Marketplace tab and wpcomsh #53511
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
+358
−208
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
22179b9
Themes: share the WordPress.com themes api, cache and mapper with wpc…
dsas 88570c5
Themes: read the Marketplace tab's catalog from the shared layer
dsas 7e8e82d
Themes: remove WordPress.org themes by plan, rather than every theme
dsas 3549e62
Themes: answer which tiers a plan includes in one place
dsas 1eed7a0
Themes: do not cache a failed catalog read for a day
dsas 2a7b707
Themes: note that a plan including the partner tier is not the whole …
dsas 4ce02f3
Themes: keep the catalog total when removing WordPress.org themes
dsas 1537c61
Themes: test the WordPress.org theme filtering without depending on a…
dsas 87240c0
Themes: say why the free tier needs no plan rather than test it
dsas 0e81d7d
Themes: changelog the failed-read fix for wpcomsh too
dsas 484e0e8
Themes: drop the changelog entries for the refactor itself
dsas ebb3748
Themes: say what a failed read costs, and what the free tier returns
dsas e542b0e
Themes: cut the comments that restate the code
dsas 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
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/dotcom-18877-dont-cache-failures
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: fixed | ||
|
|
||
| Themes: retry after a failed read of the WordPress.com theme list, rather than caching the failure for a day. |
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/dotcom-18877-shared-themes-data-layer
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 | ||
|
|
||
| Themes: share the WordPress.com themes API, cache, mapper and tier reader with wpcomsh rather than each keeping a copy. |
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
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
62 changes: 62 additions & 0 deletions
62
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/class-wpcom-themes-tiers.php
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,62 @@ | ||
| <?php | ||
| /** | ||
| * Class WPCom_Themes_Tiers. | ||
| * What a site's plan includes, by theme tier. | ||
| * | ||
| * @package automattic/jetpack-mu-wpcom | ||
| */ | ||
|
|
||
| /** | ||
| * Answers which theme tiers a site's plan includes. | ||
| * | ||
| * Entitlement only. Whether a surface shows a tier it cannot install is that surface's own | ||
| * decision: core's Add Themes tabs hide partner themes because they need their own subscription, | ||
| * while the Marketplace tab lists them to sell them. | ||
| */ | ||
| class WPCom_Themes_Tiers { | ||
|
|
||
| /** | ||
| * The tier every site can use. | ||
| */ | ||
| const FREE = 'free'; | ||
|
|
||
| /** | ||
| * The tier of a theme as WordPress.com returns it. | ||
| * | ||
| * @param stdClass $theme A theme from the WordPress.com themes API. | ||
| * @return string Tier slug, premium for a theme that reports none. | ||
| */ | ||
| public static function tier_of( $theme ): string { | ||
| return $theme->theme_tier->slug ?? 'premium'; | ||
| } | ||
|
|
||
| /** | ||
| * The capability name gating a tier. | ||
| * | ||
| * @param string $tier Tier slug. | ||
| * @return string | ||
| */ | ||
| public static function feature_for( string $tier ): string { | ||
| return $tier . '-themes'; | ||
| } | ||
|
|
||
| /** | ||
| * Whether this site's plan includes a tier. | ||
| * | ||
| * Necessary but not sufficient for the partner tier, which every paid plan includes while each | ||
| * partner theme still needs its own subscription that no plan feature reports. | ||
| * | ||
| * @param string $tier Tier slug. | ||
| * @return bool True for the free tier, which needs no plan. For the rest, false when the | ||
| * platform cannot answer, so an unknown host offers nothing. | ||
| */ | ||
| public static function site_can_use( string $tier ): bool { | ||
| // There is no free-themes capability, so asking the platform would deny every free theme. | ||
| if ( self::FREE === $tier ) { | ||
| return true; | ||
| } | ||
|
|
||
| return function_exists( 'wpcom_site_has_feature' ) | ||
| && (bool) wpcom_site_has_feature( self::feature_for( $tier ) ); | ||
| } | ||
| } | ||
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.