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.
Return
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 9.7.1
public function delete_item_permissions_check( $request ) { $id = (int) $request['id']; if ( ! wc_rest_check_user_permissions( 'delete', $id ) ) { return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); } $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; }