Make WordPress Core

Changeset 57352


Ignore:
Timestamp:
01/25/2024 10:41:38 AM (9 months ago)
Author:
youknowriad
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r57340 r57352  
    936936                if ( $duotone_support ) {
    937937                    $root_selector    = wp_get_block_css_selector( $block_type );
    938                     $duotone_selector = WP_Theme_JSON::scope_selector( $root_selector, $duotone_support );
     938                    $duotone_selector = static::scope_selector( $root_selector, $duotone_support );
    939939                }
    940940            }
     
    10791079            }
    10801080            if ( false !== $root_style_key ) {
    1081                 $setting_nodes[ $root_style_key ]['selector'] = $options['root_selector'];
     1081                $style_nodes[ $root_style_key ]['selector'] = $options['root_selector'];
    10821082            }
    10831083        }
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r57333 r57352  
    32113211     * @param array $styles An array with style definitions.
    32123212     * @param array $path   Path to the desired properties.
    3213      *
    32143213     */
    32153214    public function test_get_property_value_should_return_string_for_invalid_paths_or_null_values( $styles, $path ) {
     
    49404939        $this->assertEquals( $secondary_color, $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Block variations: color' );
    49414940    }
     4941
     4942    /**
     4943     * Tests that a custom root selector is correctly applied when generating a stylesheet.
     4944     *
     4945     * @ticket 60343
     4946     */
     4947    public function test_get_stylesheet_custom_root_selector() {
     4948        $theme_json = new WP_Theme_JSON(
     4949            array(
     4950                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     4951                'styles'  => array(
     4952                    'color' => array(
     4953                        'text' => 'teal',
     4954                    ),
     4955                ),
     4956            ),
     4957            'default'
     4958        );
     4959
     4960        $options = array( 'root_selector' => '.custom' );
     4961        $actual  = $theme_json->get_stylesheet( array( 'styles' ), null, $options );
     4962
     4963        // Results also include root site blocks styles which hard code
     4964        // `body { margin: 0;}`.
     4965        $this->assertEquals(
     4966            '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;}',
     4967            $actual
     4968        );
     4969    }
    49424970}
Note: See TracChangeset for help on using the changeset viewer.