REST API: Add update and delete endpoints to /users/me
Now that /users/me is a standalone resource, it should have all the standard endpoints for a resource. Props pento. Fixes #38521 (hopefully). Built from https://develop.svn.wordpress.org/trunk@39092 git-svn-id: http://core.svn.wordpress.org/trunk@39034 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3fef086ede
commit
624def0ec3
|
@ -95,10 +95,30 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||||
) );
|
) );
|
||||||
|
|
||||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/me', array(
|
register_rest_route( $this->namespace, '/' . $this->rest_base . '/me', array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
array(
|
||||||
'callback' => array( $this, 'get_current_item' ),
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'args' => array(
|
'callback' => array( $this, 'get_current_item' ),
|
||||||
'context' => array(),
|
'args' => array(
|
||||||
|
'context' => array(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
|
'callback' => array( $this, 'update_current_item' ),
|
||||||
|
'permission_callback' => array( $this, 'update_current_item_permissions_check' ),
|
||||||
|
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::DELETABLE,
|
||||||
|
'callback' => array( $this, 'delete_current_item' ),
|
||||||
|
'permission_callback' => array( $this, 'delete_current_item_permissions_check' ),
|
||||||
|
'args' => array(
|
||||||
|
'force' => array(
|
||||||
|
'default' => false,
|
||||||
|
'description' => __( 'Required to be true, as resource does not support trashing.' ),
|
||||||
|
),
|
||||||
|
'reassign' => array(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'schema' => array( $this, 'get_public_item_schema' ),
|
'schema' => array( $this, 'get_public_item_schema' ),
|
||||||
));
|
));
|
||||||
|
@ -567,6 +587,36 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a given request has access to update the current user.
|
||||||
|
*
|
||||||
|
* @since 4.7.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Full details about the request.
|
||||||
|
* @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
|
||||||
|
*/
|
||||||
|
public function update_current_item_permissions_check( $request ) {
|
||||||
|
$request['id'] = get_current_user_id();
|
||||||
|
|
||||||
|
return $this->update_item_permissions_check( $request );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current user.
|
||||||
|
*
|
||||||
|
* @since 4.7.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Full details about the request.
|
||||||
|
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||||
|
*/
|
||||||
|
function update_current_item( $request ) {
|
||||||
|
$request['id'] = get_current_user_id();
|
||||||
|
|
||||||
|
return $this->update_item( $request );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given request has access delete a user.
|
* Checks if a given request has access delete a user.
|
||||||
*
|
*
|
||||||
|
@ -645,6 +695,36 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a given request has access to delete the current user.
|
||||||
|
*
|
||||||
|
* @since 4.7.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Full details about the request.
|
||||||
|
* @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
|
||||||
|
*/
|
||||||
|
public function delete_current_item_permissions_check( $request ) {
|
||||||
|
$request['id'] = get_current_user_id();
|
||||||
|
|
||||||
|
return $this->delete_item_permissions_check( $request );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the current user.
|
||||||
|
*
|
||||||
|
* @since 4.7.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Full details about the request.
|
||||||
|
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||||
|
*/
|
||||||
|
function delete_current_item( $request ) {
|
||||||
|
$request['id'] = get_current_user_id();
|
||||||
|
|
||||||
|
return $this->delete_item( $request );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares a single user output for response.
|
* Prepares a single user output for response.
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-beta1-39091';
|
$wp_version = '4.7-beta1-39092';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue