From 546e93297709669a3897cd77d13af0201f9d2461 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 4 Jun 2024 13:54:56 -0500 Subject: [PATCH 1/6] Update no break comments --- src/wp-includes/class-wp-theme-json-schema.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json-schema.php b/src/wp-includes/class-wp-theme-json-schema.php index aa654f25979eb..7f68dcb9ae7ce 100644 --- a/src/wp-includes/class-wp-theme-json-schema.php +++ b/src/wp-includes/class-wp-theme-json-schema.php @@ -52,10 +52,9 @@ public static function migrate( $theme_json ) { 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; From 8598d10c98d67d097f9a205c9e604433397d1292 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 4 Jun 2024 13:58:00 -0500 Subject: [PATCH 2/6] Update docs for migrate_v2_to_v3 --- src/wp-includes/class-wp-theme-json-schema.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json-schema.php b/src/wp-includes/class-wp-theme-json-schema.php index 7f68dcb9ae7ce..3c824a7c0efff 100644 --- a/src/wp-includes/class-wp-theme-json-schema.php +++ b/src/wp-includes/class-wp-theme-json-schema.php @@ -93,7 +93,10 @@ private static function migrate_v1_to_v2( $old ) { /** * 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 * From 2518e5b161b814202ee6fcbfe3757641efaa38b9 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 4 Jun 2024 13:58:09 -0500 Subject: [PATCH 3/6] Remove unnecessary isset checks --- src/wp-includes/class-wp-theme-json-schema.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json-schema.php b/src/wp-includes/class-wp-theme-json-schema.php index 3c824a7c0efff..366594ef3705d 100644 --- a/src/wp-includes/class-wp-theme-json-schema.php +++ b/src/wp-includes/class-wp-theme-json-schema.php @@ -131,12 +131,6 @@ private static function migrate_v2_to_v3( $old ) { * 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; } @@ -150,12 +144,6 @@ private static function migrate_v2_to_v3( $old ) { 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; } From 543260fb0a62e96621825d57181a03ae6e25df26 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 4 Jun 2024 14:16:44 -0500 Subject: [PATCH 4/6] Refactor default presets code for get_theme_data --- .../class-wp-theme-json-resolver.php | 70 +++++-------------- 1 file changed, 18 insertions(+), 52 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json-resolver.php b/src/wp-includes/class-wp-theme-json-resolver.php index c3a5db45ad79a..db4b766b82520 100644 --- a/src/wp-includes/class-wp-theme-json-resolver.php +++ b/src/wp-includes/class-wp-theme-json-resolver.php @@ -287,59 +287,25 @@ public static function get_theme_data( $deprecated = array(), $options = array() */ $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(); - } - - $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; + /* + * 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' ); - 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 From c22c4e67021f52e0e736ecfae57cffb105163c96 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 4 Jun 2024 14:27:19 -0500 Subject: [PATCH 5/6] Remove unnecessary isset checks --- src/wp-includes/class-wp-theme-json.php | 30 ------------------------- 1 file changed, 30 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 18e0872eb4673..ec1d89dd7014e 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -3524,53 +3524,32 @@ public static function get_from_editor_settings( $settings ) { // 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 @@ public static function get_from_editor_settings( $settings ) { $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']; } From 71a28451a584ba2eb7a0afa22da744bfbeaa71dd Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 4 Jun 2024 14:33:05 -0500 Subject: [PATCH 6/6] Fix doc comment for set_spacing_sizes --- src/wp-includes/class-wp-theme-json.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index ec1d89dd7014e..79d1c2e968d81 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -3745,10 +3745,9 @@ public function get_data() { * 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 */