From 14f4ae24c2d03a63d6f5a7c2ab575aff0f2bdfc4 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 18 Mar 2024 13:22:01 -0500 Subject: [PATCH] Skip defaultFontSizes migration for custom origin theme.json files --- ...est-global-styles-controller-gutenberg.php | 11 ------- lib/class-wp-theme-json-schema-gutenberg.php | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/class-wp-rest-global-styles-controller-gutenberg.php b/lib/class-wp-rest-global-styles-controller-gutenberg.php index c3e5e452d0e4c0..ca380265873f97 100644 --- a/lib/class-wp-rest-global-styles-controller-gutenberg.php +++ b/lib/class-wp-rest-global-styles-controller-gutenberg.php @@ -336,17 +336,6 @@ protected function prepare_item_for_database( $request ) { $config['settings'] = $existing_config['settings']; } - // TODO: Figure out where this should actually go. - if ( isset( $config['settings']['typography']['defaultFontSizes'] ) ) { - unset( $config['settings']['typography']['defaultFontSizes'] ); - if ( empty( $config['settings']['typography'] ) ) { - unset( $config['settings']['typography'] ); - if ( empty( $config['settings'] ) ) { - unset( $config['settings'] ); - } - } - } - $config['isGlobalStylesUserThemeJSON'] = true; $config['version'] = WP_Theme_JSON_Gutenberg::LATEST_SCHEMA; $changes->post_content = wp_json_encode( $config ); diff --git a/lib/class-wp-theme-json-schema-gutenberg.php b/lib/class-wp-theme-json-schema-gutenberg.php index 43309513708a94..567290df665709 100644 --- a/lib/class-wp-theme-json-schema-gutenberg.php +++ b/lib/class-wp-theme-json-schema-gutenberg.php @@ -95,9 +95,9 @@ private static function migrate_v1_to_v2( $old ) { } /** - * Sets settings.typography.defaultFontSizes to false as it drives - * PRESETS_METADATA prevent_override in class-wp-theme-json.php which was - * hardcoded to false in v2 but defaults to true in v3. + * Migrates from v2 to v3. + * + * - Sets settings.typography.defaultFontSizes to false. * * @since 6.5.0 * @@ -109,7 +109,25 @@ private static function migrate_v2_to_v3( $old ) { // Copy everything. $new = $old; - // Overwrite the things that changed. + // Set the new version. + $new['version'] = 3; + + /* + * Remaining changes do not need to be applied to the custom origin, + * as they should take on the value of the theme origin. + */ + if ( + isset( $new['isGlobalStylesUserThemeJSON'] ) && + true === $new['isGlobalStylesUserThemeJSON'] + ) { + return $new; + } + + /* + * Even though defaultFontSizes is a new setting, we need to migrate + * it to false as it controls the PRESETS_METADATA prevent_override + * which controls how CSS is generated and was hardcoded to false. + */ if ( ! isset( $new['settings'] ) ) { $new['settings'] = array(); } @@ -118,9 +136,6 @@ private static function migrate_v2_to_v3( $old ) { } $new['settings']['typography']['defaultFontSizes'] = false; - // Set the new version. - $new['version'] = 3; - return $new; }