WP_Theme_JSON_Schema::migrate()public staticWP 5.9.0

Function that migrates a given theme.json structure to the last version.

Method of the class: WP_Theme_JSON_Schema{}

No Hooks.

Return

Array. The structure in the last version.

Usage

$result = WP_Theme_JSON_Schema::migrate( $theme_json, $origin );
$theme_json(array) (required)
The structure to migrate.
$origin(string)
What source of data this object represents. One of 'blocks', 'default', 'theme', or 'custom'.
Default: 'theme'

Changelog

Since 5.9.0 Introduced.
Since 6.6.0 Migrate up to v3 and add $origin parameter.

WP_Theme_JSON_Schema::migrate() code WP 6.7.1

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;
}