Make WordPress Core


Ignore:
Timestamp:
11/03/2016 08:04:59 PM (9 years ago)
Author:
rachelbaker
Message:

REST API: Modify the structure of our DELETE responses to be more explicit.

Add the deleted property to the root of the Response object to communicate if the delete action was successful. Move the state of the resource prior to the delete request under a new previous property. As a result DELETE responses are now structured like so:

{ deleted: true, previous: { ... } }

Also includes helpful information to DELETE requests for resources that are not trashable.

Props timmydcrawford, rmccue, jnylen0.
Fixes #38494.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r39106 r39126  
    117117                'args'                => array(
    118118                    'force' => array(
     119                        'type'        => 'boolean',
    119120                        'default'     => false,
    120121                        'description' => __( 'Required to be true, as resource does not support trashing.' ),
     
    567568        // We don't support trashing for this resource type.
    568569        if ( ! $force ) {
    569             return new WP_Error( 'rest_trash_not_supported', __( 'Resource does not support trashing.' ), array( 'status' => 501 ) );
     570            return new WP_Error( 'rest_trash_not_supported', __( 'Terms do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
    570571        }
    571572
     
    574575        $request->set_param( 'context', 'view' );
    575576
    576         $response = $this->prepare_item_for_response( $term, $request );
     577        $previous = $this->prepare_item_for_response( $term, $request );
    577578
    578579        $retval = wp_delete_term( $term->term_id, $term->taxonomy );
     
    581582            return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) );
    582583        }
     584
     585        $response = new WP_REST_Response();
     586        $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
    583587
    584588        /**
Note: See TracChangeset for help on using the changeset viewer.