Skip to content

Commit

Permalink
Skip defaultFontSizes migration for custom origin theme.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlende committed Mar 18, 2024
1 parent a0e0831 commit 14f4ae2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
11 changes: 0 additions & 11 deletions lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
29 changes: 22 additions & 7 deletions lib/class-wp-theme-json-schema-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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();
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 14f4ae2

Please sign in to comment.