Skip to content
Closed
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Editor: Fix Theme.json application of custom root selector for styles.
Theme.json stylesheets attempting to use a custom root selector are generated with in correct styles.

Props aaronrobertshaw, get_dave, mukesh27.
Fixes #60343.

git-svn-id: https://develop.svn.wordpress.org/trunk@57352 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
youknowriad committed Jan 25, 2024
commit 5bd13e7cc1a2f7b649c1b97e3ada88b8950ed2b6
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ protected static function get_blocks_metadata() {

if ( $duotone_support ) {
$root_selector = wp_get_block_css_selector( $block_type );
$duotone_selector = WP_Theme_JSON::scope_selector( $root_selector, $duotone_support );
$duotone_selector = static::scope_selector( $root_selector, $duotone_support );
}
}

Expand Down Expand Up @@ -1078,7 +1078,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
$setting_nodes[ $root_settings_key ]['selector'] = $options['root_selector'];
}
if ( false !== $root_style_key ) {
$setting_nodes[ $root_style_key ]['selector'] = $options['root_selector'];
$style_nodes[ $root_style_key ]['selector'] = $options['root_selector'];
}
}

Expand Down
30 changes: 29 additions & 1 deletion tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -3210,7 +3210,6 @@ public function test_get_property_value_valid() {
*
* @param array $styles An array with style definitions.
* @param array $path Path to the desired properties.
*
*/
public function test_get_property_value_should_return_string_for_invalid_paths_or_null_values( $styles, $path ) {
$reflection_class = new ReflectionClass( WP_Theme_JSON::class );
Expand Down Expand Up @@ -4939,4 +4938,33 @@ public function test_resolve_variables() {
$this->assertEquals( $small_font, $styles['blocks']['core/quote']['variations']['plain']['typography']['fontSize'], 'Block variations: font-size' );
$this->assertEquals( $secondary_color, $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Block variations: color' );
}

/**
* Tests that a custom root selector is correctly applied when generating a stylesheet.
*
* @ticket 60343
*/
public function test_get_stylesheet_custom_root_selector() {
$theme_json = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'styles' => array(
'color' => array(
'text' => 'teal',
),
),
),
'default'
);

$options = array( 'root_selector' => '.custom' );
$actual = $theme_json->get_stylesheet( array( 'styles' ), null, $options );

// Results also include root site blocks styles which hard code
// `body { margin: 0;}`.
$this->assertEquals(
'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.custom{color: teal;}',
$actual
);
}
}