Skip to content

Commit

Permalink
Theme Export: If the theme declares a version number then add a schema
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Mar 28, 2022
1 parent 5a71300 commit 29b0e66
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/compat/wordpress-6.0/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ function gutenberg_generate_block_templates_export_file() {
// Load theme.json into the zip file.
$tree = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data();
$tree->merge( WP_Theme_JSON_Resolver_Gutenberg::get_user_data() );
$theme_json_raw = $tree->get_data();
// If a version is defined, add a schema.
if ( $theme_json_raw['version'] && in_array( $theme_json_raw['version'], array( "1", "2" ) ) ) {
// Put $schema at the start of the array.
$theme_json_raw = array_reverse( $theme_json_raw );
$theme_json_raw['$schema'] = "https://json.schemastore.org/theme-v1.json";
$theme_json_raw = array_reverse( $theme_json_raw );
}

$zip->addFromString(
'theme.json',
wp_json_encode( $tree->get_data(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
wp_json_encode( $theme_json_raw, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
);

// Save changes to the zip file.
Expand Down

0 comments on commit 29b0e66

Please sign in to comment.