From 40b22d120930000ad8368b1e0ab990656b4ca563 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 7 Dec 2021 18:38:02 +0000 Subject: [PATCH] REST API: Ensure that the export template endpoint returns a valid WP_Error object. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure that the export template endpoint returns a WP_Error object, including code and message, so that the site editor can display an error message. Add some basic unit tests to ensure that permission checks are working as expected. Follow-up to [52286]. Props Spacedmonkey, dlh, hellofromTonya , Mamaduka, TimothyBlynJacobs. Fixes #54448. Built from https://develop.svn.wordpress.org/trunk@52340 git-svn-id: http://core.svn.wordpress.org/trunk@51932 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-template-utils.php | 4 ++-- .../endpoints/class-wp-rest-edit-site-export-controller.php | 4 ++-- wp-includes/version.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index 6a53fd6730..28efb5cbad 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -913,7 +913,7 @@ function block_footer_area() { */ function wp_generate_block_templates_export_file() { if ( ! class_exists( 'ZipArchive' ) ) { - return new WP_Error( __( 'Zip Export not supported.' ) ); + return new WP_Error( 'missing_zip_package', __( 'Zip Export not supported.' ) ); } $obscura = wp_generate_password( 12, false, false ); @@ -921,7 +921,7 @@ function wp_generate_block_templates_export_file() { $zip = new ZipArchive(); if ( true !== $zip->open( $filename, ZipArchive::CREATE ) ) { - return new WP_Error( __( 'Unable to open export file (archive) for writing.' ) ); + return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.' ) ); } $zip->addEmptyDir( 'theme' ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php index 1bd40cd637..d5abfa5682 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php @@ -54,8 +54,8 @@ class WP_REST_Edit_Site_Export_Controller extends WP_REST_Controller { */ public function permissions_check() { if ( ! current_user_can( 'edit_theme_options' ) ) { - new WP_Error( - 'rest_cannot_view_url_details', + return new WP_Error( + 'rest_cannot_export_templates', __( 'Sorry, you are not allowed to export templates and template parts.' ), array( 'status' => rest_authorization_required_code() ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index bf4440d189..a427642995 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-beta1-52339'; +$wp_version = '5.9-beta1-52340'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.