Repository navigation
Editor: Cache the theme.json data merged from all origins #14071
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0af082b
Editor: Cache the theme.json data merged from all origins.
sirreal b1f3806
Editor: Remove the object cache from wp_get_global_settings().
sirreal 75a6e42
Editor: Store and clone the merged data at one exit of get_merged_dat…
sirreal 6cbc280
Editor: Test the settings accessor's behavior, not the absence of the…
sirreal c68189c
Editor: Name the settings accessor test after the behavior it checks.
sirreal fef4674
Merge branch 'trunk' into theme-json/cache-merged-data
sirreal 41d6595
Merge branch 'trunk' into theme-json/cache-merged-data
sirreal ef87252
Editor: Add the ticket annotation to the merged data cache tests.
sirreal 2df838c
Editor: Test that wp_get_global_styles() reflects late block registra…
sirreal 1458bb3
Editor: Read global styles per layout block instead of once per request.
sirreal 2ffbb7a
Editor: Declare types on the merged data cache tests.
sirreal 80210a7
Merge branch 'trunk' into theme-json/cache-merged-data
peterwilsoncc cde8b56
Remove unneeded tear downs.
peterwilsoncc be84046
Comment explaining needed tear down.
peterwilsoncc 83610ee
Merge branch 'trunk' into theme-json/cache-merged-data
sirreal 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests wp_get_global_settings(). | ||
| * | ||
| * @group themes | ||
| * | ||
| * @covers ::wp_get_global_settings | ||
| */ | ||
| class Tests_Theme_wpGetGlobalSettings extends WP_UnitTestCase { | ||
|
|
||
| public function tear_down(): void { | ||
| // Required to reset properties in WP_Theme_JSON_Resolver. | ||
| wp_clean_theme_json_cache(); | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 66280 | ||
| */ | ||
| public function test_reflects_theme_data_changed_after_a_previous_call(): void { | ||
| wp_get_global_settings(); | ||
|
|
||
| // Block registration adds no settings, so inject one through the theme data | ||
| // filter: registering a block refreshes the theme data, which reapplies the filter. | ||
| $filter = static function ( WP_Theme_JSON_Data $theme_json ): WP_Theme_JSON_Data { | ||
| return $theme_json->update_with( | ||
| array( | ||
| 'version' => WP_Theme_JSON::LATEST_SCHEMA, | ||
| 'settings' => array( | ||
| 'custom' => array( 'cacheProbe' => 'fresh' ), | ||
| ), | ||
| ) | ||
| ); | ||
| }; | ||
| add_filter( 'wp_theme_json_data_theme', $filter ); | ||
| register_block_type( 'test/block-settings' ); | ||
|
|
||
| $settings = wp_get_global_settings(); | ||
|
|
||
| unregister_block_type( 'test/block-settings' ); | ||
|
|
||
| $this->assertSame( | ||
| 'fresh', | ||
| $settings['custom']['cacheProbe'] ?? null, | ||
| 'Settings from theme data changed after a previous call should be present.' | ||
| ); | ||
| } | ||
| } | ||
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,44 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests wp_get_global_styles(). | ||
| * | ||
| * @group themes | ||
| * | ||
| * @covers ::wp_get_global_styles | ||
| */ | ||
| class Tests_Theme_wpGetGlobalStyles extends WP_UnitTestCase { | ||
|
|
||
| public function tear_down(): void { | ||
| wp_clean_theme_json_cache(); | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 66280 | ||
| */ | ||
| public function test_reflects_blocks_registered_after_a_previous_call(): void { | ||
| wp_get_global_styles(); | ||
|
|
||
| register_block_type( | ||
| 'test/block-gap', | ||
| array( | ||
| 'supports' => array( | ||
| '__experimentalStyle' => array( | ||
| 'spacing' => array( 'blockGap' => '77px' ), | ||
| ), | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $styles = wp_get_global_styles(); | ||
|
|
||
| unregister_block_type( 'test/block-gap' ); | ||
|
|
||
| $this->assertSame( | ||
| '77px', | ||
| $styles['blocks']['test/block-gap']['spacing']['blockGap'] ?? null, | ||
| 'Styles for a block registered after a previous call should be present.' | ||
| ); | ||
| } | ||
| } |
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.