Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Styles: Add scoping of feature level selectors for custom block style variations #61033

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
$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 );
}
Expand Down Expand Up @@ -4039,4 +4039,37 @@ function ( $matches ) use ( $variation_class ) {

return implode( ',', $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;
}
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
}
Loading