Make WordPress Core

Changeset 52675


Ignore:
Timestamp:
02/04/2022 01:50:34 PM (3 years ago)
Author:
jorgefilipecosta
Message:

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.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/global-styles-and-settings.php

    r52275 r52675  
    104104    }
    105105
     106    $tree = WP_Theme_JSON_Resolver::get_merged_data();
     107
    106108    $supports_theme_json = WP_Theme_JSON_Resolver::theme_has_support();
    107     $supports_link_color = get_theme_support( 'experimental-link-color' );
    108109    if ( empty( $types ) && ! $supports_theme_json ) {
    109110        $types = array( 'variables', 'presets' );
     
    112113    }
    113114
    114     $origins = array( 'default', 'theme', 'custom' );
    115     if ( ! $supports_theme_json && ! $supports_link_color ) {
    116         // In this case we only enqueue the core presets (CSS Custom Properties + the classes).
    117         $origins = array( 'default' );
    118     } elseif ( ! $supports_theme_json && $supports_link_color ) {
    119         // For the legacy link color feature to work, the CSS Custom Properties
    120         // should be in scope (either the core or the theme ones).
    121         $origins = array( 'default', 'theme' );
     115    // If variables are part of the stylesheet,
     116    // we add them for all origins (default, theme, user).
     117    // This is so themes without a theme.json still work as before 5.9:
     118    // they can override the default presets.
     119    // See https://core.trac.wordpress.org/ticket/54782
     120    $styles_variables = '';
     121    if ( in_array( 'variables', $types ) ) {
     122        $styles_variables = $tree->get_stylesheet( array( 'variables' ) );
     123        $types            = array_diff( $types, array( 'variables' ) );
    122124    }
    123125
    124     $tree       = WP_Theme_JSON_Resolver::get_merged_data();
    125     $stylesheet = $tree->get_stylesheet( $types, $origins );
     126    // For the remaining types (presets, styles), we do consider origins:
     127    //
     128    // - themes without theme.json: only the classes for the presets defined by core
     129    // - themes with theme.json: the presets and styles classes, both from core and the theme
     130    $styles_rest = '';
     131    if ( ! empty( $types ) ) {
     132        $origins = array( 'default', 'theme', 'custom' );
     133        if ( ! $supports_theme_json ) {
     134            $origins = array( 'default' );
     135        }
     136        $styles_rest = $tree->get_stylesheet( $types, $origins );
     137    }
     138
     139    $stylesheet = $styles_variables . $styles_rest;
    126140
    127141    if ( $can_use_cached ) {
Note: See TracChangeset for help on using the changeset viewer.