From 6f9de6388cb86d9ea17c3e37dbdac9a69783814c Mon Sep 17 00:00:00 2001 From: isabel_brison Date: Thu, 30 May 2024 04:40:07 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-theme-json.php | 35 ++++++++++++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index 3dba653520..7cc87759ab 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -1199,7 +1199,7 @@ class WP_Theme_JSON { $node['selector'] = static::scope_selector( $options['scope'], $node['selector'] ); } 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 ); } @@ -1825,6 +1825,39 @@ class WP_Theme_JSON { 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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 79a32170cc..8373aff672 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @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.