Make WordPress Core


Ignore:
Timestamp:
06/05/2024 08:11:03 AM (11 months ago)
Author:
oandregal
Message:

Editor: improve code quality of theme.json classes.

Follow-up to [58328], #61282.

Props ajlende, ramonopoly.
Fixes #61370.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r58328 r58339  
    288288        $theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
    289289        if ( ! wp_theme_has_theme_json() ) {
    290             if ( ! isset( $theme_support_data['settings']['color'] ) ) {
    291                 $theme_support_data['settings']['color'] = array();
    292             }
    293 
    294             $default_palette = false;
    295             if ( current_theme_supports( 'default-color-palette' ) ) {
    296                 $default_palette = true;
    297             }
    298             if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) {
    299                 // If the theme does not have any palette, we still want to show the core one.
    300                 $default_palette = true;
    301             }
    302             $theme_support_data['settings']['color']['defaultPalette'] = $default_palette;
    303 
    304             $default_gradients = false;
    305             if ( current_theme_supports( 'default-gradient-presets' ) ) {
    306                 $default_gradients = true;
    307             }
    308             if ( ! isset( $theme_support_data['settings']['color']['gradients'] ) ) {
    309                 // If the theme does not have any gradients, we still want to show the core ones.
    310                 $default_gradients = true;
    311             }
    312             $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;
    313 
    314             if ( ! isset( $theme_support_data['settings']['typography'] ) ) {
    315                 $theme_support_data['settings']['typography'] = array();
    316             }
    317             $default_font_sizes = false;
    318             if ( current_theme_supports( 'default-font-sizes' ) ) {
    319                 $default_font_sizes = true;
    320             }
    321             if ( ! isset( $theme_support_data['settings']['typography']['fontSizes'] ) ) {
    322                 // If the theme does not have any font sizes, we still want to show the core one.
    323                 $default_font_sizes = true;
    324             }
    325             $theme_support_data['settings']['typography']['defaultFontSizes'] = $default_font_sizes;
    326 
    327             if ( ! isset( $theme_support_data['settings']['spacing'] ) ) {
    328                 $theme_support_data['settings']['spacing'] = array();
    329             }
    330             $default_spacing_sizes = false;
    331             if ( current_theme_supports( 'default-spacing-sizes' ) ) {
    332                 $default_spacing_sizes = true;
    333             }
    334             if ( ! isset( $theme_support_data['settings']['spacing']['spacingSizes'] ) ) {
    335                 // If the theme does not have any spacing sizes, we still want to show the core one.
    336                 $default_spacing_sizes = true;
    337             }
    338             $theme_support_data['settings']['spacing']['defaultSpacingSizes'] = $default_spacing_sizes;
    339 
    340             if ( ! isset( $theme_support_data['settings']['shadow'] ) ) {
    341                 $theme_support_data['settings']['shadow'] = array();
    342             }
     290            /*
     291             * Unlike block themes, classic themes without a theme.json disable
     292             * default presets when custom preset theme support is added. This
     293             * behavior can be overridden by using the corresponding default
     294             * preset theme support.
     295             */
     296            $theme_support_data['settings']['color']['defaultPalette']        =
     297                ! isset( $theme_support_data['settings']['color']['palette'] ) ||
     298                current_theme_supports( 'default-color-palette' );
     299            $theme_support_data['settings']['color']['defaultGradients']      =
     300                ! isset( $theme_support_data['settings']['color']['gradients'] ) ||
     301                current_theme_supports( 'default-gradient-presets' );
     302            $theme_support_data['settings']['typography']['defaultFontSizes'] =
     303                ! isset( $theme_support_data['settings']['typography']['fontSizes'] ) ||
     304                current_theme_supports( 'default-font-sizes' );
     305            $theme_support_data['settings']['spacing']['defaultSpacingSizes'] =
     306                ! isset( $theme_support_data['settings']['spacing']['spacingSizes'] ) ||
     307                current_theme_supports( 'default-spacing-sizes' );
     308
    343309            /*
    344310             * Shadow presets are explicitly disabled for classic themes until a
Note: See TracChangeset for help on using the changeset viewer.