Skip to content

Commit

Permalink
Refactor theme.json migrations to be a single class
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Nov 3, 2021
1 parent 23369ee commit 69c2a5c
Show file tree
Hide file tree
Showing 9 changed files with 554 additions and 557 deletions.
33 changes: 2 additions & 31 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function __construct( $theme_json = array(), $origin = 'theme' ) {
$origin = 'theme';
}

$theme_json = self::migrate( $theme_json );
$theme_json = WP_Theme_JSON_Schema::migrate( $theme_json );

$valid_block_names = array_keys( self::get_blocks_metadata() );
$valid_element_names = array_keys( self::ELEMENTS );
Expand All @@ -305,35 +305,6 @@ public function __construct( $theme_json = array(), $origin = 'theme' ) {
}
}

/**
* Function that migrates a given theme.json structure to the last version.
*
* @param array $theme_json The structure to migrate.
*
* @return array The structure in the last version.
*/
private static function migrate( $theme_json ) {
// Can be removed when the plugin minimum required version is WordPress 5.8.
// This doesn't need to land in WordPress core.
if ( ! isset( $theme_json['version'] ) || 0 === $theme_json['version'] ) {
$theme_json = WP_Theme_JSON_Schema_V0_To_V1::migrate( $theme_json );
}

// Provide backwards compatibility for settings that did not land in 5.8
// and have had their `custom` prefixed removed since.
// Can be removed when the plugin minimum required version is WordPress 5.9.
// This doesn't need to land in WordPress core.
if ( 1 === $theme_json['version'] ) {
$theme_json = WP_Theme_JSON_Schema_V1_Remove_Custom_Prefixes::migrate( $theme_json );
}

if ( 1 === $theme_json['version'] ) {
$theme_json = WP_Theme_JSON_Schema_V1_To_V2::migrate( $theme_json );
}

return $theme_json;
}

/**
* Sanitizes the input according to the schemas.
*
Expand Down Expand Up @@ -1455,7 +1426,7 @@ private static function is_safe_css_declaration( $property_name, $property_value
public static function remove_insecure_properties( $theme_json ) {
$sanitized = array();

$theme_json = self::migrate( $theme_json );
$theme_json = WP_Theme_JSON_Schema::migrate( $theme_json );

$valid_block_names = array_keys( self::get_blocks_metadata() );
$valid_element_names = array_keys( self::ELEMENTS );
Expand Down
116 changes: 0 additions & 116 deletions lib/class-wp-theme-json-schema-v1-remove-custom-prefixes.php

This file was deleted.

111 changes: 0 additions & 111 deletions lib/class-wp-theme-json-schema-v1-to-v2.php

This file was deleted.

Loading

0 comments on commit 69c2a5c

Please sign in to comment.