Make WordPress Core


Ignore:
Timestamp:
10/14/2026 05:12:04 AM (4 days ago)
Author:
isabel_brison
Message:

Editor: fix block style variation custom CSS selector

Ensures block style variations use the feature selector for custom CSS if the block defines one.

Props isabel_brison, andrewserong.
Fixes #66297.

File:
1 edited

Legend:

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

    r64309 r64340  
    39173917                $responsive_media_queries = static::get_viewport_media_queries( $settings['viewport'] ?? null );
    39183918
     3919                $css_feature_selector = $block_metadata['selectors']['css'] ?? null;
     3920                if ( is_array( $css_feature_selector ) ) {
     3921                        $css_feature_selector = $css_feature_selector['root'] ?? null;
     3922                }
     3923                if ( ! is_string( $css_feature_selector ) ) {
     3924                        $css_feature_selector = null;
     3925                }
     3926
    39193927                // Update text indent selector for paragraph blocks based on the textIndent setting.
    39203928                $block_name           = $block_metadata['name'] ?? null;
    … …  
    39663974                                $style_variation_declarations  = array_merge( $style_variation_declarations, $variation_pseudo_declarations );
    39673975
     3976                                // Custom CSS targets the block's `css` feature selector, if any.
     3977                                $variation_css_selector = null !== $css_feature_selector
     3978                                        ? static::get_block_style_variation_feature_selector( $style_variation, $css_feature_selector )
     3979                                        : $style_variation['selector'];
     3980
    39683981                                // Store custom CSS for the style variation.
    39693982                                if ( isset( $style_variation_node['css'] ) ) {
    3970                                         $style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $style_variation['selector'] );
     3983                                        $style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $variation_css_selector );
    39713984                                }
    39723985
    … …  
    40344047                                        // Process custom CSS for this breakpoint.
    40354048                                        if ( isset( $breakpoint_node['css'] ) ) {
    4036                                                 $breakpoint_custom_css     = static::process_blocks_custom_css( $breakpoint_node['css'], $style_variation['selector'] );
     4049                                                $breakpoint_custom_css     = static::process_blocks_custom_css( $breakpoint_node['css'], $variation_css_selector );
    40374050                                                $variation_responsive_css .= $breakpoint_media . '{' . $breakpoint_custom_css . '}';
    40384051                                        }
    … …  
    42784291                // 7. Generate and append any custom CSS rules.
    42794292                if ( isset( $node['css'] ) && ! $is_root_selector ) {
    4280                         $css_feature_selector = $block_metadata['selectors']['css'] ?? null;
    4281                         if ( is_array( $css_feature_selector ) ) {
    4282                                 $css_feature_selector = $css_feature_selector['root'] ?? null;
    4283                         }
    4284                         $css_selector = is_string( $css_feature_selector ) ? $css_feature_selector : $selector;
     4293                        $css_selector = $css_feature_selector ?? $selector;
    42854294                        $block_rules .= $this->process_blocks_custom_css( $node['css'], $css_selector );
    42864295                }
Note: See TracChangeset for help on using the changeset viewer.