summaryrefslogtreecommitdiffstats
path: root/wp-includes/class-wp-theme-json.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-includes/class-wp-theme-json.php')
-rw-r--r--wp-includes/class-wp-theme-json.php22
1 files changed, 20 insertions, 2 deletions
diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php
index d754da9..6500b44 100644
--- a/wp-includes/class-wp-theme-json.php
+++ b/wp-includes/class-wp-theme-json.php
@@ -1227,7 +1227,7 @@ class WP_Theme_JSON {
);
foreach ( $base_styles_nodes as $base_style_node ) {
- $stylesheet .= $this->get_layout_styles( $base_style_node );
+ $stylesheet .= $this->get_layout_styles( $base_style_node, $types );
}
}
@@ -1388,11 +1388,14 @@ 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.
+ * @since 6.5.3 Add types parameter to check if only base layout styles are needed.
*
* @param array $block_metadata Metadata about the block to get styles for.
+ * @param array $types Optional. Types of styles to output. If empty, all styles will be output.
* @return string Layout styles for the block.
*/
- protected function get_layout_styles( $block_metadata ) {
+ protected function get_layout_styles( $block_metadata, $types = array() ) {
$block_rules = '';
$block_type = null;
@@ -1542,12 +1545,27 @@ class WP_Theme_JSON {
foreach ( $base_style_rules as $base_style_rule ) {
$declarations = array();
+ // Skip outputting base styles for flow and constrained layout types if theme doesn't support theme.json. The 'base-layout-styles' type flags this.
+ if ( in_array( 'base-layout-styles', $types, true ) && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) {
+ continue;
+ }
+
if (
isset( $base_style_rule['selector'] ) &&
preg_match( $layout_selector_pattern, $base_style_rule['selector'] ) &&
! 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,