Skip to content

Commit

Permalink
Layout: Skip outputting base layout rules that reference content or w…
Browse files Browse the repository at this point in the history
…ide sizes if no layout sizes exist (#60489)

* Layout: Skip outputting base layout rules that reference content or wide sizes if no content or wide sizes exist

* Update tests
  • Loading branch information
andrewserong committed Apr 5, 2024
1 parent b825410 commit 59a4104
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
10 changes: 10 additions & 0 deletions lib/class-wp-theme-json-gutenberg.php
Expand Up @@ -1614,6 +1614,16 @@ protected function get_layout_styles( $block_metadata ) {
! empty( $base_style_rule['rules'] )
) {
foreach ( $base_style_rule['rules'] as $css_property => $css_value ) {
// Skip rules that reference content size or wide size if they are not defined in the theme.json.
if (
is_string( $css_value ) &&
( str_contains( $css_value, '--global--content-size' ) || str_contains( $css_value, '--global--wide-size' ) ) &&
! isset( $this->theme_json['settings']['layout']['contentSize'] ) &&
! isset( $this->theme_json['settings']['layout']['wideSize'] )
) {
continue;
}

if ( static::is_safe_css_declaration( $css_property, $css_value ) ) {
$declarations[] = array(
'name' => $css_property,
Expand Down

0 comments on commit 59a4104

Please sign in to comment.