Make WordPress Core


Ignore:
Timestamp:
12/07/2021 06:36:29 PM (3 years ago)
Author:
spacedmonkey
Message:

REST API: Ensure that the export template endpoint returns a valid WP_Error object.

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r52332 r52340  
    914914function wp_generate_block_templates_export_file() {
    915915    if ( ! class_exists( 'ZipArchive' ) ) {
    916         return new WP_Error( __( 'Zip Export not supported.' ) );
     916        return new WP_Error( 'missing_zip_package', __( 'Zip Export not supported.' ) );
    917917    }
    918918
     
    922922    $zip = new ZipArchive();
    923923    if ( true !== $zip->open( $filename, ZipArchive::CREATE ) ) {
    924         return new WP_Error( __( 'Unable to open export file (archive) for writing.' ) );
     924        return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.' ) );
    925925    }
    926926
Note: See TracChangeset for help on using the changeset viewer.