Skip to content

Commit

Permalink
Editor: skip outputting base layout rules if content and wide size va…
Browse files Browse the repository at this point in the history
…lues don’t exist.

Skip outputting layout rules that reference content and wide sizes CSS variables, if no layout sizes exist in the current `theme.json`.

Props andrewserong.
Fixes #60936.

Built from https://develop.svn.wordpress.org/trunk@57948


git-svn-id: https://core.svn.wordpress.org/trunk@57445 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
tellthemachines committed Apr 9, 2024
1 parent 3c623a7 commit 79704cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ protected function get_block_classes( $style_nodes ) {
*
* @since 6.1.0
* @since 6.3.0 Reduced specificity for layout margin rules.
* @since 6.5.1 Only output rules referencing content and wide sizes when values exist.
*
* @param array $block_metadata Metadata about the block to get styles for.
* @return string Layout styles for the block.
Expand Down Expand Up @@ -1548,6 +1549,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
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-57946';
$wp_version = '6.6-alpha-57948';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 79704cc

Please sign in to comment.