diff --git a/backport-changelog/6.6/6797.md b/backport-changelog/6.6/6797.md new file mode 100644 index 00000000000000..630b677655ddce --- /dev/null +++ b/backport-changelog/6.6/6797.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/6797 + +* https://github.com/WordPress/gutenberg/pull/62526 \ No newline at end of file diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 3f45b137d186d2..84715827342b4e 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -2694,6 +2694,7 @@ public function get_styles_for_block( $block_metadata ) { // 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() ); @@ -2720,9 +2721,12 @@ static function ( $split_selector ) use ( $clean_style_variation_selector ) { // Add the new declarations to the overall results under the modified selector. $style_variation_declarations[ $combined_selectors ] = $new_declarations; } - // 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'] ); + } } } @@ -2853,6 +2857,9 @@ static function ( $pseudo_selector ) use ( $selector ) { // 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 ]; + } } return $block_rules; diff --git a/packages/block-editor/src/components/global-styles/use-global-styles-output.js b/packages/block-editor/src/components/global-styles/use-global-styles-output.js index 28e1ddac9ab1d6..68839ea15d775e 100644 --- a/packages/block-editor/src/components/global-styles/use-global-styles-output.js +++ b/packages/block-editor/src/components/global-styles/use-global-styles-output.js @@ -651,7 +651,9 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => { ( [ variationName, variation ] ) => { variations[ variationName ] = pickStyleKeys( variation ); - + if ( variation?.css ) { + variations[ variationName ].css = variation.css; + } const variationSelector = blockSelectors[ blockName ] .styleVariationSelectors?.[ variationName ]; @@ -697,6 +699,14 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => { .featureSelectors ); + const variationBlockStyleNodes = + pickStyleKeys( variationBlockStyles ); + + if ( variationBlockStyles?.css ) { + variationBlockStyleNodes.css = + variationBlockStyles.css; + } + nodes.push( { selector: variationBlockSelector, duotoneSelector: variationDuotoneSelector, @@ -707,9 +717,7 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => { hasLayoutSupport: blockSelectors[ variationBlockName ] .hasLayoutSupport, - styles: pickStyleKeys( - variationBlockStyles - ), + styles: variationBlockStyleNodes, } ); // Process element styles for the inner blocks @@ -995,6 +1003,12 @@ export const toStyles = ( ';' ) };}`; } + if ( styles?.css ) { + ruleset += processCSSNesting( + styles.css, + `:root :where(${ selector })` + ); + } if ( styleVariationSelectors ) { Object.entries( styleVariationSelectors ).forEach( @@ -1041,6 +1055,12 @@ export const toStyles = ( ';' ) };}`; } + if ( styleVariations?.css ) { + ruleset += processCSSNesting( + styleVariations.css, + `:root :where(${ styleVariationSelector })` + ); + } } } );