Make WordPress Core

Changeset 58339


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

Editor: improve code quality of theme.json classes.

Follow-up to [58328], #61282.

Props ajlende, ramonopoly.
Fixes #61370.

Location:
trunk/src/wp-includes
Files:
3 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
  • trunk/src/wp-includes/class-wp-theme-json-schema.php

    r58328 r58339  
    5353                        case 1:
    5454                                $theme_json = self::migrate_v1_to_v2( $theme_json );
    55                                 // no break
     55                                // Deliberate fall through. Once migrated to v2, also migrate to v3.
    5656                        case 2:
    5757                                $theme_json = self::migrate_v2_to_v3( $theme_json );
    58                                 // no break
    5958                }
    6059
    … …  
    9594         * Migrates from v2 to v3.
    9695         *
    97          * - Sets settings.typography.defaultFontSizes to false.
     96         * - Sets settings.typography.defaultFontSizes to false if settings.typography.fontSizes are defined.
     97         * - Sets settings.spacing.defaultSpacingSizes to false if settings.spacing.spacingSizes are defined.
     98         * - Prevents settings.spacing.spacingSizes from merging with settings.spacing.spacingScale by
     99         *   unsetting spacingScale when spacingSizes are defined.
    98100         *
    99101         * @since 6.6.0
    … …  
    130132                 */
    131133                if ( isset( $old['settings']['typography']['fontSizes'] ) ) {
    132                         if ( ! isset( $new['settings'] ) ) {
    133                                 $new['settings'] = array();
    134                         }
    135                         if ( ! isset( $new['settings']['typography'] ) ) {
    136                                 $new['settings']['typography'] = array();
    137                         }
    138134                        $new['settings']['typography']['defaultFontSizes'] = false;
    139135                }
    … …  
    149145                        isset( $old['settings']['spacing']['spacingScale'] )
    150146                ) {
    151                         if ( ! isset( $new['settings'] ) ) {
    152                                 $new['settings'] = array();
    153                         }
    154                         if ( ! isset( $new['settings']['spacing'] ) ) {
    155                                 $new['settings']['spacing'] = array();
    156                         }
    157147                        $new['settings']['spacing']['defaultSpacingSizes'] = false;
    158148                }
  • trunk/src/wp-includes/class-wp-theme-json.php

    r58328 r58339  
    35253525                // Deprecated theme supports.
    35263526                if ( isset( $settings['disableCustomColors'] ) ) {
    3527                         if ( ! isset( $theme_settings['settings']['color'] ) ) {
    3528                                 $theme_settings['settings']['color'] = array();
    3529                         }
    35303527                        $theme_settings['settings']['color']['custom'] = ! $settings['disableCustomColors'];
    35313528                }
    35323529
    35333530                if ( isset( $settings['disableCustomGradients'] ) ) {
    3534                         if ( ! isset( $theme_settings['settings']['color'] ) ) {
    3535                                 $theme_settings['settings']['color'] = array();
    3536                         }
    35373531                        $theme_settings['settings']['color']['customGradient'] = ! $settings['disableCustomGradients'];
    35383532                }
    35393533
    35403534                if ( isset( $settings['disableCustomFontSizes'] ) ) {
    3541                         if ( ! isset( $theme_settings['settings']['typography'] ) ) {
    3542                                 $theme_settings['settings']['typography'] = array();
    3543                         }
    35443535                        $theme_settings['settings']['typography']['customFontSize'] = ! $settings['disableCustomFontSizes'];
    35453536                }
    35463537
    35473538                if ( isset( $settings['enableCustomLineHeight'] ) ) {
    3548                         if ( ! isset( $theme_settings['settings']['typography'] ) ) {
    3549                                 $theme_settings['settings']['typography'] = array();
    3550                         }
    35513539                        $theme_settings['settings']['typography']['lineHeight'] = $settings['enableCustomLineHeight'];
    35523540                }
    35533541
    35543542                if ( isset( $settings['enableCustomUnits'] ) ) {
    3555                         if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
    3556                                 $theme_settings['settings']['spacing'] = array();
    3557                         }
    35583543                        $theme_settings['settings']['spacing']['units'] = ( true === $settings['enableCustomUnits'] ) ?
    35593544                                array( 'px', 'em', 'rem', 'vh', 'vw', '%' ) :
    … …  
    35623547
    35633548                if ( isset( $settings['colors'] ) ) {
    3564                         if ( ! isset( $theme_settings['settings']['color'] ) ) {
    3565                                 $theme_settings['settings']['color'] = array();
    3566                         }
    35673549                        $theme_settings['settings']['color']['palette'] = $settings['colors'];
    35683550                }
    35693551
    35703552                if ( isset( $settings['gradients'] ) ) {
    3571                         if ( ! isset( $theme_settings['settings']['color'] ) ) {
    3572                                 $theme_settings['settings']['color'] = array();
    3573                         }
    35743553                        $theme_settings['settings']['color']['gradients'] = $settings['gradients'];
    35753554                }
    … …  
    35833562                                }
    35843563                        }
    3585                         if ( ! isset( $theme_settings['settings']['typography'] ) ) {
    3586                                 $theme_settings['settings']['typography'] = array();
    3587                         }
    35883564                        $theme_settings['settings']['typography']['fontSizes'] = $font_sizes;
    35893565                }
    35903566
    35913567                if ( isset( $settings['enableCustomSpacing'] ) ) {
    3592                         if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
    3593                                 $theme_settings['settings']['spacing'] = array();
    3594                         }
    35953568                        $theme_settings['settings']['spacing']['padding'] = $settings['enableCustomSpacing'];
    35963569                }
    35973570
    35983571                if ( isset( $settings['spacingSizes'] ) ) {
    3599                         if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
    3600                                 $theme_settings['settings']['spacing'] = array();
    3601                         }
    36023572                        $theme_settings['settings']['spacing']['spacingSizes'] = $settings['spacingSizes'];
    36033573                }
    … …  
    37763746         *
    37773747         * @since 6.1.0
    3778          * @deprecated 6.6.0
    3779          *
    3780          * @param string $origin Optional. What source of data to set the spacing sizes for.
    3781          *                       One of 'default', 'theme', or 'custom'. Default 'default'.
     3748         * @deprecated 6.6.0 No longer used as the spacingSizes are automatically
     3749         *                   generated in the constructor and merge methods instead
     3750         *                   of manually after instantiation.
    37823751         *
    37833752         * @return null|void
Note: See TracChangeset for help on using the changeset viewer.