Editor: skip outputting base layout rules if content and wide size values 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: http://core.svn.wordpress.org/trunk@57445 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
isabel_brison 2024-04-09 07:20:15 +00:00
parent f3873d2f8a
commit 8fbd2fc6f4
2 changed files with 12 additions and 1 deletions

View File

@ -1388,6 +1388,7 @@ class WP_Theme_JSON {
*
* @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.
@ -1548,6 +1549,16 @@ class WP_Theme_JSON {
! 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,

View File

@ -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.