Make WordPress Core


Ignore:
Timestamp:
02/12/2025 03:38:09 AM (2 months ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r59802 r59814  
    28512851                // Combine selectors with style variation's selector and add to overall style variation declarations.
    28522852                foreach ( $variation_declarations as $current_selector => $new_declarations ) {
    2853                     // If current selector includes block classname, remove it but leave the whitespace in.
    2854                     $shortened_selector = str_replace( $block_metadata['selector'] . ' ', ' ', $current_selector );
     2853                    /*
     2854                     * Clean up any whitespace between comma separated selectors.
     2855                     * This prevents these spaces breaking compound selectors such as:
     2856                     * - `.wp-block-list:not(.wp-block-list .wp-block-list)`
     2857                     * - `.wp-block-image img, .wp-block-image.my-class img`
     2858                     */
     2859                    $clean_current_selector = preg_replace( '/,\s+/', ',', $current_selector );
     2860                    $shortened_selector     = str_replace( $block_metadata['selector'], '', $clean_current_selector );
    28552861
    28562862                    // Prepend the variation selector to the current selector.
Note: See TracChangeset for help on using the changeset viewer.