Skip to content

Commit 7c796cd

Browse files
committed
Pass origin into migrate instead of relying on isGlobalStylesUserThemeJSON
1 parent ffb6c43 commit 7c796cd

3 files changed

+11
-12
lines changed

lib/class-wp-theme-json-gutenberg.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ public function __construct( $theme_json = array( 'version' => WP_Theme_JSON_Gut
741741
$origin = 'theme';
742742
}
743743

744-
$this->theme_json = WP_Theme_JSON_Schema_Gutenberg::migrate( $theme_json );
744+
$this->theme_json = WP_Theme_JSON_Schema_Gutenberg::migrate( $theme_json, $origin );
745745
$registry = WP_Block_Type_Registry::get_instance();
746746
$valid_block_names = array_keys( $registry->get_all_registered() );
747747
$valid_element_names = array_keys( static::ELEMENTS );

lib/class-wp-theme-json-resolver-gutenberg.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ public static function get_user_data() {
568568
isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) &&
569569
$decoded_data['isGlobalStylesUserThemeJSON']
570570
) {
571+
unset( $decoded_data['isGlobalStylesUserThemeJSON'] );
571572
$config = $decoded_data;
572573
}
573574
}
@@ -576,9 +577,6 @@ public static function get_user_data() {
576577
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
577578
$config = $theme_json->get_data();
578579

579-
// Needs to be set for schema migrations of user data.
580-
$config['isGlobalStylesUserThemeJSON'] = true;
581-
582580
static::$user = new WP_Theme_JSON_Gutenberg( $config, 'custom' );
583581

584582
return static::$user;

lib/class-wp-theme-json-schema-gutenberg.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ class WP_Theme_JSON_Schema_Gutenberg {
4040
* @since 5.9.0
4141
* @since 6.6.0 Migrate up to v3.
4242
*
43-
* @param array $theme_json The structure to migrate.
43+
* @param array $theme_json The structure to migrate.
44+
* @param string $origin Optional. What source of data this object represents.
45+
* One of 'default', 'theme', or 'custom'. Default 'theme'.
4446
*
4547
* @return array The structure in the last version.
4648
*/
47-
public static function migrate( $theme_json ) {
49+
public static function migrate( $theme_json, $origin = 'theme' ) {
4850
if ( ! isset( $theme_json['version'] ) ) {
4951
$theme_json = array(
5052
'version' => WP_Theme_JSON::LATEST_SCHEMA,
@@ -57,7 +59,7 @@ public static function migrate( $theme_json ) {
5759
$theme_json = self::migrate_v1_to_v2( $theme_json );
5860
// no break
5961
case 2:
60-
$theme_json = self::migrate_v2_to_v3( $theme_json );
62+
$theme_json = self::migrate_v2_to_v3( $theme_json, $origin );
6163
// no break
6264
}
6365

@@ -102,10 +104,12 @@ private static function migrate_v1_to_v2( $old ) {
102104
* @since 6.6.0
103105
*
104106
* @param array $old Data to migrate.
107+
* @param string $origin What source of data this object represents.
108+
* One of 'default', 'theme', or 'custom'.
105109
*
106110
* @return array Data with defaultFontSizes set to false.
107111
*/
108-
private static function migrate_v2_to_v3( $old ) {
112+
private static function migrate_v2_to_v3( $old, $origin ) {
109113
// Copy everything.
110114
$new = $old;
111115

@@ -116,10 +120,7 @@ private static function migrate_v2_to_v3( $old ) {
116120
* Remaining changes do not need to be applied to the custom origin,
117121
* as they should take on the value of the theme origin.
118122
*/
119-
if (
120-
isset( $new['isGlobalStylesUserThemeJSON'] ) &&
121-
true === $new['isGlobalStylesUserThemeJSON']
122-
) {
123+
if ( 'custom' === $origin ) {
123124
return $new;
124125
}
125126

0 commit comments

Comments
 (0)