wp_trash_comment

Moves a comment to the Trash.

Description

wp_trash_comment( (int|WP_Comment) $comment_id ); 

If trash is disabled, comment is permanently deleted.

Parameters (1)

0. $comment_id (int|WP_Comment)
Comment ID or WP_Comment object.

Usage

  1. if ( !function_exists( 'wp_trash_comment' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Comment ID or WP_Comment object. 
  5. $comment_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_trash_comment($comment_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function wp_trash_comment($comment_id) { 
  2. if ( !EMPTY_TRASH_DAYS
  3. return wp_delete_comment($comment_id, true); 
  4.  
  5. if ( !$comment = get_comment($comment_id) ) 
  6. return false; 
  7.  
  8. /** 
  9. * Fires immediately before a comment is sent to the Trash. 
  10. * @since 2.9.0 
  11. * @param int $comment_id The comment ID. 
  12. */ 
  13. do_action( 'trash_comment', $comment->comment_ID ); 
  14.  
  15. if ( wp_set_comment_status( $comment, 'trash' ) ) { 
  16. delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); 
  17. delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); 
  18. add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); 
  19. add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); 
  20.  
  21. /** 
  22. * Fires immediately after a comment is sent to Trash. 
  23. * @since 2.9.0 
  24. * @param int $comment_id The comment ID. 
  25. */ 
  26. do_action( 'trashed_comment', $comment->comment_ID ); 
  27. return true; 
  28.  
  29. return false;