From 93177aa249022605aadee47012e9447cf5358668 Mon Sep 17 00:00:00 2001 From: isabel_brison Date: Mon, 17 Jun 2024 03:49:11 +0000 Subject: [PATCH] Editor: fix custom CSS output for block style variations. Adds custom CSS to the block style variation rules output by `get_styles_for_block` in class `WP_Theme_JSON`. Props isabel_brison, aaronrobertshaw. Fixes #61425. Built from https://develop.svn.wordpress.org/trunk@58421 git-svn-id: http://core.svn.wordpress.org/trunk@57870 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json.php | 14 ++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index 05f5e7b9e7..d4c52e92e0 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -2647,6 +2647,7 @@ class WP_Theme_JSON { * @since 6.1.0 * @since 6.6.0 Setting a min-height of HTML when root styles have a background gradient or image. * Updated general global styles specificity to 0-1-0. + * Fixed custom CSS output in block style variations. * * @param array $block_metadata Metadata about the block to get styles for. * @@ -2662,6 +2663,7 @@ class WP_Theme_JSON { // If there are style variations, generate the declarations for them, including any feature selectors the block may have. $style_variation_declarations = array(); + $style_variation_custom_css = array(); if ( ! empty( $block_metadata['variations'] ) ) { foreach ( $block_metadata['variations'] as $style_variation ) { $style_variation_node = _wp_array_get( $this->theme_json, $style_variation['path'], array() ); @@ -2691,6 +2693,10 @@ class WP_Theme_JSON { // Compute declarations for remaining styles not covered by feature level selectors. $style_variation_declarations[ $style_variation['selector'] ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json ); + // Store custom CSS for the style variation. + if ( isset( $style_variation_node['css'] ) ) { + $style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $style_variation['selector'] ); + } } } /* @@ -2819,6 +2825,14 @@ class WP_Theme_JSON { // 6. Generate and append the style variation rulesets. foreach ( $style_variation_declarations as $style_variation_selector => $individual_style_variation_declarations ) { $block_rules .= static::to_ruleset( ":root :where($style_variation_selector)", $individual_style_variation_declarations ); + if ( isset( $style_variation_custom_css[ $style_variation_selector ] ) ) { + $block_rules .= $style_variation_custom_css[ $style_variation_selector ]; + } + } + + // 7. Generate and append any custom CSS rules pertaining to nested block style variations. + if ( isset( $node['css'] ) && ! $is_root_selector ) { + $block_rules .= $this->process_blocks_custom_css( $node['css'], $selector ); } return $block_rules; diff --git a/wp-includes/version.php b/wp-includes/version.php index 0feb50382a..d5bf6e7896 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-beta2-58420'; +$wp_version = '6.6-beta2-58421'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.