From 2766df98d2e8b78e6d45559ab6d3ee068bc0270f Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 12 Feb 2025 03:40:23 +0000 Subject: [PATCH] Editor: Fix complex variation selectors when using selectors API. Fixes a bug in the manipulation of selectors for block style variations that would result in an incorrect selector and fail to match the appropriate elements on the frontend. Props aaronrobertshaw, ramonopoly, joemcgill. Fixes #62471. Built from https://develop.svn.wordpress.org/trunk@59814 git-svn-id: http://core.svn.wordpress.org/trunk@59156 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json.php | 10 ++++++++-- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index 7f45040221..dafbfb405c 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -2850,8 +2850,14 @@ class WP_Theme_JSON { // 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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 14d45e4f52..c86ad3ee7c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59813'; +$wp_version = '6.8-alpha-59814'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.