PluginProbe
Gutenberg / 17.0.2
Gutenberg v17.0.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | lib/class-wp-theme-json-schema-gutenberg.php +39 -70 23.7.0 → 17.0.2 View file →
@@ -1,10 +1,14 @@
1 1 <?php
2 2 /**
3 3 * WP_Theme_JSON_Schema_Gutenberg class
4 4 *
5 + * This class/file will NOT be backported to Core. It exists to provide a
6 + * migration path for theme.json files that used the deprecated "behaviors".
7 + * This file will be removed from Gutenberg in version 17.0.0.
8 + *
5 9 * @package gutenberg
6 - * @since 5.9.0
10 + * @since 16.7.0
7 11 */
8 12
9 13 if ( class_exists( 'WP_Theme_JSON_Schema_Gutenberg' ) ) {
10 14 return;
@@ -37,32 +41,28 @@
37 41 /**
38 42 * Function that migrates a given theme.json structure to the last version.
39 43 *
40 44 * @since 5.9.0
41 - * @since 6.6.0 Migrate up to v3.
42 45 *
43 - * @param array $theme_json The structure to migrate.
44 - * @param string $origin Optional. What source of data this object represents.
45 - * One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
46 + * @param array $theme_json The structure to migrate.
46 47 *
47 48 * @return array The structure in the last version.
48 49 */
49 - public static function migrate( $theme_json, $origin = 'theme' ) {
50 + public static function migrate( $theme_json ) {
50 51 if ( ! isset( $theme_json['version'] ) ) {
51 52 $theme_json = array(
52 - 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
53 + 'version' => WP_Theme_JSON::LATEST_SCHEMA,
53 54 );
54 55 }
55 56
56 - // Migrate each version in order starting with the current version.
57 - switch ( $theme_json['version'] ) {
58 - case 1:
59 - $theme_json = self::migrate_v1_to_v2( $theme_json );
60 - // Deliberate fall through. Once migrated to v2, also migrate to v3.
61 - case 2:
62 - $theme_json = self::migrate_v2_to_v3( $theme_json, $origin );
57 + if ( 1 === $theme_json['version'] ) {
58 + $theme_json = self::migrate_v1_to_v2( $theme_json );
63 59 }
64 60
61 + if ( 2 === $theme_json['version'] ) {
62 + $theme_json = self::migrate_deprecated_lightbox_behaviors( $theme_json );
63 + }
64 +
65 65 return $theme_json;
66 66 }
67 67
68 68 /**
@@ -94,74 +94,43 @@
94 94
95 95 return $new;
96 96 }
97 97
98 +
98 99 /**
99 - * Migrates from v2 to v3.
100 + * Migrate away from the previous syntax that used a top-level "behaviors" key
101 + * in the `theme.json` to a new "lightbox" setting.
100 102 *
101 - * - Sets settings.typography.defaultFontSizes to false if settings.typography.fontSizes are defined.
102 - * - Sets settings.spacing.defaultSpacingSizes to false if settings.spacing.spacingSizes are defined.
103 - * - Prevents settings.spacing.spacingSizes from merging with settings.spacing.spacingScale by
104 - * unsetting spacingScale when spacingSizes are defined.
103 + * This function SHOULD NOT be ported to Core!!!
105 104 *
106 - * @since 6.6.0
105 + * It is a temporary migration that will be removed in Gutenberg 17.0.0
107 106 *
108 - * @param array $old Data to migrate.
109 - * @param string $origin What source of data this object represents.
110 - * One of 'blocks', 'default', 'theme', or 'custom'.
111 - * @return array Data with defaultFontSizes set to false.
107 + * @since 16.7.0
108 + *
109 + * @param array $old Data with (potentially) behaviors.
110 + * @return array Data with behaviors removed.
112 111 */
113 - private static function migrate_v2_to_v3( $old, $origin ) {
112 + private static function migrate_deprecated_lightbox_behaviors( $old ) {
114 113 // Copy everything.
115 114 $new = $old;
116 115
117 - // Set the new version.
118 - $new['version'] = 3;
119 -
120 - /*
121 - * Remaining changes do not need to be applied to the custom origin,
122 - * as they should take on the value of the theme origin.
123 - */
124 - if ( 'custom' === $origin ) {
125 - return $new;
116 + // Migrate the old behaviors syntax to the new "lightbox" syntax.
117 + if ( isset( $old['behaviors']['blocks']['core/image']['lightbox']['enabled'] ) ) {
118 + _wp_array_set(
119 + $new,
120 + array( 'settings', 'blocks', 'core/image', 'lightbox', 'enabled' ),
121 + $old['behaviors']['blocks']['core/image']['lightbox']['enabled']
122 + );
126 123 }
127 124
128 - /*
129 - * Even though defaultFontSizes is a new setting, we need to migrate
130 - * it as it controls the PRESETS_METADATA prevent_override which was
131 - * previously hardcoded to false. This only needs to happen when the
132 - * theme provided font sizes as they could match the default ones and
133 - * affect the generated CSS. And in v2 we provided default font sizes
134 - * when the theme did not provide any.
135 - */
136 - if ( isset( $old['settings']['typography']['fontSizes'] ) ) {
137 - $new['settings']['typography']['defaultFontSizes'] = false;
138 - }
139 -
140 - /*
141 - * Similarly to defaultFontSizes, we need to migrate defaultSpacingSizes
142 - * as it controls the PRESETS_METADATA prevent_override which was
143 - * previously hardcoded to false. This only needs to happen when the
144 - * theme provided spacing sizes via spacingSizes or spacingScale.
145 - */
146 - if (
147 - isset( $old['settings']['spacing']['spacingSizes'] ) ||
148 - isset( $old['settings']['spacing']['spacingScale'] )
149 - ) {
150 - $new['settings']['spacing']['defaultSpacingSizes'] = false;
151 - }
152 -
153 - /*
154 - * In v3 spacingSizes is merged with the generated spacingScale sizes
155 - * instead of completely replacing them. The v3 behavior is what was
156 - * documented for the v2 schema, but the code never actually did work
157 - * that way. Instead of surprising users with a behavior change two
158 - * years after the fact at the same time as a v3 update is introduced,
159 - * we'll continue using the "bugged" behavior for v2 themes. And treat
160 - * the "bug fix" as a breaking change for v3.
161 - */
162 - if ( isset( $old['settings']['spacing']['spacingSizes'] ) ) {
163 - unset( $new['settings']['spacing']['spacingScale'] );
125 + // Migrate the behaviors setting to the new syntax. This setting controls
126 + // whether the Lightbox UI shows up in the block editor.
127 + if ( isset( $old['settings']['blocks']['core/image']['behaviors']['lightbox'] ) ) {
128 + _wp_array_set(
129 + $new,
130 + array( 'settings', 'blocks', 'core/image', 'lightbox', 'allowEditing' ),
131 + $old['settings']['blocks']['core/image']['behaviors']['lightbox']
132 + );
164 133 }
165 134
166 135 return $new;
167 136 }