-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Global Styles: Preserve block style variations in global styles revisions. #10541
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
Global Styles: Preserve block style variations in global styles revisions. #10541
Conversation
This update ensures that block style variations are registered and preserved when creating and retrieving revisions of global styles. New tests have been added to verify that variations are correctly maintained across revisions, including scenarios with multiple variations and theme-defined variations.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…292. This commit updates the test cases in the `rest-global-styles-revisions-controller.php` file to link the preservation of block style variations in revisions to the specific ticket #64292, ensuring better tracking and documentation of the related functionality.
This commit refactors the test cases in `rest-global-styles-revisions-controller.php` to improve code consistency by aligning variable assignments and formatting. The changes enhance readability without altering the test logic.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fast work on this fix @ramonjd 🙇
It's testing well for me. I have one tiny nit regarding the inline comment but other than that, it LGTM.
✅ Manual testing via site editor, creating revisions with variations data, applying them etc all works
Screen.Recording.2025-11-24.at.5.28.53.pm.mp4
✅ API response contains correct variations styles data
✅ Automated test coverage looks good and all passes locally
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php
Outdated
Show resolved
Hide resolved
|
Do you know when it was introduced? |
Style variations have been a thing since May/June 2024. See: First added to Core in f91931a |
…-revisions-controller.php Co-authored-by: Aaron Robertshaw <[email protected]>
|
Thanks for testing @aaronrobertshaw 🙇🏻 |
|
Committed in https://core.trac.wordpress.org/changeset/61301 |
Description
Fixes an issue where block style variations were being stripped from global styles revisions when retrieved via the REST API.
Trac ticket: https://core.trac.wordpress.org/ticket/64292
Problem
When retrieving global styles revisions through the REST API, any block style variations (e.g.,
styles.blocks.core/group.variations.my-variation) were being removed duringWP_Theme_JSONsanitization. This occurred because:WP_Theme_JSON::sanitize()only preserves variations that exist in$valid_variations$valid_variationsis populated fromWP_Block_Styles_Registry(registered block styles)remove_keys_not_in_schema()Why This Matters
WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()Solution
Register theme-defined block style variations in
WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response()before instantiatingWP_Theme_JSON, ensuring variations pass sanitization regardless of initialization order.Changed file:
src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.phpTesting Instructions
Switch to a theme with block style variations (e.g., Twenty Twenty-Five)
Go to Global styles > Group and select a style variation
Change the style variation and save. Create a few revisions.
In the site editor, apply the variation to a group block and save the post.
Now open the global styles > revisions and ensure that, when you click on a past revision the style variation applies to the group block.
Kapture.2025-11-23.at.18.28.40.mp4
You can also check that the REST API returns the full revisions:
Run the test suite for bonus points
Props
@ellatrix for finding the bug in WordPress/gutenberg#73440 and @aaronrobertshaw for initial investigation