WC_REST_Authentication::check_permissions
Check that the API keys provided have the proper key-specific permissions to either read or write API resources.
Method of the class: WC_REST_Authentication{}
No Hooks.
Returns
true|false|WP_Error.
Usage
// private - for code of main (parent) class only $result = $this->check_permissions( $method );
- $method(string) (required)
- Request method.
WC_REST_Authentication::check_permissions() WC REST Authentication::check permissions code WC 10.8.1
private function check_permissions( $method ) {
$permissions = $this->user->permissions;
switch ( $method ) {
case 'HEAD':
case 'GET':
if ( 'read' !== $permissions && 'read_write' !== $permissions ) {
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have read permissions.', 'woocommerce' ), array( 'status' => 401 ) );
}
break;
case 'POST':
case 'PUT':
case 'PATCH':
case 'DELETE':
if ( 'write' !== $permissions && 'read_write' !== $permissions ) {
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have write permissions.', 'woocommerce' ), array( 'status' => 401 ) );
}
break;
case 'OPTIONS':
return true;
default:
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Unknown request method.', 'woocommerce' ), array( 'status' => 401 ) );
}
return true;
}