Make WordPress Core

Changeset 52678 for branches/5.9


Ignore:
Timestamp:
02/04/2022 02:46:27 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Themes: Fix for Classic themes using default presets.

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 theme overwrites a core preset, the core CSS variables are also overwritten and use the theme value.

Props oandregal, hellofromTonya, desrosj, costdev, pbearne, johnstonphilip, webmandesign, jorgefilipecosta, SergeyBiryukov.
Merges [52675-52677] to the 5.9 branch.
Fixes #54782.

Location:
branches/5.9
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/5.9

  • branches/5.9/src/wp-includes/global-styles-and-settings.php

    r52275 r52678  
    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    /*
     116     * If variables are part of the stylesheet,
     117     * we add them for all origins (default, theme, user).
     118     * This is so themes without a theme.json still work as before 5.9:
     119     * they can override the default presets.
     120     * See https://core.trac.wordpress.org/ticket/54782
     121     */
     122    $styles_variables = '';
     123    if ( in_array( 'variables', $types, true ) ) {
     124        $styles_variables = $tree->get_stylesheet( array( 'variables' ) );
     125        $types            = array_diff( $types, array( 'variables' ) );
    122126    }
    123127
    124     $tree       = WP_Theme_JSON_Resolver::get_merged_data();
    125     $stylesheet = $tree->get_stylesheet( $types, $origins );
     128    /*
     129     * For the remaining types (presets, styles), we do consider origins:
     130     *
     131     * - themes without theme.json: only the classes for the presets defined by core
     132     * - themes with theme.json: the presets and styles classes, both from core and the theme
     133     */
     134    $styles_rest = '';
     135    if ( ! empty( $types ) ) {
     136        $origins = array( 'default', 'theme', 'custom' );
     137        if ( ! $supports_theme_json ) {
     138            $origins = array( 'default' );
     139        }
     140        $styles_rest = $tree->get_stylesheet( $types, $origins );
     141    }
     142
     143    $stylesheet = $styles_variables . $styles_rest;
    126144
    127145    if ( $can_use_cached ) {
Note: See TracChangeset for help on using the changeset viewer.