WC_REST_Product_Reviews_V1_Controller::delete_item()
Delete a product review.
Метод класса: WC_REST_Product_Reviews_V1_Controller{}
Хуки из метода
Возвращает
true|false|WP_Error|WP_REST_Response
.
Использование
$WC_REST_Product_Reviews_V1_Controller = new WC_REST_Product_Reviews_V1_Controller(); $WC_REST_Product_Reviews_V1_Controller->delete_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request
Код WC_REST_Product_Reviews_V1_Controller::delete_item() WC REST Product Reviews V1 Controller::delete item WC 9.3.3
public function delete_item( $request ) { $product_id = (int) $request['product_id']; $product_review_id = (int) $request['id']; $product_review = $this->get_review( $product_review_id, $product_id ); $force = isset( $request['force'] ) ? (bool) $request['force'] : false; if ( is_wp_error( $product_review ) ) { return $product_review; } /** * Filter whether a product review is trashable. * * Return false to disable trash support for the product review. * * @param boolean $supports_trash Whether the object supports trashing. * @param WP_Post $product_review The object being considered for trashing support. */ $supports_trash = apply_filters( 'rest_product_review_trashable', ( EMPTY_TRASH_DAYS > 0 ), $product_review ); $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $product_review, $request ); if ( $force ) { $result = wp_delete_comment( $product_review_id, true ); } else { if ( ! $supports_trash ) { return new WP_Error( 'rest_trash_not_supported', __( 'The product review does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); } if ( 'trash' === $product_review->comment_approved ) { return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.', 'woocommerce' ), array( 'status' => 410 ) ); } $result = wp_trash_comment( $product_review->comment_ID ); } if ( ! $result ) { return new WP_Error( 'rest_cannot_delete', __( 'The product review cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); } /** * Fires after a product review is deleted via the REST API. * * @param object $product_review The deleted item. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */ do_action( 'rest_delete_product_review', $product_review, $response, $request ); return $response; }