WC_REST_Webhooks_V1_Controller::delete_item()
Delete a single webhook.
Метод класса: WC_REST_Webhooks_V1_Controller{}
Хуки из метода
Возвращает
WP_REST_Response|WP_Error
.
Использование
$WC_REST_Webhooks_V1_Controller = new WC_REST_Webhooks_V1_Controller(); $WC_REST_Webhooks_V1_Controller->delete_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_Webhooks_V1_Controller::delete_item() WC REST Webhooks V1 Controller::delete item WC 9.2.3
public function delete_item( $request ) { $id = (int) $request['id']; $force = isset( $request['force'] ) ? (bool) $request['force'] : false; // We don't support trashing for this type, error out. if ( ! $force ) { return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); } $webhook = wc_get_webhook( $id ); if ( empty( $webhook ) || is_null( $webhook ) ) { return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $webhook, $request ); $result = $webhook->delete( true ); if ( ! $result ) { /* translators: %s: post type */ return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) ); } /** * Fires after a single item is deleted or trashed via the REST API. * * @param WC_Webhook $webhook The deleted or trashed item. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_webhook_object', $webhook, $response, $request ); return $response; }