Ticket #39000: 39000.2.diff
File 39000.2.diff, 4.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
92 92 'reassign' => array( 93 93 'type' => 'integer', 94 94 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), 95 'required' => true, 96 'sanitize_callback' => array( $this, 'check_reassign' ), 95 97 ), 96 98 ), 97 99 ), … … 125 127 'reassign' => array( 126 128 'type' => 'integer', 127 129 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), 130 'required' => true, 131 'sanitize_callback' => array( $this, 'check_reassign' ), 128 132 ), 129 133 ), 130 134 ), … … 133 137 } 134 138 135 139 /** 140 * Checks for a valid value for the reassign parameter when deleting users. 141 * 142 * @since 4.7.0 143 * 144 * @param $value 145 * @param $request 146 * @param $param 147 * 148 * @return int|bool|WP_Error 149 */ 150 public function check_reassign( $value, $request, $param ) { 151 if ( is_numeric( $value ) ) { 152 return $value; 153 } 154 155 if ( false === $value || 'false' === $value ) { 156 return false; 157 } 158 159 return new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); 160 } 161 162 /** 136 163 * Permissions check for getting all users. 137 164 * 138 165 * @since 4.7.0 … … 673 700 */ 674 701 public function delete_item( $request ) { 675 702 $id = (int) $request['id']; 676 $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null;703 $reassign = false === $request['reassign'] ? null : absint( $request['reassign'] ); 677 704 $force = isset( $request['force'] ) ? (bool) $request['force'] : false; 678 705 679 706 // We don't support trashing for users. -
tests/phpunit/tests/rest-api/rest-users-controller.php
1639 1639 1640 1640 $userdata = get_userdata( $user_id ); // cache for later 1641 1641 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1642 $request['force'] = true; 1642 $request->set_param( 'force', true ); 1643 $request->set_param( 'reassign', false ); 1643 1644 $response = $this->server->dispatch( $request ); 1644 1645 1645 1646 $this->assertEquals( 200, $response->get_status() ); … … 1657 1658 $userdata = get_userdata( $user_id ); // cache for later 1658 1659 1659 1660 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1661 $request->set_param( 'reassign', false ); 1660 1662 $response = $this->server->dispatch( $request ); 1661 1663 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1662 1664 … … 1678 1680 1679 1681 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1680 1682 $request['force'] = true; 1683 $request->set_param( 'reassign', false ); 1681 1684 $response = $this->server->dispatch( $request ); 1682 1685 1683 1686 $this->assertEquals( 200, $response->get_status() ); … … 1694 1697 update_site_option( 'site_admins', array( $user->user_login ) ); 1695 1698 1696 1699 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1700 $request->set_param( 'reassign', false ); 1697 1701 $response = $this->server->dispatch( $request ); 1698 1702 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1699 1703 … … 1714 1718 1715 1719 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1716 1720 $request['force'] = true; 1721 $request->set_param( 'reassign', false ); 1717 1722 $response = $this->server->dispatch( $request ); 1718 1723 1719 1724 $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 ); … … 1720 1725 1721 1726 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1722 1727 $request['force'] = true; 1728 $request->set_param( 'reassign', false ); 1723 1729 $response = $this->server->dispatch( $request ); 1724 1730 1725 1731 $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 ); … … 1731 1737 1732 1738 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/100' ); 1733 1739 $request['force'] = true; 1740 $request->set_param( 'reassign', false ); 1734 1741 $response = $this->server->dispatch( $request ); 1735 1742 1736 1743 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );