Changeset 58328 for trunk/src/wp-includes/class-wp-theme-json-schema.php
- Timestamp:
- 06/04/2024 11:53:37 AM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json-schema.php
r56753 r58328 36 36 * 37 37 * @since 5.9.0 38 * @since 6.6.0 Migrate up to v3. 38 39 * 39 40 * @param array $theme_json The structure to migrate. … … 48 49 } 49 50 50 if ( 1 === $theme_json['version'] ) { 51 $theme_json = self::migrate_v1_to_v2( $theme_json ); 51 // Migrate each version in order starting with the current version. 52 switch ( $theme_json['version'] ) { 53 case 1: 54 $theme_json = self::migrate_v1_to_v2( $theme_json ); 55 // no break 56 case 2: 57 $theme_json = self::migrate_v2_to_v3( $theme_json ); 58 // no break 52 59 } 53 60 … … 81 88 // Set the new version. 82 89 $new['version'] = 2; 90 91 return $new; 92 } 93 94 /** 95 * Migrates from v2 to v3. 96 * 97 * - Sets settings.typography.defaultFontSizes to false. 98 * 99 * @since 6.6.0 100 * 101 * @param array $old Data to migrate. 102 * 103 * @return array Data with defaultFontSizes set to false. 104 */ 105 private static function migrate_v2_to_v3( $old ) { 106 // Copy everything. 107 $new = $old; 108 109 // Set the new version. 110 $new['version'] = 3; 111 112 /* 113 * Remaining changes do not need to be applied to the custom origin, 114 * as they should take on the value of the theme origin. 115 */ 116 if ( 117 isset( $new['isGlobalStylesUserThemeJSON'] ) && 118 true === $new['isGlobalStylesUserThemeJSON'] 119 ) { 120 return $new; 121 } 122 123 /* 124 * Even though defaultFontSizes and defaultSpacingSizes are new 125 * settings, we need to migrate them as they each control 126 * PRESETS_METADATA prevent_override values which were previously 127 * hardcoded to false. This only needs to happen when the theme provides 128 * fontSizes or spacingSizes as they could match the default ones and 129 * affect the generated CSS. 130 */ 131 if ( isset( $old['settings']['typography']['fontSizes'] ) ) { 132 if ( ! isset( $new['settings'] ) ) { 133 $new['settings'] = array(); 134 } 135 if ( ! isset( $new['settings']['typography'] ) ) { 136 $new['settings']['typography'] = array(); 137 } 138 $new['settings']['typography']['defaultFontSizes'] = false; 139 } 140 141 /* 142 * Similarly to defaultFontSizes, we need to migrate defaultSpacingSizes 143 * as it controls the PRESETS_METADATA prevent_override which was 144 * previously hardcoded to false. This only needs to happen when the 145 * theme provided spacing sizes via spacingSizes or spacingScale. 146 */ 147 if ( 148 isset( $old['settings']['spacing']['spacingSizes'] ) || 149 isset( $old['settings']['spacing']['spacingScale'] ) 150 ) { 151 if ( ! isset( $new['settings'] ) ) { 152 $new['settings'] = array(); 153 } 154 if ( ! isset( $new['settings']['spacing'] ) ) { 155 $new['settings']['spacing'] = array(); 156 } 157 $new['settings']['spacing']['defaultSpacingSizes'] = false; 158 } 159 160 /* 161 * In v3 spacingSizes is merged with the generated spacingScale sizes 162 * instead of completely replacing them. The v3 behavior is what was 163 * documented for the v2 schema, but the code never actually did work 164 * that way. Instead of surprising users with a behavior change two 165 * years after the fact at the same time as a v3 update is introduced, 166 * we'll continue using the "bugged" behavior for v2 themes. And treat 167 * the "bug fix" as a breaking change for v3. 168 */ 169 if ( isset( $old['settings']['spacing']['spacingSizes'] ) ) { 170 unset( $new['settings']['spacing']['spacingScale'] ); 171 } 83 172 84 173 return $new;
Note: See TracChangeset
for help on using the changeset viewer.