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-users-controller.php

    r39106 r39126  
    8686                'args'                => array(
    8787                    'force'    => array(
     88                        'type'        => 'boolean',
    8889                        'default'     => false,
    8990                        'description' => __( 'Required to be true, as resource does not support trashing.' ),
     
    115116                'args'                => array(
    116117                    'force'    => array(
     118                        'type'        => 'boolean',
    117119                        'default'     => false,
    118120                        'description' => __( 'Required to be true, as resource does not support trashing.' ),
     
    654656        // We don't support trashing for this type, error out.
    655657        if ( ! $force ) {
    656             return new WP_Error( 'rest_trash_not_supported', __( 'Users do not support trashing.' ), array( 'status' => 501 ) );
     658            return new WP_Error( 'rest_trash_not_supported', __( 'Users do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
    657659        }
    658660
     
    671673        $request->set_param( 'context', 'edit' );
    672674
    673         $response = $this->prepare_item_for_response( $user, $request );
     675        $previous = $this->prepare_item_for_response( $user, $request );
    674676
    675677        /** Include admin user functions to get access to wp_delete_user() */
     
    681683            return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) );
    682684        }
     685
     686        $response = new WP_REST_Response();
     687        $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
    683688
    684689        /**
Note: See TracChangeset for help on using the changeset viewer.