From 9c8e01d97bcbf65507eccd1d522616246a23b7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:07:37 +0200 Subject: [PATCH 1/5] Update theme.json version schema --- lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php | 7 +++++++ lib/compat/wordpress-6.0/theme.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php b/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php index 8868185360acdb..579ba81d12099d 100644 --- a/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php +++ b/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php @@ -197,6 +197,13 @@ class WP_Theme_JSON_Gutenberg extends WP_Theme_JSON_5_9 { ), ); + /** + * The latest version of the schema in use. + * + * @var int + */ + const LATEST_SCHEMA = 3; + /** * Returns the current theme's wanted patterns(slugs) to be * registered from Pattern Directory. diff --git a/lib/compat/wordpress-6.0/theme.json b/lib/compat/wordpress-6.0/theme.json index 7691aa4a64e6a9..f66aa503f8ef3a 100644 --- a/lib/compat/wordpress-6.0/theme.json +++ b/lib/compat/wordpress-6.0/theme.json @@ -1,5 +1,5 @@ { - "version": 2, + "version": 3, "settings": { "appearanceTools": false, "border": { From 39b24f5c97af3b1a306aefdc898b85ce4161f4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:11:28 +0200 Subject: [PATCH 2/5] Add note about v2 to v3 migrations --- .../theme-json-reference/theme-json-migrations.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/reference-guides/theme-json-reference/theme-json-migrations.md b/docs/reference-guides/theme-json-reference/theme-json-migrations.md index cac253f64ffbe9..4f0be60a65999d 100644 --- a/docs/reference-guides/theme-json-reference/theme-json-migrations.md +++ b/docs/reference-guides/theme-json-reference/theme-json-migrations.md @@ -2,6 +2,10 @@ This guide documents the changes between different `theme.json` versions and how to upgrade. Using older versions will continue to be supported. Upgrading is recommended because new development will continue in the newer versions. +## Migrating from v2 to v3 + +Update `version` to `3`. No other changes necessary. + ## Migrating from v1 to v2 Upgrading to v2 enables some new features and adjusts the naming of some old features to be more consistent with one another. From 31e01312c55344119335deba6fcafb06696ae2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:47:15 +0200 Subject: [PATCH 3/5] Migrate 2 to 3 --- .../wordpress-5.9/class-wp-theme-json-schema-gutenberg.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-schema-gutenberg.php b/lib/compat/wordpress-5.9/class-wp-theme-json-schema-gutenberg.php index 0fa833c68072c6..8ea5e504b48935 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-schema-gutenberg.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-schema-gutenberg.php @@ -77,6 +77,10 @@ public static function migrate( $theme_json ) { $theme_json = self::migrate_v1_to_v2( $theme_json ); } + if ( 2 === $theme_json['version'] ) { + $theme_json['version'] = 3; + } + return $theme_json; } From cb7e5735b4701ae6e7c88c20c9a7c192c9a339cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:51:28 +0200 Subject: [PATCH 4/5] update controller tests --- phpunit/class-gutenberg-rest-global-styles-controller-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit/class-gutenberg-rest-global-styles-controller-test.php b/phpunit/class-gutenberg-rest-global-styles-controller-test.php index 01063aa7e51bc1..d3a8b42d210422 100644 --- a/phpunit/class-gutenberg-rest-global-styles-controller-test.php +++ b/phpunit/class-gutenberg-rest-global-styles-controller-test.php @@ -87,7 +87,7 @@ public function test_get_theme_items() { $data = $response->get_data(); $expected = array( array( - 'version' => 2, + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( From 4960e0e12fcd775d24d235cec99697e9a543246e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:52:50 +0200 Subject: [PATCH 5/5] Update tests --- phpunit/class-wp-theme-json-test.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index 89240870399dc9..56f822f3693611 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -2263,7 +2263,7 @@ function test_sanitization() { $actual = $theme_json->get_raw_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'styles' => array( 'spacing' => array( 'blockGap' => 'valid value', @@ -2329,7 +2329,7 @@ function test_export_data() { $theme->merge( $user ); $actual = $theme->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( @@ -2381,7 +2381,7 @@ function test_export_data_deals_with_empty_user_data() { $actual = $theme->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( @@ -2429,7 +2429,7 @@ function test_export_data_deals_with_empty_theme_data() { $actual = $user->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( @@ -2459,7 +2459,7 @@ function test_export_data_deals_with_empty_data() { 'theme' ); $actual_v2 = $theme_v2->get_data(); - $expected_v2 = array( 'version' => 2 ); + $expected_v2 = array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA ); $this->assertEqualSetsWithIndex( $expected_v2, $actual_v2 ); $theme_v1 = new WP_Theme_JSON_Gutenberg( @@ -2469,7 +2469,7 @@ function test_export_data_deals_with_empty_data() { 'theme' ); $actual_v1 = $theme_v1->get_data(); - $expected_v1 = array( 'version' => 2 ); + $expected_v1 = array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA ); $this->assertEqualSetsWithIndex( $expected_v1, $actual_v1 ); } @@ -2490,7 +2490,7 @@ function test_export_data_sets_appearance_tools() { $actual = $theme->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'settings' => array( 'appearanceTools' => true, 'blocks' => array(