Make WordPress Core

Changeset 58028


Ignore:
Timestamp:
04/22/2024 05:28:50 AM (8 weeks ago)
Author:
isabel_brison
Message:

Editor: limit layout rules on themes without theme.json.

Removes output of base rules for flow and constrained layout types on themes without theme.json.

Props evanltd, poena, isabel_brison, andrewserong, oandregal.
See #60981.

Location:
trunk
Files:
2 edited

Legend:

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

    r57987 r58028  
    12281228
    12291229            foreach ( $base_styles_nodes as $base_style_node ) {
    1230                 $stylesheet .= $this->get_layout_styles( $base_style_node );
     1230                $stylesheet .= $this->get_layout_styles( $base_style_node, $types );
    12311231            }
    12321232        }
     
    13901390     * @since 6.3.0 Reduced specificity for layout margin rules.
    13911391     * @since 6.5.1 Only output rules referencing content and wide sizes when values exist.
     1392     * @since 6.5.3 Add types parameter to check if only base layout styles are needed.
    13921393     *
    13931394     * @param array $block_metadata Metadata about the block to get styles for.
     1395     * @param array $types Optional. Types of styles to output. If empty, all styles will be output.
    13941396     * @return string Layout styles for the block.
    13951397     */
    1396     protected function get_layout_styles( $block_metadata ) {
     1398    protected function get_layout_styles( $block_metadata, $types = array() ) {
    13971399        $block_rules = '';
    13981400        $block_type  = null;
     
    15431545                    foreach ( $base_style_rules as $base_style_rule ) {
    15441546                        $declarations = array();
     1547
     1548                        // Skip outputting base styles for flow and constrained layout types if theme doesn't support theme.json. The 'base-layout-styles' type flags this.
     1549                        if ( in_array( 'base-layout-styles', $types, true ) && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) {
     1550                            continue;
     1551                        }
    15451552
    15461553                        if (
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r57987 r58028  
    12611261        // Note the `base-layout-styles` includes a fallback gap for the Columns block for backwards compatibility.
    12621262        $this->assertSame(
    1263             ':where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width: var(--wp--style--global--content-size);margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignwide{max-width: var(--wp--style--global--wide-size);}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}:where(.wp-block-columns.is-layout-flex){gap: 2em;}:where(.wp-block-columns.is-layout-grid){gap: 2em;}:where(.wp-block-post-template.is-layout-flex){gap: 1.25em;}:where(.wp-block-post-template.is-layout-grid){gap: 1.25em;}',
     1263            ':where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}:where(.wp-block-columns.is-layout-flex){gap: 2em;}:where(.wp-block-columns.is-layout-grid){gap: 2em;}:where(.wp-block-post-template.is-layout-flex){gap: 1.25em;}:where(.wp-block-post-template.is-layout-grid){gap: 1.25em;}',
    12641264            $stylesheet
    12651265        );
Note: See TracChangeset for help on using the changeset viewer.