Global Styles: Fix registration of theme style variation defined block styles #62495
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.
Addresses WordPress/wordpress-develop#6756 (comment)
What?
Ensures theme style variation defined block style variations are supported when saving global styles via the the REST API.
Why?
If block style variations aren't registered they are stripping out during the sanitization of theme json data. This makes it appear as though global style customizations have been lost until the editor is reloaded.
How?
When a theme style variation is selected, its values are copied into the user origin data to be saved. This includes the shared block style variation definitions that need registering.
The REST API has been updated to register shared block style variations prior to saving the global styles. This maintains the data for variations they weren't able to be registered via the normal
init
filter.Testing Instructions
styles/ember.json
(theme style variation) file, paste the following under styles.blocks.variations:VariationDark
variation by going to "Global Styles > Blocks > Group > VariationDark". Modify the background color to something else.npm run test:unit:php:base -- --filter WP_REST_Global_Styles_Controller_Gutenberg_Test::test_update_item_with_custom_block_style_variations
Screenshots or screencast
Screen.Recording.2024-06-12.at.12.26.30.PM.mp4
Screen.Recording.2024-06-12.at.12.25.44.PM.mp4