trashed_comment
Fires immediately after a comment is moved to the Trash.
If you need to do something when a comment is deleted from the database, use the deleted_comment hook.
Usage
add_action( 'trashed_comment', 'wp_kama_trashed_comment_action', 10, 2 );
/**
* Function for `trashed_comment` action-hook.
*
* @param string $comment_id The comment ID as a numeric string.
* @param WP_Comment $comment The trashed comment.
*
* @return void
*/
function wp_kama_trashed_comment_action( $comment_id, $comment ){
// action...
}
- $comment_id(int)
- The comment ID.
- $comment(WP_Comment)
- The trashed comment object.
Examples
#1 Send an email to the author of a trashed comment
add_action( 'trashed_comment', 'send_email_commentator_after_trashed' );
function send_email_commentator_after_trashed( $comment_id ) {
$email = get_comment_author_email( $comment_id );
$subject = 'Your comment was moved to the Trash';
$message = 'For some reason, your comment was moved to the Trash.';
wp_mail( $email, $subject, $message );
}Changelog
| Since 2.9.0 | Introduced. |
| Since 4.9.0 | Added the $comment parameter. |
Where the hook is called
trashed_comment
wp-includes/comment.php 1703
do_action( 'trashed_comment', $comment->comment_ID, $comment );