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.

Built from https://develop.svn.wordpress.org/trunk@58244


git-svn-id: http://core.svn.wordpress.org/trunk@57707 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
isabel_brison 2024-05-30 04:40:07 +00:00
parent f7515f439f
commit 6f9de6388c
2 changed files with 35 additions and 2 deletions

View File

@ -1199,7 +1199,7 @@ class WP_Theme_JSON {
$node['selector'] = static::scope_selector( $options['scope'], $node['selector'] ); $node['selector'] = static::scope_selector( $options['scope'], $node['selector'] );
} }
foreach ( $style_nodes as &$node ) { foreach ( $style_nodes as &$node ) {
$node['selector'] = static::scope_selector( $options['scope'], $node['selector'] ); $node = static::scope_style_node_selectors( $options['scope'], $node );
} }
unset( $node ); unset( $node );
} }
@ -1825,6 +1825,39 @@ class WP_Theme_JSON {
return $result; return $result;
} }
/**
* Scopes the selectors for a given style node.
*
* This includes the primary selector, i.e. `$node['selector']`, as well as any custom
* selectors for features and subfeatures, e.g. `$node['selectors']['border']` etc.
*
* @since 6.6.0
*
* @param string $scope Selector to scope to.
* @param array $node Style node with selectors to scope.
* @return array Node with updated selectors.
*/
protected static function scope_style_node_selectors( $scope, $node ) {
$node['selector'] = static::scope_selector( $scope, $node['selector'] );
if ( empty( $node['selectors'] ) ) {
return $node;
}
foreach ( $node['selectors'] as $feature => $selector ) {
if ( is_string( $selector ) ) {
$node['selectors'][ $feature ] = static::scope_selector( $scope, $selector );
}
if ( is_array( $selector ) ) {
foreach ( $selector as $subfeature => $subfeature_selector ) {
$node['selectors'][ $feature ][ $subfeature ] = static::scope_selector( $scope, $subfeature_selector );
}
}
}
return $node;
}
/** /**
* Gets preset values keyed by slugs based on settings and metadata. * Gets preset values keyed by slugs based on settings and metadata.
* *

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-alpha-58243'; $wp_version = '6.6-alpha-58244';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.