Skip to content

Commit c1ea2a2

Browse files
committed
Disable layout styles in classic themes
1 parent cc47781 commit c1ea2a2

File tree

2 files changed

+11
-46
lines changed

2 files changed

+11
-46
lines changed

src/wp-includes/class-wp-theme-json.php

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,6 @@ public function get_settings() {
13331333
* - `variables`: only the CSS Custom Properties for presets & custom ones.
13341334
* - `styles`: only the styles section in theme.json.
13351335
* - `presets`: only the classes for the presets.
1336-
* - `base-layout-styles`: only the base layout styles.
13371336
* - `custom-css`: only the custom CSS.
13381337
* @param string[] $origins A list of origins to include. By default it includes VALID_ORIGINS.
13391338
* @param array $options {
@@ -1400,42 +1399,6 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
14001399
$stylesheet .= $this->get_root_layout_rules( $style_nodes[ $root_style_key ]['selector'], $style_nodes[ $root_style_key ] );
14011400
}
14021401
$stylesheet .= $this->get_block_classes( $style_nodes );
1403-
} elseif ( in_array( 'base-layout-styles', $types, true ) ) {
1404-
$root_selector = static::ROOT_BLOCK_SELECTOR;
1405-
$columns_selector = '.wp-block-columns';
1406-
$post_template_selector = '.wp-block-post-template';
1407-
if ( ! empty( $options['scope'] ) ) {
1408-
$root_selector = static::scope_selector( $options['scope'], $root_selector );
1409-
$columns_selector = static::scope_selector( $options['scope'], $columns_selector );
1410-
$post_template_selector = static::scope_selector( $options['scope'], $post_template_selector );
1411-
}
1412-
if ( ! empty( $options['root_selector'] ) ) {
1413-
$root_selector = $options['root_selector'];
1414-
}
1415-
/*
1416-
* Base layout styles are provided as part of `styles`, so only output separately if explicitly requested.
1417-
* For backwards compatibility, the Columns block is explicitly included, to support a different default gap value.
1418-
*/
1419-
$base_styles_nodes = array(
1420-
array(
1421-
'path' => array( 'styles' ),
1422-
'selector' => $root_selector,
1423-
),
1424-
array(
1425-
'path' => array( 'styles', 'blocks', 'core/columns' ),
1426-
'selector' => $columns_selector,
1427-
'name' => 'core/columns',
1428-
),
1429-
array(
1430-
'path' => array( 'styles', 'blocks', 'core/post-template' ),
1431-
'selector' => $post_template_selector,
1432-
'name' => 'core/post-template',
1433-
),
1434-
);
1435-
1436-
foreach ( $base_styles_nodes as $base_style_node ) {
1437-
$stylesheet .= $this->get_layout_styles( $base_style_node, $types );
1438-
}
14391402
}
14401403

14411404
if ( in_array( 'presets', $types, true ) ) {
@@ -1783,8 +1746,9 @@ protected function get_layout_styles( $block_metadata, $types = array() ) {
17831746
foreach ( $base_style_rules as $base_style_rule ) {
17841747
$declarations = array();
17851748

1786-
// Skip outputting base styles for flow and constrained layout types if theme doesn't support theme.json. The 'base-layout-styles' type flags this.
1787-
if ( in_array( 'base-layout-styles', $types, true ) && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) {
1749+
// Skip outputting base styles for flow and constrained layout types for classic themes without theme.json.
1750+
// These themes don't use .wp-site-blocks wrapper, so these layout-specific alignment styles aren't needed.
1751+
if ( ! wp_is_block_theme() && ! wp_theme_has_theme_json() && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) {
17881752
continue;
17891753
}
17901754

@@ -3107,9 +3071,13 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
31073071
$css .= '.has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull)) > .alignfull { margin-left: 0; margin-right: 0; }';
31083072
}
31093073

3110-
$css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
3111-
$css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
3112-
$css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
3074+
// Skip outputting alignment styles for classic themes without theme.json.
3075+
// These styles target .wp-site-blocks which is only used by block themes.
3076+
if ( wp_is_block_theme() || wp_theme_has_theme_json() ) {
3077+
$css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
3078+
$css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
3079+
$css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
3080+
}
31133081

31143082
// Block gap styles will be output unless explicitly set to `null`. See static::PROTECTED_PROPERTIES.
31153083
if ( isset( $this->theme_json['settings']['spacing']['blockGap'] ) ) {

src/wp-includes/global-styles-and-settings.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,11 @@ function wp_get_global_styles( $path = array(), $context = array() ) {
135135
* Returns the stylesheet resulting of merging core, theme, and user data.
136136
*
137137
* @since 5.9.0
138-
* @since 6.1.0 Added 'base-layout-styles' support.
139138
* @since 6.6.0 Resolves relative paths in theme.json styles to theme absolute paths.
140139
*
141140
* @param array $types Optional. Types of styles to load.
142141
* See {@see 'WP_Theme_JSON::get_stylesheet'} for all valid types.
143-
* If empty, it'll load the following:
144-
* - for themes without theme.json: 'variables', 'presets', 'base-layout-styles'.
145-
* - for themes with theme.json: 'variables', 'presets', 'styles'.
142+
* If empty, will load: 'variables', 'presets', 'styles'.
146143
* @return string Stylesheet.
147144
*/
148145
function wp_get_global_stylesheet( $types = array() ) {

0 commit comments

Comments
 (0)