wppaste
WordPress

WP_Theme_JSON_Schema

Since
5.9.0
Source
wp-includes/class-wp-theme-json-schema.php:20
Class that migrates a given theme.json structure to the latest schema.

Description

This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes).
This is a low-level API that may need to do breaking changes. Please, use get_global_settings, get_global_styles, and get_global_stylesheet instead.

Compatibility

WordPress
since 5.9.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Methods · 6

Source code

#[AllowDynamicProperties]class WP_Theme_JSON_Schema { 	/**	 * Maps old properties to their new location within the schema's settings.	 * This will be applied at both the defaults and individual block levels.	 */	const V1_TO_V2_RENAMED_PATHS = array(		'border.customRadius'         => 'border.radius',		'spacing.customMargin'        => 'spacing.margin',		'spacing.customPadding'       => 'spacing.padding',		'typography.customLineHeight' => 'typography.lineHeight',	); 	/**	 * Function that migrates a given theme.json structure to the last version.	 *	 * @since 5.9.0	 * @since 6.6.0 Migrate up to v3 and add $origin parameter.	 *	 * @param array $theme_json The structure to migrate.	 * @param string $origin    Optional. What source of data this object represents.	 *                          One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.	 * @return array The structure in the last version.	 */	public static function migrate( $theme_json, $origin = 'theme' ) {		if ( ! isset( $theme_json['version'] ) ) {			$theme_json = array(				'version' => WP_Theme_JSON::LATEST_SCHEMA,			);		} 		// Migrate each version in order starting with the current version.		switch ( $theme_json['version'] ) {			case 1:				$theme_json = self::migrate_v1_to_v2( $theme_json );				// Deliberate fall through. Once migrated to v2, also migrate to v3.			case 2:				$theme_json = self::migrate_v2_to_v3( $theme_json, $origin );		} 		return $theme_json;	} 	/**	 * Removes the custom prefixes for a few properties	 * that were part of v1:	 *	 * 'border.customRadius'         => 'border.radius',	 * 'spacing.customMargin'        => 'spacing.margin',	 * 'spacing.customPadding'       => 'spacing.padding',	 * 'typography.customLineHeight' => 'typography.lineHeight',	 *	 * @since 5.9.0	 *	 * @param array $old Data to migrate.	 *	 * @return array Data without the custom prefixes.	 */	private static function migrate_v1_to_v2( $old ) {		// Copy everything.		$new = $old; 		// Overwrite the things that changed.		if ( isset( $old['settings'] ) ) {			$new['settings'] = self::rename_paths( $old['settings'], self::V1_TO_V2_RENAMED_PATHS );		} 		// Set the new version.		$new['version'] = 2; 		return $new;	} 	/**	 * Migrates from v2 to v3.	 *	 * - Sets settings.typography.defaultFontSizes to false if settings.typography.fontSizes are defined.	 * - Sets settings.spacing.defaultSpacingSizes to false if settings.spacing.spacingSizes are defined.	 * - Prevents settings.spacing.spacingSizes from merging with settings.spacing.spacingScale by

Changelog

Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-theme-json-schema.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.