From e8e20a282371286e958cca39ced6c9b8a76641fc Mon Sep 17 00:00:00 2001 From: jorgefilipecosta Date: Fri, 4 Feb 2022 13:52:00 +0000 Subject: [PATCH] Fix: Classic themes using default presets are not working. This commit makes the presets provided by the theme via add_theme_support always create CSS Custom Properties, whether or not the theme has a theme.json file. This way, if the overwrites a core preset, the core CSS variables are also overwritten and use the theme value. Props oandregal, hellofromTonya, desrosj, costdev, pbearne, johnstonphilip, webmandesign. Fixes #54782. Built from https://develop.svn.wordpress.org/trunk@52675 git-svn-id: http://core.svn.wordpress.org/trunk@52264 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/global-styles-and-settings.php | 36 +++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/wp-includes/global-styles-and-settings.php b/wp-includes/global-styles-and-settings.php index 9db95a3e95..f8cd905fdc 100644 --- a/wp-includes/global-styles-and-settings.php +++ b/wp-includes/global-styles-and-settings.php @@ -103,26 +103,40 @@ function wp_get_global_stylesheet( $types = array() ) { } } + $tree = WP_Theme_JSON_Resolver::get_merged_data(); + $supports_theme_json = WP_Theme_JSON_Resolver::theme_has_support(); - $supports_link_color = get_theme_support( 'experimental-link-color' ); if ( empty( $types ) && ! $supports_theme_json ) { $types = array( 'variables', 'presets' ); } elseif ( empty( $types ) ) { $types = array( 'variables', 'styles', 'presets' ); } - $origins = array( 'default', 'theme', 'custom' ); - if ( ! $supports_theme_json && ! $supports_link_color ) { - // In this case we only enqueue the core presets (CSS Custom Properties + the classes). - $origins = array( 'default' ); - } elseif ( ! $supports_theme_json && $supports_link_color ) { - // For the legacy link color feature to work, the CSS Custom Properties - // should be in scope (either the core or the theme ones). - $origins = array( 'default', 'theme' ); + // If variables are part of the stylesheet, + // we add them for all origins (default, theme, user). + // This is so themes without a theme.json still work as before 5.9: + // they can override the default presets. + // See https://core.trac.wordpress.org/ticket/54782 + $styles_variables = ''; + if ( in_array( 'variables', $types ) ) { + $styles_variables = $tree->get_stylesheet( array( 'variables' ) ); + $types = array_diff( $types, array( 'variables' ) ); } - $tree = WP_Theme_JSON_Resolver::get_merged_data(); - $stylesheet = $tree->get_stylesheet( $types, $origins ); + // For the remaining types (presets, styles), we do consider origins: + // + // - themes without theme.json: only the classes for the presets defined by core + // - themes with theme.json: the presets and styles classes, both from core and the theme + $styles_rest = ''; + if ( ! empty( $types ) ) { + $origins = array( 'default', 'theme', 'custom' ); + if ( ! $supports_theme_json ) { + $origins = array( 'default' ); + } + $styles_rest = $tree->get_stylesheet( $types, $origins ); + } + + $stylesheet = $styles_variables . $styles_rest; if ( $can_use_cached ) { // Cache for a minute. diff --git a/wp-includes/version.php b/wp-includes/version.php index 2988859aa5..9112c7ddb8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52674'; +$wp_version = '6.0-alpha-52675'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.