Ticket #38494: 38494.3.diff
File 38494.3.diff, 10.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
726 726 727 727 $request->set_param( 'context', 'edit' ); 728 728 729 $ response= $this->prepare_item_for_response( $comment, $request );729 $previous = $this->prepare_item_for_response( $comment, $request ); 730 730 731 731 if ( $force ) { 732 732 $result = wp_delete_comment( $comment->comment_ID, true ); 733 734 $response = new WP_REST_Response(); 735 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 733 736 } else { 734 737 // If this type doesn't support trashing, error out. 735 738 if ( ! $supports_trash ) { … … 741 744 } 742 745 743 746 $result = wp_trash_comment( $comment->comment_ID ); 747 $comment = get_comment( $comment->comment_ID ); 748 $response = $this->prepare_item_for_response( $comment, $request ); 744 749 } 745 750 746 751 if ( ! $result ) { -
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
749 749 750 750 $request->set_param( 'context', 'edit' ); 751 751 752 $response = $this->prepare_item_for_response( $post, $request );753 752 754 753 // If we're forcing, then delete permanently. 755 754 if ( $force ) { 755 $previous = $this->prepare_item_for_response( $post, $request ); 756 756 $result = wp_delete_post( $id, true ); 757 $response = new WP_REST_Response(); 758 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 757 759 } else { 758 760 // If we don't support trashing for this type, error out. 759 761 if ( ! $supports_trash ) { … … 768 770 // (Note that internally this falls through to `wp_delete_post` if 769 771 // the trash is disabled.) 770 772 $result = wp_trash_post( $id ); 773 $post = $this->get_post( $id ); 774 $response = $this->prepare_item_for_response( $post, $request ); 771 775 } 772 776 773 777 if ( ! $result ) { -
src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
93 93 'methods' => WP_REST_Server::DELETABLE, 94 94 'callback' => array( $this, 'delete_item' ), 95 95 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 96 'args' => array( 97 'force' => array( 98 'default' => false, 99 'description' => __( 'Required to be true, as resource does not support trashing.' ), 100 ), 101 ), 96 102 ), 97 103 'schema' => array( $this, 'get_public_item_schema' ), 98 104 )); … … 220 226 * @return true|WP_Error True on success, or WP_Error object on failure. 221 227 */ 222 228 public function delete_item( $request ) { 229 $force = isset( $request['force'] ) ? (bool) $request['force'] : false; 230 231 // We don't support trashing for this resource type. 232 if ( ! $force ) { 233 return new WP_Error( 'rest_trash_not_supported', __( 'Resource does not support trashing.' ), array( 'status' => 501 ) ); 234 } 235 236 $revision = $this->get_post( $request['id'] ); 237 $previous = $this->prepare_item_for_response( $revision, $request ); 238 223 239 $result = wp_delete_post( $request['id'], true ); 224 240 225 241 /** … … 234 250 */ 235 251 do_action( 'rest_delete_revision', $result, $request ); 236 252 237 if ( $result ) { 238 return true; 239 } else { 253 if ( ! $result ) { 240 254 return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); 241 255 } 256 257 $response = new WP_REST_Response(); 258 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 259 return $response; 242 260 } 243 261 244 262 /** -
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
573 573 574 574 $request->set_param( 'context', 'view' ); 575 575 576 $ response= $this->prepare_item_for_response( $term, $request );576 $previous = $this->prepare_item_for_response( $term, $request ); 577 577 578 578 $retval = wp_delete_term( $term->term_id, $term->taxonomy ); 579 579 … … 581 581 return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) ); 582 582 } 583 583 584 $response = new WP_REST_Response(); 585 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 586 584 587 /** 585 588 * Fires after a single term is deleted via the REST API. 586 589 * -
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
620 620 621 621 $request->set_param( 'context', 'edit' ); 622 622 623 $ response= $this->prepare_item_for_response( $user, $request );623 $previous = $this->prepare_item_for_response( $user, $request ); 624 624 625 625 /** Include admin user functions to get access to wp_delete_user() */ 626 626 require_once ABSPATH . 'wp-admin/includes/user.php'; … … 631 631 return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) ); 632 632 } 633 633 634 $response = new WP_REST_Response(); 635 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 636 634 637 /** 635 638 * Fires immediately after a user is deleted via the REST API. 636 639 * -
tests/phpunit/tests/rest-api/rest-categories-controller.php
716 716 $response = $this->server->dispatch( $request ); 717 717 $this->assertEquals( 200, $response->get_status() ); 718 718 $data = $response->get_data(); 719 $this->assertEquals( 'Deleted Category', $data['name'] ); 719 $this->assertTrue( $data['deleted'] ); 720 $this->assertEquals( 'Deleted Category', $data['previous']['name'] ); 720 721 } 721 722 722 723 public function test_delete_item_force_false() { -
tests/phpunit/tests/rest-api/rest-comments-controller.php
1622 1622 $response = $this->server->dispatch( $request ); 1623 1623 $this->assertEquals( 200, $response->get_status() ); 1624 1624 $data = $response->get_data(); 1625 $this->assertEquals( self::$post_id, $data['post'] ); 1625 $this->assertTrue( $data['deleted'] ); 1626 $this->assertEquals( self::$post_id, $data['previous']['post'] ); 1626 1627 } 1627 1628 1628 1629 public function test_delete_item_skip_trash() { … … 1639 1640 $response = $this->server->dispatch( $request ); 1640 1641 $this->assertEquals( 200, $response->get_status() ); 1641 1642 $data = $response->get_data(); 1642 $this->assertEquals( self::$post_id, $data['post'] ); 1643 $this->assertTrue( $data['deleted'] ); 1644 $this->assertNotEmpty( $data['previous']['post'] ); 1643 1645 } 1644 1646 1645 1647 public function test_delete_item_already_trashed() { -
tests/phpunit/tests/rest-api/rest-posts-controller.php
1830 1830 $this->assertEquals( 200, $response->get_status() ); 1831 1831 $data = $response->get_data(); 1832 1832 $this->assertEquals( 'Deleted post', $data['title']['raw'] ); 1833 $this->assertEquals( 'trash', $data['status'] ); 1833 1834 } 1834 1835 1835 1836 public function test_delete_item_skip_trash() { … … 1843 1844 $this->assertNotInstanceOf( 'WP_Error', $response ); 1844 1845 $this->assertEquals( 200, $response->get_status() ); 1845 1846 $data = $response->get_data(); 1846 $this->assertEquals( 'Deleted post', $data['title']['raw'] ); 1847 $this->assertTrue( $data['deleted'] ); 1848 $this->assertNotEmpty( $data['previous'] ); 1847 1849 } 1848 1850 1849 1851 public function test_delete_item_already_trashed() { -
tests/phpunit/tests/rest-api/rest-tags-controller.php
599 599 $response = $this->server->dispatch( $request ); 600 600 $this->assertEquals( 200, $response->get_status() ); 601 601 $data = $response->get_data(); 602 $this->assertEquals( 'Deleted Tag', $data['name'] ); 602 $this->assertTrue( $data['deleted'] ); 603 $this->assertEquals( 'Deleted Tag', $data['previous']['name'] ); 603 604 } 604 605 605 606 public function test_delete_item_force_false() { … … 641 642 642 643 $this->assertEquals( 200, $response->get_status() ); 643 644 $data = $response->get_data(); 644 $this->assertEquals( 'Deleted Tag', $data['name'] ); 645 $this->assertTrue( $data['deleted'] ); 646 $this->assertEquals( 'Deleted Tag', $data['previous']['name'] ); 645 647 } 646 648 647 649 public function grant_delete_term( $caps, $cap ) { -
tests/phpunit/tests/rest-api/rest-users-controller.php
1063 1063 1064 1064 $this->assertEquals( 200, $response->get_status() ); 1065 1065 $data = $response->get_data(); 1066 $this->assertEquals( 'Deleted User', $data['name'] ); 1066 $this->assertTrue( $data['deleted'] ); 1067 $this->assertEquals( 'Deleted User', $data['previous']['name'] ); 1067 1068 } 1068 1069 1069 1070 public function test_delete_item_no_trash() {