<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[39126] trunk: REST API: Modify the structure of our DELETE responses to be more explicit.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/39126">39126</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/39126","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>rachelbaker</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-11-03 20:04:59 +0000 (Thu, 03 Nov 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/38494">#38494</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestcommentscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestrevisionscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestuserscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestattachmentscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcategoriescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcommentscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpostscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestrevisionscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiresttagscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestuserscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-users-controller.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswprestcommentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php    2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php      2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -83,6 +83,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'permission_callback' => array( $this, 'delete_item_permissions_check' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'args'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'force'    => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                'type'        => 'boolean',
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'default'     => false,
</span><span class="cx" style="display: block; padding: 0 10px">                                                'description' => __( 'Whether to bypass trash and force deletion.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -738,14 +739,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $request->set_param( 'context', 'edit' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $this->prepare_item_for_response( $comment, $request );
-
</del><span class="cx" style="display: block; padding: 0 10px">                 if ( $force ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $previous = $this->prepare_item_for_response( $comment, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $result = wp_delete_comment( $comment->comment_ID, true );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $response = new WP_REST_Response();
+                       $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        // If this type doesn't support trashing, error out.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! $supports_trash ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing.' ), array( 'status' => 501 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( 'trash' === $comment->comment_approved ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -753,6 +755,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $result = wp_trash_comment( $comment->comment_ID );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $comment = get_comment( $comment->comment_ID );
+                       $response = $this->prepare_item_for_response( $comment, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $result ) {
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php       2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -101,6 +101,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'permission_callback' => array( $this, 'delete_item_permissions_check' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'args'                => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'force' => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                'type'        => 'boolean',
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'default'     => false,
</span><span class="cx" style="display: block; padding: 0 10px">                                                'description' => __( 'Whether to bypass trash and force deletion.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -757,15 +758,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $request->set_param( 'context', 'edit' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $this->prepare_item_for_response( $post, $request );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // If we're forcing, then delete permanently.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $force ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $previous = $this->prepare_item_for_response( $post, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $result = wp_delete_post( $id, true );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $response = new WP_REST_Response();
+                       $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        // If we don't support trashing for this type, error out.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! $supports_trash ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                return new WP_Error( 'rest_trash_not_supported', __( 'The post does not support trashing.' ), array( 'status' => 501 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         return new WP_Error( 'rest_trash_not_supported', __( 'The post does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Otherwise, only trash if we haven't already.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -776,6 +779,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        // (Note that internally this falls through to `wp_delete_post` if
</span><span class="cx" style="display: block; padding: 0 10px">                        // the trash is disabled.)
</span><span class="cx" style="display: block; padding: 0 10px">                        $result = wp_trash_post( $id );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $post = $this->get_post( $id );
+                       $response = $this->prepare_item_for_response( $post, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $result ) {
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php   2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php     2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -93,6 +93,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'methods'             => WP_REST_Server::DELETABLE,
</span><span class="cx" style="display: block; padding: 0 10px">                                'callback'            => array( $this, 'delete_item' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'permission_callback' => array( $this, 'delete_item_permissions_check' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'args'                => array(
+                                       'force' => array(
+                                               'type'        => 'boolean',
+                                               'default'     => false,
+                                               'description' => __( 'Required to be true, as resource does not support trashing.' ),
+                                       ),
+                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'schema' => array( $this, 'get_public_item_schema' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ));
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -220,6 +227,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return true|WP_Error True on success, or WP_Error object on failure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function delete_item( $request ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $force = isset( $request['force'] ) ? (bool) $request['force'] : false;
+
+               // We don't support trashing for this resource type.
+               if ( ! $force ) {
+                       return new WP_Error( 'rest_trash_not_supported', __( 'Revisions do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
+               }
+
+               $revision = $this->get_post( $request['id'] );
+               $previous = $this->prepare_item_for_response( $revision, $request );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $result = wp_delete_post( $request['id'], true );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,11 +251,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                do_action( 'rest_delete_revision', $result, $request );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $result ) {
-                       return true;
-               } else {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $result ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $response = new WP_REST_Response();
+               $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
+               return $response;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php       2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php 2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -116,6 +116,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'permission_callback' => array( $this, 'delete_item_permissions_check' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'args'                => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'force' => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                'type'        => 'boolean',
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'default'     => false,
</span><span class="cx" style="display: block; padding: 0 10px">                                                'description' => __( 'Required to be true, as resource does not support trashing.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -566,14 +567,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // We don't support trashing for this resource type.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $force ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_Error( 'rest_trash_not_supported', __( 'Resource does not support trashing.' ), array( 'status' => 501 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_Error( 'rest_trash_not_supported', __( 'Terms do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $term = get_term( (int) $request['id'], $this->taxonomy );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $request->set_param( 'context', 'view' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $this->prepare_item_for_response( $term, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $previous = $this->prepare_item_for_response( $term, $request );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $retval = wp_delete_term( $term->term_id, $term->taxonomy );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -581,6 +582,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $response = new WP_REST_Response();
+               $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Fires after a single term is deleted via the REST API.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestuserscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php       2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php 2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -85,6 +85,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'permission_callback' => array( $this, 'delete_item_permissions_check' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'args'                => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'force'    => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                'type'        => 'boolean',
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'default'     => false,
</span><span class="cx" style="display: block; padding: 0 10px">                                                'description' => __( 'Required to be true, as resource does not support trashing.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -114,6 +115,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'permission_callback' => array( $this, 'delete_current_item_permissions_check' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'args'                => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'force'    => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                'type'        => 'boolean',
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'default'     => false,
</span><span class="cx" style="display: block; padding: 0 10px">                                                'description' => __( 'Required to be true, as resource does not support trashing.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -653,7 +655,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // We don't support trashing for this type, error out.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $force ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_Error( 'rest_trash_not_supported', __( 'Users do not support trashing.' ), array( 'status' => 501 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_Error( 'rest_trash_not_supported', __( 'Users do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $user = get_userdata( $id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -670,7 +672,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $request->set_param( 'context', 'edit' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $this->prepare_item_for_response( $user, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $previous = $this->prepare_item_for_response( $user, $request );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /** Include admin user functions to get access to wp_delete_user() */
</span><span class="cx" style="display: block; padding: 0 10px">                require_once ABSPATH . 'wp-admin/includes/user.php';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -681,6 +683,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $response = new WP_REST_Response();
+               $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Fires immediately after a user is deleted via the REST API.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestattachmentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php        2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php  2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -730,6 +730,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $request->set_param( 'force', 'false' );
+               $response = $this->server->dispatch( $request );
+               $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Ensure the post still exists
</span><span class="cx" style="display: block; padding: 0 10px">                $post = get_post( $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotEmpty( $post );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestcategoriescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php 2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php   2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -725,16 +725,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $response->get_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 'Deleted Category', $data['name'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( $data['deleted'] );
+               $this->assertEquals( 'Deleted Category', $data['previous']['name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_delete_item_force_false() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_delete_item_no_trash() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 wp_set_current_user( self::$administrator );
</span><span class="cx" style="display: block; padding: 0 10px">                $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // force defaults to false
</del><span class="cx" style="display: block; padding: 0 10px">                 $response = $this->server->dispatch( $request );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 501, $response->get_status() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
+
+               $request->set_param( 'force', 'false' );
+               $response = $this->server->dispatch( $request );
+               $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_item_invalid_taxonomy() {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestcommentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php   2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php     2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1888,12 +1888,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'comment_post_ID'  => self::$post_id,
</span><span class="cx" style="display: block; padding: 0 10px">                        'user_id'          => self::$subscriber_id,
</span><span class="cx" style="display: block; padding: 0 10px">                ));
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $request->set_param( 'force', 'false' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $data = $response->get_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( self::$post_id, $data['post'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 'trash', $data['status'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_item_skip_trash() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1910,7 +1912,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $response->get_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( self::$post_id, $data['post'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( $data['deleted'] );
+               $this->assertNotEmpty( $data['previous']['post'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_item_already_trashed() {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpostscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php      2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php        2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2008,12 +2008,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$editor_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $request->set_param( 'force', 'false' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotInstanceOf( 'WP_Error', $response );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $response->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'Deleted post', $data['title']['raw'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( 'trash', $data['status'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_item_skip_trash() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2027,7 +2029,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotInstanceOf( 'WP_Error', $response );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $response->get_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 'Deleted post', $data['title']['raw'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( $data['deleted'] );
+               $this->assertNotEmpty( $data['previous'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_item_already_trashed() {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php  2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php    2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -184,11 +184,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_item() {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$editor_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $request->set_param( 'force', true );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNull( get_post( $this->revision_id1 ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_delete_item_no_trash() {
+               wp_set_current_user( self::$editor_id );
+
+               $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
+               $response = $this->server->dispatch( $request );
+               $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
+
+               $request->set_param( 'force', 'false' );
+               $response = $this->server->dispatch( $request );
+               $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
+
+               // Ensure the revision still exists
+               $this->assertNotNull( get_post( $this->revision_id1 ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_delete_item_no_permission() {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$contributor_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiresttagscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php       2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php 2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -625,16 +625,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $response->get_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 'Deleted Tag', $data['name'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( $data['deleted'] );
+               $this->assertEquals( 'Deleted Tag', $data['previous']['name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_delete_item_force_false() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_delete_item_no_trash() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 wp_set_current_user( self::$administrator );
</span><span class="cx" style="display: block; padding: 0 10px">                $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // force defaults to false
</del><span class="cx" style="display: block; padding: 0 10px">                 $response = $this->server->dispatch( $request );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 501, $response->get_status() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
+
+               $request->set_param( 'force', 'false' );
+               $response = $this->server->dispatch( $request );
+               $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_delete_item_invalid_term() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -667,7 +672,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $response->get_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 'Deleted Tag', $data['name'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( $data['deleted'] );
+               $this->assertEquals( 'Deleted Tag', $data['previous']['name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function grant_delete_term( $caps, $cap ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestuserscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-users-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-users-controller.php      2016-11-03 19:56:53 UTC (rev 39125)
+++ trunk/tests/phpunit/tests/rest-api/rest-users-controller.php        2016-11-03 20:04:59 UTC (rev 39126)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1154,25 +1154,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $response->get_data();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 'Deleted User', $data['name'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( $data['deleted'] );
+               $this->assertEquals( 'Deleted User', $data['previous']['name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_delete_current_item() {
-               $user_id = $this->factory->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User' ) );
-
-               wp_set_current_user( $user_id );
-               $user = wp_get_current_user();
-               update_site_option( 'site_admins', array( $user->user_login ) );
-
-               $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' );
-               $request['force'] = true;
-               $response = $this->server->dispatch( $request );
-
-               $this->assertEquals( 200, $response->get_status() );
-               $data = $response->get_data();
-               $this->assertEquals( 'Deleted User', $data['name'] );
-       }
-
</del><span class="cx" style="display: block; padding: 0 10px">         public function test_delete_item_no_trash() {
</span><span class="cx" style="display: block; padding: 0 10px">                $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1180,27 +1165,52 @@
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$user );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $userdata = get_userdata( $user_id ); // cache for later
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $request->set_param( 'force', 'false' );
+               $response = $this->server->dispatch( $request );
+               $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Ensure the user still exists
</span><span class="cx" style="display: block; padding: 0 10px">                $user = get_user_by( 'id', $user_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotEmpty( $user );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_delete_current_item() {
+               $user_id = $this->factory->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User' ) );
+
+               wp_set_current_user( $user_id );
+               $user = wp_get_current_user();
+               update_site_option( 'site_admins', array( $user->user_login ) );
+
+               $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' );
+               $request['force'] = true;
+               $response = $this->server->dispatch( $request );
+
+               $this->assertEquals( 200, $response->get_status() );
+               $data = $response->get_data();
+               $this->assertTrue( $data['deleted'] );
+               $this->assertEquals( 'Deleted User', $data['previous']['name'] );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_delete_current_item_no_trash() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $user_id = $this->factory->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( $user_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $user = wp_get_current_user();
</span><span class="cx" style="display: block; padding: 0 10px">                update_site_option( 'site_admins', array( $user->user_login ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $userdata = get_userdata( $user_id ); // cache for later
</del><span class="cx" style="display: block; padding: 0 10px">                 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = $this->server->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $request->set_param( 'force', 'false' );
+               $response = $this->server->dispatch( $request );
+               $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Ensure the user still exists
</span><span class="cx" style="display: block; padding: 0 10px">                $user = get_user_by( 'id', $user_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotEmpty( $user );
</span></span></pre>
</div>
</div>

</body>
</html>