Skip to content

Commit 818a849

Browse files
ajlendeoandregal
authored andcommitted
Pass origin into migrate instead of relying on isGlobalStylesUserThemeJSON
1 parent 1863e49 commit 818a849

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
@@ -534,6 +534,7 @@ public static function get_user_data() {
534534
isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) &&
535535
$decoded_data['isGlobalStylesUserThemeJSON']
536536
) {
537+
unset( $decoded_data['isGlobalStylesUserThemeJSON'] );
537538
$config = $decoded_data;
538539
}
539540
}
@@ -542,9 +543,6 @@ public static function get_user_data() {
542543
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
543544
$config = $theme_json->get_data();
544545

545-
// Needs to be set for schema migrations of user data.
546-
$config['isGlobalStylesUserThemeJSON'] = true;
547-
548546
static::$user = new WP_Theme_JSON_Gutenberg( $config, 'custom' );
549547

550548
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
// Deliberate fall through. Once migrated to v2, also migrate to v3.
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
}
6264

6365
return $theme_json;
@@ -104,10 +106,12 @@ private static function migrate_v1_to_v2( $old ) {
104106
* @since 6.6.0
105107
*
106108
* @param array $old Data to migrate.
109+
* @param string $origin What source of data this object represents.
110+
* One of 'default', 'theme', or 'custom'.
107111
*
108112
* @return array Data with defaultFontSizes set to false.
109113
*/
110-
private static function migrate_v2_to_v3( $old ) {
114+
private static function migrate_v2_to_v3( $old, $origin ) {
111115
// Copy everything.
112116
$new = $old;
113117

@@ -118,10 +122,7 @@ private static function migrate_v2_to_v3( $old ) {
118122
* Remaining changes do not need to be applied to the custom origin,
119123
* as they should take on the value of the theme origin.
120124
*/
121-
if (
122-
isset( $new['isGlobalStylesUserThemeJSON'] ) &&
123-
true === $new['isGlobalStylesUserThemeJSON']
124-
) {
125+
if ( 'custom' === $origin ) {
125126
return $new;
126127
}
127128

0 commit comments

Comments
 (0)