Skip to content

Commit c11b2aa

Browse files
committed
Global Styles Revisions: Preserve block style variations in global styles revisions
When retrieving global styles revisions through the REST API, any block style variations (e.g., `styles.blocks.core/group.variations.my-variation`) are being removed during `WP_Theme_JSON` sanitization. `WP_Theme_JSON` will only allow block style variations that are registered. This means user modifications to any theme block style variations were being stripped from global styles revisions when retrieved via the REST API. This commit registers theme-defined block style variations in `WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response` so that they can be properly parsed by `WP_Theme_JSON`, and therefore added to the global styles revisions REST API GET response. Props ramonopoly, aaronrobertshaw, ellatrix. Fixes #64292. git-svn-id: https://develop.svn.wordpress.org/trunk@61301 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2898ab5 commit c11b2aa

File tree

2 files changed

+403
-0
lines changed

2 files changed

+403
-0
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,15 @@ public function prepare_item_for_response( $post, $request ) {
312312
$theme_json = null;
313313

314314
if ( ! empty( $global_styles_config['styles'] ) || ! empty( $global_styles_config['settings'] ) ) {
315+
/*
316+
* Register block style variations from the theme data.
317+
* This is required so the variations pass sanitization of theme.json data.
318+
*/
319+
if ( ! empty( $global_styles_config['styles']['blocks'] ) ) {
320+
$variations = WP_Theme_JSON_Resolver::get_style_variations( 'block' );
321+
wp_register_block_style_variations_from_theme_json_partials( $variations );
322+
}
323+
315324
$theme_json = new WP_Theme_JSON( $global_styles_config, 'custom' );
316325
$global_styles_config = $theme_json->get_raw_data();
317326
if ( rest_is_field_included( 'settings', $fields ) ) {

0 commit comments

Comments
 (0)