Skip to content

Commit

Permalink
Theme Export: Convert spaces to tabs in theme.json
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Mar 28, 2022
1 parent 5a71300 commit 3542763
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/compat/wordpress-6.0/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ 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() );

// Convert to a string.
$theme_json_encoded = wp_json_encode( $tree->get_data(), 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.
$zip->addFromString(
'theme.json',
wp_json_encode( $tree->get_data(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
$theme_json_tabbed
);

// Save changes to the zip file.
Expand Down

0 comments on commit 3542763

Please sign in to comment.