Skip to content

Commit

Permalink
Fix variation selectors using selectors API
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Nov 18, 2024
1 parent f3b3fff commit 7b2d197
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2874,8 +2874,14 @@ public function get_styles_for_block( $block_metadata ) {

// Combine selectors with style variation's selector and add to overall style variation declarations.
foreach ( $variation_declarations as $current_selector => $new_declarations ) {
// If current selector includes block classname, remove it but leave the whitespace in.
$shortened_selector = str_replace( $block_metadata['selector'] . ' ', ' ', $current_selector );
/*
* Clean up any whitespace between comma separated selectors.
* This prevents these spaces breaking compound selectors such as:
* - `.wp-block-list:not(.wp-block-list .wp-block-list)`
* - `.wp-block-image img, .wp-block-image.my-class img`
*/
$clean_current_selector = preg_replace( '/,\s+/', ',', $current_selector );
$shortened_selector = str_replace( $block_metadata['selector'], '', $clean_current_selector );

// Prepend the variation selector to the current selector.
$split_selectors = explode( ',', $shortened_selector );
Expand Down

0 comments on commit 7b2d197

Please sign in to comment.