Make WordPress Core


Ignore:
Timestamp:
12/06/2021 10:40:45 PM (3 years ago)
Author:
hellofromTonya
Message:

Editor: Allow theme.json to take precedence in setting the root level element's reset margin value.

Any margin added to the root element via theme.json is overwritten by a CSS reset margin value provided by the Gutenberg Plugin.

This commit makes theme.json setting take precedence by generating the global styles body reset prior to processing the theme.json.

Follow-up to [52049].

Props get_dave, hellofromTonya.
Fixes #54550.

File:
1 edited

Legend:

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

    r52321 r52329  
    356356     * @since 5.8.0
    357357     *
    358      * @param array $theme_json A structure that follows the theme.json schema.
    359      * @param string $origin    Optional. What source of data this object represents.
    360      *                          One of 'default', 'theme', or 'custom'. Default 'theme'.
     358     * @param array  $theme_json A structure that follows the theme.json schema.
     359     * @param string $origin     Optional. What source of data this object represents.
     360     *                           One of 'default', 'theme', or 'custom'. Default 'theme'.
    361361     */
    362362    public function __construct( $theme_json = array(), $origin = 'theme' ) {
     
    777777            }
    778778
     779            /*
     780             * Reset default browser margin on the root body element.
     781             * This is set on the root selector **before** generating the ruleset
     782             * from the `theme.json`. This is to ensure that if the `theme.json` declares
     783             * `margin` in its `spacing` declaration for the `body` element then these
     784             * user-generated values take precedence in the CSS cascade.
     785             * @link https://github.com/WordPress/gutenberg/issues/36147.
     786             */
     787            if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
     788                $block_rules .= 'body { margin: 0; }';
     789            }
     790
    779791            // 2. Generate the rules that use the general selector.
    780792            $block_rules .= self::to_ruleset( $selector, $declarations );
     
    787799
    788800            if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
    789                 $block_rules .= 'body { margin: 0; }';
    790801                $block_rules .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
    791802                $block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
Note: See TracChangeset for help on using the changeset viewer.