-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Add theme.json to export file (#39048)
* Override REST API route * Port changes from previous PR * Add export_theme_json method * Use new method to get exported data * Rename export_theme_json to get_data * Improve nesting * Update the export label Co-authored-by: André <[email protected]> Co-authored-by: Ben Dwyer <[email protected]>
- Loading branch information
1 parent
3041b45
commit 8fbf70c
Showing
9 changed files
with
302 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Temporary compatibility shims for features present in Gutenberg. | ||
* This file should be removed when WordPress 6.0.0 becomes the lowest | ||
* supported version by this plugin. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Creates an export of the current templates and | ||
* template parts from the site editor at the | ||
* specified path in a ZIP file. | ||
* | ||
* @since 5.9.0 | ||
* @since 6.0.0 Adds theme.json to the export archive. | ||
* | ||
* @return WP_Error|string Path of the ZIP file or error on failure. | ||
*/ | ||
function gutenberg_generate_block_templates_export_file() { | ||
if ( ! class_exists( 'ZipArchive' ) ) { | ||
return new WP_Error( 'missing_zip_package', __( 'Zip Export not supported.', 'gutenberg' ) ); | ||
} | ||
|
||
$obscura = wp_generate_password( 12, false, false ); | ||
$filename = get_temp_dir() . 'edit-site-export-' . $obscura . '.zip'; | ||
|
||
$zip = new ZipArchive(); | ||
if ( true !== $zip->open( $filename, ZipArchive::CREATE ) ) { | ||
return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.', 'gutenberg' ) ); | ||
} | ||
|
||
$zip->addEmptyDir( 'theme' ); | ||
$zip->addEmptyDir( 'theme/templates' ); | ||
$zip->addEmptyDir( 'theme/parts' ); | ||
|
||
// Load templates into the zip file. | ||
$templates = gutenberg_get_block_templates(); | ||
foreach ( $templates as $template ) { | ||
$template->content = _remove_theme_attribute_in_block_template_content( $template->content ); | ||
|
||
$zip->addFromString( | ||
'theme/templates/' . $template->slug . '.html', | ||
$template->content | ||
); | ||
} | ||
|
||
// Load template parts into the zip file. | ||
$template_parts = gutenberg_get_block_templates( array(), 'wp_template_part' ); | ||
foreach ( $template_parts as $template_part ) { | ||
$zip->addFromString( | ||
'theme/parts/' . $template_part->slug . '.html', | ||
$template_part->content | ||
); | ||
} | ||
|
||
$tree = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data(); | ||
$tree->merge( WP_Theme_JSON_Resolver_Gutenberg::get_user_data() ); | ||
|
||
$zip->addFromString( | ||
'theme/theme.json', | ||
wp_json_encode( $tree->get_data(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) | ||
); | ||
|
||
// Save changes to the zip file. | ||
$zip->close(); | ||
|
||
return $filename; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.