Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3980,9 +3980,19 @@ public function get_styles_for_block( $block_metadata ) {
$variation_pseudo_declarations = $this->process_pseudo_selectors( $style_variation_node, $style_variation['selector'], $settings, $block_name, $block_metadata, $style_variation );
$style_variation_declarations = array_merge( $style_variation_declarations, $variation_pseudo_declarations );

// Custom CSS targets the block's `css` feature selector, if any.
$variation_css_selector = $style_variation['selector'];
$css_feature_selector = $block_metadata['selectors']['css'] ?? null;
if ( is_array( $css_feature_selector ) ) {
$css_feature_selector = $css_feature_selector['root'] ?? null;
}
if ( is_string( $css_feature_selector ) ) {
$variation_css_selector = static::get_block_style_variation_feature_selector( $style_variation, $css_feature_selector );
}

Comment on lines +3992 to +3996

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be set each time in the loop over style variations? Bit of a nit-picky comment, but if not, then setting $variation_css_selector could move somewhere further up, i.e. before the foreach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does because the selector will be slightly different for each variation, but the bit that fetches the feature selector from block metadata can be extracted. I've just pushed a change to do so!

// 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'] );
$style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $variation_css_selector );
}

// Store variation metadata and node for layout styles generation.
Expand Down Expand Up @@ -4048,7 +4058,7 @@ public function get_styles_for_block( $block_metadata ) {

// Process custom CSS for this breakpoint.
if ( isset( $breakpoint_node['css'] ) ) {
$breakpoint_custom_css = static::process_blocks_custom_css( $breakpoint_node['css'], $style_variation['selector'] );
$breakpoint_custom_css = static::process_blocks_custom_css( $breakpoint_node['css'], $variation_css_selector );
$variation_responsive_css .= $breakpoint_media . '{' . $breakpoint_custom_css . '}';
}

Expand Down
Loading