WP_REST_Edit_Site_Export_Controller::export() WordPress Method

The WP_REST_Edit_Site_Export_Controller::export() method allows you to generate an export file for your WordPress site. This file can be used to import your site into another WordPress installation.

WP_REST_Edit_Site_Export_Controller::export() #

Output a ZIP file with an export of the current templates and template parts from the site editor, and close the connection.


Return

(WP_Error|void)


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php

	public function export() {
		// Generate the export file.
		$filename = wp_generate_block_templates_export_file();

		if ( is_wp_error( $filename ) ) {
			$filename->add_data( array( 'status' => 500 ) );

			return $filename;
		}

		$theme_name = basename( get_stylesheet() );
		header( 'Content-Type: application/zip' );
		header( 'Content-Disposition: attachment; filename=' . $theme_name . '.zip' );
		header( 'Content-Length: ' . filesize( $filename ) );
		flush();
		readfile( $filename );
		unlink( $filename );
		exit;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.