Changeset 39126
- Timestamp:
- 11/03/2016 08:04:59 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39106 r39126 84 84 'args' => array( 85 85 'force' => array( 86 'type' => 'boolean', 86 87 'default' => false, 87 88 'description' => __( 'Whether to bypass trash and force deletion.' ), … … 739 740 $request->set_param( 'context', 'edit' ); 740 741 741 $response = $this->prepare_item_for_response( $comment, $request );742 743 742 if ( $force ) { 743 $previous = $this->prepare_item_for_response( $comment, $request ); 744 744 $result = wp_delete_comment( $comment->comment_ID, true ); 745 $response = new WP_REST_Response(); 746 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 745 747 } else { 746 748 // If this type doesn't support trashing, error out. 747 749 if ( ! $supports_trash ) { 748 return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing. ' ), array( 'status' => 501 ) );750 return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); 749 751 } 750 752 … … 754 756 755 757 $result = wp_trash_comment( $comment->comment_ID ); 758 $comment = get_comment( $comment->comment_ID ); 759 $response = $this->prepare_item_for_response( $comment, $request ); 756 760 } 757 761 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r39108 r39126 102 102 'args' => array( 103 103 'force' => array( 104 'type' => 'boolean', 104 105 'default' => false, 105 106 'description' => __( 'Whether to bypass trash and force deletion.' ), … … 758 759 $request->set_param( 'context', 'edit' ); 759 760 760 $response = $this->prepare_item_for_response( $post, $request );761 761 762 762 // If we're forcing, then delete permanently. 763 763 if ( $force ) { 764 $previous = $this->prepare_item_for_response( $post, $request ); 764 765 $result = wp_delete_post( $id, true ); 766 $response = new WP_REST_Response(); 767 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 765 768 } else { 766 769 // If we don't support trashing for this type, error out. 767 770 if ( ! $supports_trash ) { 768 return new WP_Error( 'rest_trash_not_supported', __( 'The post does not support trashing. ' ), array( 'status' => 501 ) );771 return new WP_Error( 'rest_trash_not_supported', __( 'The post does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); 769 772 } 770 773 … … 777 780 // the trash is disabled.) 778 781 $result = wp_trash_post( $id ); 782 $post = $this->get_post( $id ); 783 $response = $this->prepare_item_for_response( $post, $request ); 779 784 } 780 785 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
r39106 r39126 94 94 'callback' => array( $this, 'delete_item' ), 95 95 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 96 'args' => array( 97 'force' => array( 98 'type' => 'boolean', 99 'default' => false, 100 'description' => __( 'Required to be true, as resource does not support trashing.' ), 101 ), 102 ), 96 103 ), 97 104 'schema' => array( $this, 'get_public_item_schema' ), … … 221 228 */ 222 229 public function delete_item( $request ) { 230 $force = isset( $request['force'] ) ? (bool) $request['force'] : false; 231 232 // We don't support trashing for this resource type. 233 if ( ! $force ) { 234 return new WP_Error( 'rest_trash_not_supported', __( 'Revisions do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); 235 } 236 237 $revision = $this->get_post( $request['id'] ); 238 $previous = $this->prepare_item_for_response( $revision, $request ); 239 223 240 $result = wp_delete_post( $request['id'], true ); 224 241 … … 235 252 do_action( 'rest_delete_revision', $result, $request ); 236 253 237 if ( $result ) { 238 return true; 239 } else { 254 if ( ! $result ) { 240 255 return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); 241 256 } 257 258 $response = new WP_REST_Response(); 259 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 260 return $response; 242 261 } 243 262 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r39106 r39126 117 117 'args' => array( 118 118 'force' => array( 119 'type' => 'boolean', 119 120 'default' => false, 120 121 'description' => __( 'Required to be true, as resource does not support trashing.' ), … … 567 568 // We don't support trashing for this resource type. 568 569 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 ) ); 570 571 } 571 572 … … 574 575 $request->set_param( 'context', 'view' ); 575 576 576 $ response= $this->prepare_item_for_response( $term, $request );577 $previous = $this->prepare_item_for_response( $term, $request ); 577 578 578 579 $retval = wp_delete_term( $term->term_id, $term->taxonomy ); … … 581 582 return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) ); 582 583 } 584 585 $response = new WP_REST_Response(); 586 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 583 587 584 588 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r39106 r39126 86 86 'args' => array( 87 87 'force' => array( 88 'type' => 'boolean', 88 89 'default' => false, 89 90 'description' => __( 'Required to be true, as resource does not support trashing.' ), … … 115 116 'args' => array( 116 117 'force' => array( 118 'type' => 'boolean', 117 119 'default' => false, 118 120 'description' => __( 'Required to be true, as resource does not support trashing.' ), … … 654 656 // We don't support trashing for this type, error out. 655 657 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 ) ); 657 659 } 658 660 … … 671 673 $request->set_param( 'context', 'edit' ); 672 674 673 $ response= $this->prepare_item_for_response( $user, $request );675 $previous = $this->prepare_item_for_response( $user, $request ); 674 676 675 677 /** Include admin user functions to get access to wp_delete_user() */ … … 681 683 return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) ); 682 684 } 685 686 $response = new WP_REST_Response(); 687 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 683 688 684 689 /** -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r39104 r39126 731 731 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 732 732 733 $request->set_param( 'force', 'false' ); 734 $response = $this->server->dispatch( $request ); 735 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 736 733 737 // Ensure the post still exists 734 738 $post = get_post( $attachment_id ); -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r39105 r39126 726 726 $this->assertEquals( 200, $response->get_status() ); 727 727 $data = $response->get_data(); 728 $this->assertEquals( 'Deleted Category', $data['name'] ); 729 } 730 731 public function test_delete_item_force_false() { 728 $this->assertTrue( $data['deleted'] ); 729 $this->assertEquals( 'Deleted Category', $data['previous']['name'] ); 730 } 731 732 public function test_delete_item_no_trash() { 732 733 wp_set_current_user( self::$administrator ); 733 734 $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); 735 734 736 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); 735 // force defaults to false 736 $response = $this->server->dispatch( $request ); 737 $this->assertEquals( 501, $response->get_status() ); 737 $response = $this->server->dispatch( $request ); 738 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 739 740 $request->set_param( 'force', 'false' ); 741 $response = $this->server->dispatch( $request ); 742 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 738 743 } 739 744 -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39105 r39126 1889 1889 'user_id' => self::$subscriber_id, 1890 1890 )); 1891 1891 1892 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 1892 1893 $response = $this->server->dispatch( $request ); 1894 $this->assertEquals( 200, $response->get_status() ); 1895 $data = $response->get_data(); 1896 $this->assertEquals( self::$post_id, $data['post'] ); 1893 $request->set_param( 'force', 'false' ); 1894 $response = $this->server->dispatch( $request ); 1895 $this->assertEquals( 200, $response->get_status() ); 1896 1897 $data = $response->get_data(); 1898 $this->assertEquals( 'trash', $data['status'] ); 1897 1899 } 1898 1900 … … 1911 1913 $this->assertEquals( 200, $response->get_status() ); 1912 1914 $data = $response->get_data(); 1913 $this->assertEquals( self::$post_id, $data['post'] ); 1915 $this->assertTrue( $data['deleted'] ); 1916 $this->assertNotEmpty( $data['previous']['post'] ); 1914 1917 } 1915 1918 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r39108 r39126 2009 2009 2010 2010 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2011 $request->set_param( 'force', 'false' ); 2011 2012 $response = $this->server->dispatch( $request ); 2012 2013 … … 2015 2016 $data = $response->get_data(); 2016 2017 $this->assertEquals( 'Deleted post', $data['title']['raw'] ); 2018 $this->assertEquals( 'trash', $data['status'] ); 2017 2019 } 2018 2020 … … 2028 2030 $this->assertEquals( 200, $response->get_status() ); 2029 2031 $data = $response->get_data(); 2030 $this->assertEquals( 'Deleted post', $data['title']['raw'] ); 2032 $this->assertTrue( $data['deleted'] ); 2033 $this->assertNotEmpty( $data['previous'] ); 2031 2034 } 2032 2035 -
trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php
r38975 r39126 185 185 wp_set_current_user( self::$editor_id ); 186 186 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 187 $request->set_param( 'force', true ); 187 188 $response = $this->server->dispatch( $request ); 188 189 $this->assertEquals( 200, $response->get_status() ); 189 190 $this->assertNull( get_post( $this->revision_id1 ) ); 191 } 192 193 public function test_delete_item_no_trash() { 194 wp_set_current_user( self::$editor_id ); 195 196 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 197 $response = $this->server->dispatch( $request ); 198 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 199 200 $request->set_param( 'force', 'false' ); 201 $response = $this->server->dispatch( $request ); 202 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 203 204 // Ensure the revision still exists 205 $this->assertNotNull( get_post( $this->revision_id1 ) ); 190 206 } 191 207 -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r39105 r39126 626 626 $this->assertEquals( 200, $response->get_status() ); 627 627 $data = $response->get_data(); 628 $this->assertEquals( 'Deleted Tag', $data['name'] ); 629 } 630 631 public function test_delete_item_force_false() { 628 $this->assertTrue( $data['deleted'] ); 629 $this->assertEquals( 'Deleted Tag', $data['previous']['name'] ); 630 } 631 632 public function test_delete_item_no_trash() { 632 633 wp_set_current_user( self::$administrator ); 633 634 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 635 634 636 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 635 // force defaults to false 636 $response = $this->server->dispatch( $request ); 637 $this->assertEquals( 501, $response->get_status() ); 637 $response = $this->server->dispatch( $request ); 638 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 639 640 $request->set_param( 'force', 'false' ); 641 $response = $this->server->dispatch( $request ); 642 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 638 643 } 639 644 … … 668 673 $this->assertEquals( 200, $response->get_status() ); 669 674 $data = $response->get_data(); 670 $this->assertEquals( 'Deleted Tag', $data['name'] ); 675 $this->assertTrue( $data['deleted'] ); 676 $this->assertEquals( 'Deleted Tag', $data['previous']['name'] ); 671 677 } 672 678 -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r39105 r39126 1155 1155 $this->assertEquals( 200, $response->get_status() ); 1156 1156 $data = $response->get_data(); 1157 $this->assertEquals( 'Deleted User', $data['name'] ); 1157 $this->assertTrue( $data['deleted'] ); 1158 $this->assertEquals( 'Deleted User', $data['previous']['name'] ); 1159 } 1160 1161 public function test_delete_item_no_trash() { 1162 $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); 1163 1164 $this->allow_user_to_manage_multisite(); 1165 wp_set_current_user( self::$user ); 1166 1167 $userdata = get_userdata( $user_id ); // cache for later 1168 1169 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1170 $response = $this->server->dispatch( $request ); 1171 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1172 1173 $request->set_param( 'force', 'false' ); 1174 $response = $this->server->dispatch( $request ); 1175 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1176 1177 // Ensure the user still exists 1178 $user = get_user_by( 'id', $user_id ); 1179 $this->assertNotEmpty( $user ); 1158 1180 } 1159 1181 … … 1171 1193 $this->assertEquals( 200, $response->get_status() ); 1172 1194 $data = $response->get_data(); 1173 $this->assertEquals( 'Deleted User', $data['name'] ); 1174 } 1175 1176 public function test_delete_item_no_trash() { 1177 $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); 1178 1179 $this->allow_user_to_manage_multisite(); 1180 wp_set_current_user( self::$user ); 1181 1182 $userdata = get_userdata( $user_id ); // cache for later 1183 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1184 $response = $this->server->dispatch( $request ); 1185 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1186 1187 // Ensure the user still exists 1188 $user = get_user_by( 'id', $user_id ); 1189 $this->assertNotEmpty( $user ); 1195 $this->assertTrue( $data['deleted'] ); 1196 $this->assertEquals( 'Deleted User', $data['previous']['name'] ); 1190 1197 } 1191 1198 1192 1199 public function test_delete_current_item_no_trash() { 1193 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );1200 $user_id = $this->factory->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User' ) ); 1194 1201 1195 1202 wp_set_current_user( $user_id ); … … 1197 1204 update_site_option( 'site_admins', array( $user->user_login ) ); 1198 1205 1199 $userdata = get_userdata( $user_id ); // cache for later1200 1206 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1207 $response = $this->server->dispatch( $request ); 1208 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1209 1210 $request->set_param( 'force', 'false' ); 1201 1211 $response = $this->server->dispatch( $request ); 1202 1212 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
Note: See TracChangeset
for help on using the changeset viewer.