Make WordPress Core


Ignore:
Timestamp:
05/30/2024 04:38:26 AM (20 months ago)
Author:
isabel_brison
Message:

Editor: Add scoping of feature level global styles selectors.

Ensures that feature-level selectors for block style variations are correctly scoped when generating a theme.json stylesheet.

Props aaronrobertshaw, audrasjb, vcanales, isabel_brison.
Fixes #61119.

File:
1 edited

Legend:

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

    r58242 r58244  
    12001200            }
    12011201            foreach ( $style_nodes as &$node ) {
    1202                 $node['selector'] = static::scope_selector( $options['scope'], $node['selector'] );
     1202                $node = static::scope_style_node_selectors( $options['scope'], $node );
    12031203            }
    12041204            unset( $node );
     
    18241824        $result = implode( ', ', $selectors_scoped );
    18251825        return $result;
     1826    }
     1827
     1828    /**
     1829     * Scopes the selectors for a given style node.
     1830     *
     1831     * This includes the primary selector, i.e. `$node['selector']`, as well as any custom
     1832     * selectors for features and subfeatures, e.g. `$node['selectors']['border']` etc.
     1833     *
     1834     * @since 6.6.0
     1835     *
     1836     * @param string $scope Selector to scope to.
     1837     * @param array  $node  Style node with selectors to scope.
     1838     * @return array Node with updated selectors.
     1839     */
     1840    protected static function scope_style_node_selectors( $scope, $node ) {
     1841        $node['selector'] = static::scope_selector( $scope, $node['selector'] );
     1842
     1843        if ( empty( $node['selectors'] ) ) {
     1844            return $node;
     1845        }
     1846
     1847        foreach ( $node['selectors'] as $feature => $selector ) {
     1848            if ( is_string( $selector ) ) {
     1849                $node['selectors'][ $feature ] = static::scope_selector( $scope, $selector );
     1850            }
     1851            if ( is_array( $selector ) ) {
     1852                foreach ( $selector as $subfeature => $subfeature_selector ) {
     1853                    $node['selectors'][ $feature ][ $subfeature ] = static::scope_selector( $scope, $subfeature_selector );
     1854                }
     1855            }
     1856        }
     1857
     1858        return $node;
    18261859    }
    18271860
Note: See TracChangeset for help on using the changeset viewer.