WC_REST_Customers_V1_Controller::delete_item_permissions_check
Check if a given request has access delete a customer.
Method of the class: WC_REST_Customers_V1_Controller{}
No Hooks.
Returns
true|false|WP_Error.
Usage
$WC_REST_Customers_V1_Controller = new WC_REST_Customers_V1_Controller(); $WC_REST_Customers_V1_Controller->delete_item_permissions_check( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
WC_REST_Customers_V1_Controller::delete_item_permissions_check() WC REST Customers V1 Controller::delete item permissions check code WC 10.4.3
public function delete_item_permissions_check( $request ) {
$permission_result = $this->permissions_check(
$request,
'delete',
new WP_Error(
'woocommerce_rest_cannot_delete',
__( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ),
array( 'status' => rest_authorization_required_code() )
)
);
if ( ! $permission_result || is_wp_error( $permission_result ) ) {
return $permission_result;
}
$id = (int) $request['id'];
$allowed_roles = $this->allowed_roles();
$customer = new WC_Customer( $id );
if ( ! in_array( $customer->get_role(), $allowed_roles, true ) ) {
return new WP_Error(
'woocommerce_rest_cannot_delete',
sprintf(
/* translators: 1: Role of the user (administrator, customer), 2: comma separated list of allowed roles. egs customer, subscriber */
__( 'Sorry, users with %1$s role cannot be deleted via this endpoint. Allowed roles: %2$s', 'woocommerce' ),
$customer->get_role(),
implode( ', ', $allowed_roles )
),
array( 'status' => rest_authorization_required_code() )
);
}
return true;
}