WP_REST_Edit_Site_Export_Controller::export()publicWP 5.9.0

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

Метод класса: WP_REST_Edit_Site_Export_Controller{}

Хуков нет.

Возвращает

WP_Error|null.

Использование

$WP_REST_Edit_Site_Export_Controller = new WP_REST_Edit_Site_Export_Controller();
$WP_REST_Edit_Site_Export_Controller->export();

Список изменений

С версии 5.9.0 Введена.

Код WP_REST_Edit_Site_Export_Controller::export() WP 6.4.3

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;
}