diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index a893dfb6a9..6fd954705e 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -1032,7 +1032,7 @@ class WP_Theme_JSON { if ( ! empty( $block_type->styles ) ) { $style_selectors = array(); foreach ( $block_type->styles as $style ) { - $style_selectors[ $style['name'] ] = static::append_to_selector( '.is-style-' . $style['name'], static::$blocks_metadata[ $block_name ]['selector'] ); + $style_selectors[ $style['name'] ] = static::get_block_style_variation_selector( $style['name'], static::$blocks_metadata[ $block_name ]['selector'] ); } static::$blocks_metadata[ $block_name ]['styleVariations'] = $style_selectors; } @@ -3925,4 +3925,38 @@ class WP_Theme_JSON { $theme_json->theme_json['styles'] = self::convert_variables_to_value( $styles, $vars ); return $theme_json; } + + /** + * Generates a selector for a block style variation. + * + * @since 6.5.0 + * + * @param string $variation_name Name of the block style variation. + * @param string $block_selector CSS selector for the block. + * @return string Block selector with block style variation selector added to it. + */ + protected static function get_block_style_variation_selector( $variation_name, $block_selector ) { + $variation_class = ".is-style-$variation_name"; + + if ( ! $block_selector ) { + return $variation_class; + } + + $limit = 1; + $selector_parts = explode( ',', $block_selector ); + $result = array(); + + foreach ( $selector_parts as $part ) { + $result[] = preg_replace_callback( + '/((?::\([^)]+\))?\s*)([^\s:]+)/', + function ( $matches ) use ( $variation_class ) { + return $matches[1] . $matches[2] . $variation_class; + }, + $part, + $limit + ); + } + + return implode( ',', $result ); + } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 747479be94..31ec066f68 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-57546'; +$wp_version = '6.5-alpha-57547'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.