Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Export: If the theme declares a version number then add a schema #39775

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 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,8 +99,21 @@ 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'] ) {
global $wp_version;
$theme_json_version = substr( $wp_version, 0, strpos( $wp_version, '-' ) );
if ( defined( 'IS_GUTENBERG_PLUGIN' ) ) {
$theme_json_version = 'trunk';
}
$schema = array( '$schema' => 'https://schemas.wp.org/wp/' . $theme_json_version . '/theme.json' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the convo where we talked about this, I've noticed that this code returns:

  • https://schemas.wp.org/wp/trunk/theme.json in the Gutenberg plugin: shouldn't it return https://schemas.wp.org/trunk/theme.json instead?
  • It contains the patch version as in: https://schemas.wp.org/wp/5.9.3/theme.json when running on WordPress versions with patch versions (all of them but 6.0). Shouldn't it return https://schemas.wp.org/wp/5.9/theme.json instead? Note that the Gutenberg branches that host the schema don't have the minor: 5.9, 5.8.

cc @scruffian @draganescu

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that. There's a fix here: #40106

$theme_json_raw = array_merge( $schema, $theme_json_raw );
}

// Convert to a string.
$theme_json_encoded = wp_json_encode( $tree->get_data(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$theme_json_encoded = wp_json_encode( $theme_json_raw, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
// Replace 4 spaces with a tab.
$theme_json_tabbed = preg_replace( '~(?:^|\G)\h{4}~m', "\t", $theme_json_encoded );
// Add the theme.json file to the zip.
Expand Down