Skip to content

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Nov 23, 2025

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 during WP_Theme_JSON sanitization. This occurred because:

  1. WP_Theme_JSON::sanitize() only preserves variations that exist in $valid_variations
  2. $valid_variations is populated from WP_Block_Styles_Registry (registered block styles)
  3. The revisions controller wasn't registering theme-defined variations before instantiation
  4. Unregistered variations were stripped by remove_keys_not_in_schema()

Why This Matters

  • Gutenberg works, Core doesn't: Gutenberg registers variations late through WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()
  • Data loss: Revision history was losing block style variation data
  • Inconsistent behavior: Different outcomes depending on request lifecycle/initialization order

Solution

Register theme-defined block style variations in WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response() before instantiating WP_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.php

Testing 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:

await wp.data.resolveSelect( 'core' ).getRevisions( 'root', 'globalStyles', await wp.data.resolveSelect( 'core' ).__experimentalGetCurrentGlobalStylesId() )

Run the test suite for bonus points

npm run test:php -- --filter=WP_REST_Global_Styles_Revisions_Controller_Test

Props

@ellatrix for finding the bug in WordPress/gutenberg#73440 and @aaronrobertshaw for initial investigation

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.
@ramonjd ramonjd self-assigned this Nov 23, 2025
@github-actions
Copy link

github-actions bot commented Nov 23, 2025

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ramonopoly, aaronrobertshaw, ellatrix.

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.
@github-actions
Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link

@aaronrobertshaw aaronrobertshaw left a 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

Screenshot 2025-11-24 at 5 31 03 pm

✅ Automated test coverage looks good and all passes locally

Screenshot 2025-11-24 at 5 26 46 pm

@ellatrix
Copy link
Member

Do you know when it was introduced?

@ramonjd
Copy link
Member Author

ramonjd commented Nov 24, 2025

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]>
@ramonjd
Copy link
Member Author

ramonjd commented Nov 24, 2025

Thanks for testing @aaronrobertshaw 🙇🏻

@ramonjd
Copy link
Member Author

ramonjd commented Nov 25, 2025

@ramonjd ramonjd closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants