WC_REST_Products_V1_Controller::delete_post
Delete post.
Метод класса: WC_REST_Products_V1_Controller{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->delete_post( $id );
- $id(int|WP_Post) (обязательный)
- Post ID or WP_Post instance.
Код WC_REST_Products_V1_Controller::delete_post() WC REST Products V1 Controller::delete post WC 10.7.0
protected function delete_post( $id ) {
if ( ! empty( $id->ID ) ) {
$id = $id->ID;
} elseif ( ! is_numeric( $id ) || 0 >= $id ) {
return;
}
// Delete product attachments.
$attachments = get_posts( array(
'post_parent' => $id,
'post_status' => 'any',
'post_type' => 'attachment',
) );
foreach ( (array) $attachments as $attachment ) {
wp_delete_attachment( $attachment->ID, true );
}
// Delete product.
$product = wc_get_product( $id );
$product->delete( true );
}