| 1 |
<?php |
| 2 |
/** |
| 3 |
* Controller which provides REST endpoint for exporting current templates |
| 4 |
* and template parts. |
| 5 |
* |
| 6 |
* This class extension exists so that theme exporting takes into account any updates/changes to |
| 7 |
* WP_Theme_JSON_Gutenberg, WP_Theme_JSON_Resolver_Gutenberg or related classes. |
| 8 |
* |
| 9 |
* @package gutenberg |
| 10 |
* @subpackage REST_API |
| 11 |
* @since 5.9.0 |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( class_exists( 'WP_REST_Edit_Site_Export_Controller_Gutenberg' ) ) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
class WP_REST_Edit_Site_Export_Controller_Gutenberg extends WP_REST_Edit_Site_Export_Controller { |
| 19 |
/** |
| 20 |
* Output a ZIP file with an export of the current templates |
| 21 |
* and template parts from the site editor, and close the connection. |
| 22 |
* |
| 23 |
* @since 5.9.0 |
| 24 |
* |
| 25 |
* @return WP_Error|void |
| 26 |
*/ |
| 27 |
public function export() { |
| 28 |
// Generate the export file. |
| 29 |
$filename = gutenberg_generate_block_templates_export_file(); |
| 30 |
|
| 31 |
if ( is_wp_error( $filename ) ) { |
| 32 |
$filename->add_data( array( 'status' => 500 ) ); |
| 33 |
|
| 34 |
return $filename; |
| 35 |
} |
| 36 |
|
| 37 |
$theme_name = basename( get_stylesheet() ); |
| 38 |
header( 'Content-Type: application/zip' ); |
| 39 |
header( 'Content-Disposition: attachment; filename=' . $theme_name . '.zip' ); |
| 40 |
header( 'Content-Length: ' . filesize( $filename ) ); |
| 41 |
flush(); |
| 42 |
readfile( $filename ); |
| 43 |
unlink( $filename ); |
| 44 |
exit; |
| 45 |
} |
| 46 |
} |
| 47 |
|