Make WordPress Core


Ignore:
Timestamp:
01/30/2026 02:09:32 AM (8 months ago)
Author:
isabel_brison
Message:

Editor: fix blockGap styles in block style variations.

Ensures that when a block style variation declares a blockGap value, the correct layout styles are output for the variation.

Props isabel_brison, aaronrobertshaw.
Fixes #64533.

File:
1 edited

Legend:

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

    r61473 r61564  
    16161616                $has_block_gap_support    = isset( $this->theme_json['settings']['spacing']['blockGap'] );
    16171617                $has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
    1618                 $node                     = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
     1618                $node                     = $options['node'] ?? _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
    16191619                $layout_definitions       = wp_get_layout_definitions();
    16201620                $layout_selector_pattern  = '/^[a-zA-Z0-9\-\.\,\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors.
    … …  
    23572357                        }
    23582358
    2359                         /*
    2360                          * Look up protected properties, keyed by value path.
    2361                          * Skip protected properties that are explicitly set to `null`.
    2362                          */
    2363                         $path_string = implode( '.', $value_path );
    2364                         if (
    2365                                 isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&
    2366                                 _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
    2367                         ) {
    2368                                 continue;
    2369                         }
    2370 
    23712359                        // Calculates fluid typography rules where available.
    23722360                        if ( 'font-size' === $css_property ) {
    … …  
    28122800
    28132801                // If there are style variations, generate the declarations for them, including any feature selectors the block may have.
    2814                 $style_variation_declarations = array();
    2815                 $style_variation_custom_css   = array();
     2802                $style_variation_declarations    = array();
     2803                $style_variation_custom_css      = array();
     2804                $style_variation_layout_metadata = array();
    28162805                if ( ! empty( $block_metadata['variations'] ) ) {
    28172806                        foreach ( $block_metadata['variations'] as $style_variation ) {
    … …  
    28522841                                if ( isset( $style_variation_node['css'] ) ) {
    28532842                                        $style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $style_variation['selector'] );
     2843                                }
     2844
     2845                                // Store variation metadata and node for layout styles generation.
     2846                                // Only store if the variation has blockGap defined.
     2847                                if ( isset( $style_variation_node['spacing']['blockGap'] ) ) {
     2848                                        // Append block selector to the variation selector for proper targeting.
     2849                                        $variation_metadata_with_selector                                = $style_variation;
     2850                                        $variation_metadata_with_selector['selector']                    = $style_variation['selector'] . $block_metadata['css'];
     2851                                        $style_variation_layout_metadata[ $style_variation['selector'] ] = array(
     2852                                                'metadata' => $variation_metadata_with_selector,
     2853                                                'node'     => $style_variation_node,
     2854                                        );
    28542855                                }
    28552856                        }
    … …  
    30053006                foreach ( $style_variation_declarations as $style_variation_selector => $individual_style_variation_declarations ) {
    30063007                        $block_rules .= static::to_ruleset( ":root :where($style_variation_selector)", $individual_style_variation_declarations );
     3008                        if ( isset( $style_variation_layout_metadata[ $style_variation_selector ] ) ) {
     3009                                $variation_data = $style_variation_layout_metadata[ $style_variation_selector ];
     3010                                $block_rules   .= $this->get_layout_styles( $variation_data['metadata'], array( 'node' => $variation_data['node'] ) );
     3011                        }
    30073012                        if ( isset( $style_variation_custom_css[ $style_variation_selector ] ) ) {
    30083013                                $block_rules .= $style_variation_custom_css[ $style_variation_selector ];
    … …  
    30803085                }
    30813086
    3082                 // Block gap styles will be output unless explicitly set to `null`. See static::PROTECTED_PROPERTIES.
     3087                // Block gap styles will be output unless explicitly set to `null`.
    30833088                if ( isset( $this->theme_json['settings']['spacing']['blockGap'] ) ) {
    30843089                        $block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
Note: See TracChangeset for help on using the changeset viewer.