Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Commit d32b23e

Browse files
committed
Merge pull request #2163 from WP-API/1260-delete-comment-response
Return original resource with `DELETE /wp/v2/comments/<id>`
2 parents 67bbd14 + d23f5ab commit d32b23e

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

lib/endpoints/class-wp-rest-comments-controller.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,11 @@ public function delete_item( $request ) {
487487
*/
488488
$supports_trash = apply_filters( 'rest_comment_trashable', ( EMPTY_TRASH_DAYS > 0 ), $comment );
489489

490-
$get_request = new WP_REST_Request;
491-
$get_request->set_param( 'id', $id );
492-
$get_request->set_param( 'context', 'edit' );
493-
$response = $this->prepare_item_for_response( $comment, $get_request );
490+
$request->set_param( 'context', 'edit' );
491+
$response = $this->prepare_item_for_response( $comment, $request );
494492

495493
if ( $force ) {
496494
$result = wp_delete_comment( $comment->comment_ID, true );
497-
$status = 'deleted';
498495
} else {
499496
// If we don't support trashing for this type, error out
500497
if ( ! $supports_trash ) {
@@ -506,28 +503,20 @@ public function delete_item( $request ) {
506503
}
507504

508505
$result = wp_trash_comment( $comment->comment_ID );
509-
$status = 'trashed';
510506
}
511507

512-
$data = $response->get_data();
513-
$data = array(
514-
'data' => $data,
515-
$status => true,
516-
);
517-
$response->set_data( $data );
518-
519508
if ( ! $result ) {
520509
return new WP_Error( 'rest_cannot_delete', __( 'The comment cannot be deleted.' ), array( 'status' => 500 ) );
521510
}
522511

523512
/**
524513
* Fires after a comment is deleted via the REST API.
525514
*
526-
* @param object $comment The deleted comment data.
527-
* @param array $data Delete status data.
528-
* @param WP_REST_Request $request The request sent to the API.
515+
* @param object $comment The deleted comment data.
516+
* @param WP_REST_Response $response The response returned from the API.
517+
* @param WP_REST_Request $request The request sent to the API.
529518
*/
530-
do_action( 'rest_delete_comment', $comment, $data, $request );
519+
do_action( 'rest_delete_comment', $comment, $response, $request );
531520

532521
return $response;
533522
}

tests/test-rest-comments-controller.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,7 @@ public function test_delete_item() {
10101010
$response = $this->server->dispatch( $request );
10111011
$this->assertEquals( 200, $response->get_status() );
10121012
$data = $response->get_data();
1013-
$this->assertEquals( $this->post_id, $data['data']['post'] );
1014-
$this->assertTrue( $data['trashed'] );
1013+
$this->assertEquals( $this->post_id, $data['post'] );
10151014
}
10161015

10171016
public function test_delete_item_skip_trash() {
@@ -1028,8 +1027,7 @@ public function test_delete_item_skip_trash() {
10281027
$response = $this->server->dispatch( $request );
10291028
$this->assertEquals( 200, $response->get_status() );
10301029
$data = $response->get_data();
1031-
$this->assertEquals( $this->post_id, $data['data']['post'] );
1032-
$this->assertTrue( $data['deleted'] );
1030+
$this->assertEquals( $this->post_id, $data['post'] );
10331031
}
10341032

10351033
public function test_delete_item_already_trashed() {
@@ -1044,7 +1042,6 @@ public function test_delete_item_already_trashed() {
10441042
$response = $this->server->dispatch( $request );
10451043
$this->assertEquals( 200, $response->get_status() );
10461044
$data = $response->get_data();
1047-
$this->assertTrue( $data['trashed'] );
10481045
$response = $this->server->dispatch( $request );
10491046
$this->assertErrorResponse( 'rest_already_trashed', $response, 410 );
10501047
}

0 commit comments

Comments
 (0)