Editor: improve code quality of theme.json classes.
Follow-up to [58328], #61282. Props ajlende, ramonopoly. Fixes #61370. Built from https://develop.svn.wordpress.org/trunk@58339 git-svn-id: http://core.svn.wordpress.org/trunk@57795 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9200aad73c
commit
2b50b6ab1d
|
@ -287,59 +287,25 @@ class WP_Theme_JSON_Resolver {
|
|||
*/
|
||||
$theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
|
||||
if ( ! wp_theme_has_theme_json() ) {
|
||||
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
|
||||
$theme_support_data['settings']['color'] = array();
|
||||
}
|
||||
/*
|
||||
* Unlike block themes, classic themes without a theme.json disable
|
||||
* default presets when custom preset theme support is added. This
|
||||
* behavior can be overridden by using the corresponding default
|
||||
* preset theme support.
|
||||
*/
|
||||
$theme_support_data['settings']['color']['defaultPalette'] =
|
||||
! isset( $theme_support_data['settings']['color']['palette'] ) ||
|
||||
current_theme_supports( 'default-color-palette' );
|
||||
$theme_support_data['settings']['color']['defaultGradients'] =
|
||||
! isset( $theme_support_data['settings']['color']['gradients'] ) ||
|
||||
current_theme_supports( 'default-gradient-presets' );
|
||||
$theme_support_data['settings']['typography']['defaultFontSizes'] =
|
||||
! isset( $theme_support_data['settings']['typography']['fontSizes'] ) ||
|
||||
current_theme_supports( 'default-font-sizes' );
|
||||
$theme_support_data['settings']['spacing']['defaultSpacingSizes'] =
|
||||
! isset( $theme_support_data['settings']['spacing']['spacingSizes'] ) ||
|
||||
current_theme_supports( 'default-spacing-sizes' );
|
||||
|
||||
$default_palette = false;
|
||||
if ( current_theme_supports( 'default-color-palette' ) ) {
|
||||
$default_palette = true;
|
||||
}
|
||||
if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) {
|
||||
// If the theme does not have any palette, we still want to show the core one.
|
||||
$default_palette = true;
|
||||
}
|
||||
$theme_support_data['settings']['color']['defaultPalette'] = $default_palette;
|
||||
|
||||
$default_gradients = false;
|
||||
if ( current_theme_supports( 'default-gradient-presets' ) ) {
|
||||
$default_gradients = true;
|
||||
}
|
||||
if ( ! isset( $theme_support_data['settings']['color']['gradients'] ) ) {
|
||||
// If the theme does not have any gradients, we still want to show the core ones.
|
||||
$default_gradients = true;
|
||||
}
|
||||
$theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;
|
||||
|
||||
if ( ! isset( $theme_support_data['settings']['typography'] ) ) {
|
||||
$theme_support_data['settings']['typography'] = array();
|
||||
}
|
||||
$default_font_sizes = false;
|
||||
if ( current_theme_supports( 'default-font-sizes' ) ) {
|
||||
$default_font_sizes = true;
|
||||
}
|
||||
if ( ! isset( $theme_support_data['settings']['typography']['fontSizes'] ) ) {
|
||||
// If the theme does not have any font sizes, we still want to show the core one.
|
||||
$default_font_sizes = true;
|
||||
}
|
||||
$theme_support_data['settings']['typography']['defaultFontSizes'] = $default_font_sizes;
|
||||
|
||||
if ( ! isset( $theme_support_data['settings']['spacing'] ) ) {
|
||||
$theme_support_data['settings']['spacing'] = array();
|
||||
}
|
||||
$default_spacing_sizes = false;
|
||||
if ( current_theme_supports( 'default-spacing-sizes' ) ) {
|
||||
$default_spacing_sizes = true;
|
||||
}
|
||||
if ( ! isset( $theme_support_data['settings']['spacing']['spacingSizes'] ) ) {
|
||||
// If the theme does not have any spacing sizes, we still want to show the core one.
|
||||
$default_spacing_sizes = true;
|
||||
}
|
||||
$theme_support_data['settings']['spacing']['defaultSpacingSizes'] = $default_spacing_sizes;
|
||||
|
||||
if ( ! isset( $theme_support_data['settings']['shadow'] ) ) {
|
||||
$theme_support_data['settings']['shadow'] = array();
|
||||
}
|
||||
/*
|
||||
* Shadow presets are explicitly disabled for classic themes until a
|
||||
* decision is made for whether the default presets should match the
|
||||
|
|
|
@ -52,10 +52,9 @@ class WP_Theme_JSON_Schema {
|
|||
switch ( $theme_json['version'] ) {
|
||||
case 1:
|
||||
$theme_json = self::migrate_v1_to_v2( $theme_json );
|
||||
// no break
|
||||
// Deliberate fall through. Once migrated to v2, also migrate to v3.
|
||||
case 2:
|
||||
$theme_json = self::migrate_v2_to_v3( $theme_json );
|
||||
// no break
|
||||
}
|
||||
|
||||
return $theme_json;
|
||||
|
@ -94,7 +93,10 @@ class WP_Theme_JSON_Schema {
|
|||
/**
|
||||
* Migrates from v2 to v3.
|
||||
*
|
||||
* - Sets settings.typography.defaultFontSizes to false.
|
||||
* - Sets settings.typography.defaultFontSizes to false if settings.typography.fontSizes are defined.
|
||||
* - Sets settings.spacing.defaultSpacingSizes to false if settings.spacing.spacingSizes are defined.
|
||||
* - Prevents settings.spacing.spacingSizes from merging with settings.spacing.spacingScale by
|
||||
* unsetting spacingScale when spacingSizes are defined.
|
||||
*
|
||||
* @since 6.6.0
|
||||
*
|
||||
|
@ -129,12 +131,6 @@ class WP_Theme_JSON_Schema {
|
|||
* affect the generated CSS.
|
||||
*/
|
||||
if ( isset( $old['settings']['typography']['fontSizes'] ) ) {
|
||||
if ( ! isset( $new['settings'] ) ) {
|
||||
$new['settings'] = array();
|
||||
}
|
||||
if ( ! isset( $new['settings']['typography'] ) ) {
|
||||
$new['settings']['typography'] = array();
|
||||
}
|
||||
$new['settings']['typography']['defaultFontSizes'] = false;
|
||||
}
|
||||
|
||||
|
@ -148,12 +144,6 @@ class WP_Theme_JSON_Schema {
|
|||
isset( $old['settings']['spacing']['spacingSizes'] ) ||
|
||||
isset( $old['settings']['spacing']['spacingScale'] )
|
||||
) {
|
||||
if ( ! isset( $new['settings'] ) ) {
|
||||
$new['settings'] = array();
|
||||
}
|
||||
if ( ! isset( $new['settings']['spacing'] ) ) {
|
||||
$new['settings']['spacing'] = array();
|
||||
}
|
||||
$new['settings']['spacing']['defaultSpacingSizes'] = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3524,53 +3524,32 @@ class WP_Theme_JSON {
|
|||
|
||||
// Deprecated theme supports.
|
||||
if ( isset( $settings['disableCustomColors'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['color'] ) ) {
|
||||
$theme_settings['settings']['color'] = array();
|
||||
}
|
||||
$theme_settings['settings']['color']['custom'] = ! $settings['disableCustomColors'];
|
||||
}
|
||||
|
||||
if ( isset( $settings['disableCustomGradients'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['color'] ) ) {
|
||||
$theme_settings['settings']['color'] = array();
|
||||
}
|
||||
$theme_settings['settings']['color']['customGradient'] = ! $settings['disableCustomGradients'];
|
||||
}
|
||||
|
||||
if ( isset( $settings['disableCustomFontSizes'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['typography'] ) ) {
|
||||
$theme_settings['settings']['typography'] = array();
|
||||
}
|
||||
$theme_settings['settings']['typography']['customFontSize'] = ! $settings['disableCustomFontSizes'];
|
||||
}
|
||||
|
||||
if ( isset( $settings['enableCustomLineHeight'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['typography'] ) ) {
|
||||
$theme_settings['settings']['typography'] = array();
|
||||
}
|
||||
$theme_settings['settings']['typography']['lineHeight'] = $settings['enableCustomLineHeight'];
|
||||
}
|
||||
|
||||
if ( isset( $settings['enableCustomUnits'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
|
||||
$theme_settings['settings']['spacing'] = array();
|
||||
}
|
||||
$theme_settings['settings']['spacing']['units'] = ( true === $settings['enableCustomUnits'] ) ?
|
||||
array( 'px', 'em', 'rem', 'vh', 'vw', '%' ) :
|
||||
$settings['enableCustomUnits'];
|
||||
}
|
||||
|
||||
if ( isset( $settings['colors'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['color'] ) ) {
|
||||
$theme_settings['settings']['color'] = array();
|
||||
}
|
||||
$theme_settings['settings']['color']['palette'] = $settings['colors'];
|
||||
}
|
||||
|
||||
if ( isset( $settings['gradients'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['color'] ) ) {
|
||||
$theme_settings['settings']['color'] = array();
|
||||
}
|
||||
$theme_settings['settings']['color']['gradients'] = $settings['gradients'];
|
||||
}
|
||||
|
||||
|
@ -3582,23 +3561,14 @@ class WP_Theme_JSON {
|
|||
$font_sizes[ $key ]['size'] = $font_size['size'] . 'px';
|
||||
}
|
||||
}
|
||||
if ( ! isset( $theme_settings['settings']['typography'] ) ) {
|
||||
$theme_settings['settings']['typography'] = array();
|
||||
}
|
||||
$theme_settings['settings']['typography']['fontSizes'] = $font_sizes;
|
||||
}
|
||||
|
||||
if ( isset( $settings['enableCustomSpacing'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
|
||||
$theme_settings['settings']['spacing'] = array();
|
||||
}
|
||||
$theme_settings['settings']['spacing']['padding'] = $settings['enableCustomSpacing'];
|
||||
}
|
||||
|
||||
if ( isset( $settings['spacingSizes'] ) ) {
|
||||
if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
|
||||
$theme_settings['settings']['spacing'] = array();
|
||||
}
|
||||
$theme_settings['settings']['spacing']['spacingSizes'] = $settings['spacingSizes'];
|
||||
}
|
||||
|
||||
|
@ -3775,10 +3745,9 @@ class WP_Theme_JSON {
|
|||
* Sets the spacingSizes array based on the spacingScale values from theme.json.
|
||||
*
|
||||
* @since 6.1.0
|
||||
* @deprecated 6.6.0
|
||||
*
|
||||
* @param string $origin Optional. What source of data to set the spacing sizes for.
|
||||
* One of 'default', 'theme', or 'custom'. Default 'default'.
|
||||
* @deprecated 6.6.0 No longer used as the spacingSizes are automatically
|
||||
* generated in the constructor and merge methods instead
|
||||
* of manually after instantiation.
|
||||
*
|
||||
* @return null|void
|
||||
*/
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.6-beta1-58338';
|
||||
$wp_version = '6.6-beta1-58339';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue