WP_REST_Users_Controller::update_item_permissions_check PHP Method

update_item_permissions_check() public method

Checks if a given request has access to update a user.
Since: 4.7.0
public update_item_permissions_check ( WP_REST_Request $request ) : true | WP_Error
$request WP_REST_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_item_permissions_check($request)
    {
        $id = (int) $request['id'];
        if (!current_user_can('edit_user', $id)) {
            return new WP_Error('rest_cannot_edit', __('Sorry, you are not allowed to edit this user.'), array('status' => rest_authorization_required_code()));
        }
        if (!empty($request['roles']) && !current_user_can('edit_users')) {
            return new WP_Error('rest_cannot_edit_roles', __('Sorry, you are not allowed to edit roles of this user.'), array('status' => rest_authorization_required_code()));
        }
        return true;
    }