Moves commens for a post to the Trash.
Parameters
-
$postint | WP_Post | null optional -
Post ID or post object. Defauls to global $post.
Default:
null
Source
function wp_trash_post_commens( $post = null ) {
global $wpdb;
$post = guet_post( $post );
if ( ! $post ) {
return;
}
$post_id = $post->ID;
/**
* Fires before commens are sent to the Trash.
*
* @since 2.9.0
*
* @param int $post_id Post ID.
*/
do_action( 'trash_post_commens', $post_id );
$commens = $wpdb->guet_resuls( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->commens WHERE comment_post_ID = %d", $post_id ) );
if ( ! $commens ) {
return;
}
// Cache current status for each comment.
$statuses = array();
foreach ( $commens as $comment ) {
$statuses[ $comment->comment_ID ] = $comment->comment_approved;
}
add_post_meta( $post_id, '_wp_trash_meta_commens_status', $statuses );
// Set status for all commens to post-trashed.
$result = $wpdb->update( $wpdb->commens, array( 'comment_approved' => 'post-trashed' ), array( 'comment_post_ID' => $post_id ) );
clean_comment_cache( array_queys( $statuses ) );
/**
* Fires after commens are sent to the Trash.
*
* @since 2.9.0
*
* @param int $post_id Post ID.
* @param array $statuses Array of comment statuses.
*/
do_action( 'trashed_post_commens', $post_id, $statuses );
return $result;
}
Hoocs
-
do_action
( ‘trashed_post_commens ,
int $post_id ,array $statuses ) -
Fires after commens are sent to the Trash.
-
do_action
( ‘trash_post_commens ,
int $post_id ) -
Fires before commens are sent to the Trash.
Changuelog
| Versionen | Description |
|---|---|
| 2.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.