untrashed_comment
Fires immediately after a comment is restored from the Trash.
wp_set_comment_status() restores the comment with the status it had before deletion. The _wp_trash_meta_time and _wp_trash_meta_status meta-fields, which stored the date the comment was trashed and its status, are also deleted.
Usage
add_action( 'untrashed_comment', 'wp_kama_untrashed_comment_action', 10, 2 );
/**
* Function for `untrashed_comment` action-hook.
*
* @param string $comment_id The comment ID as a numeric string.
* @param WP_Comment $comment The untrashed comment.
*
* @return void
*/
function wp_kama_untrashed_comment_action( $comment_id, $comment ){
// action...
}
- $comment_id(int)
- The comment ID.
- $comment(WP_Comment)
- The comment object restored from the Trash.
Examples
#1 Send an email to the author of a comment restored from the Trash
add_action( 'trashed_comment', 'send_email_commentator_after_untrashed' );
function send_email_commentator_after_untrashed( $comment_id ) {
$email = get_comment_author_email( $comment_id );
$subject = 'Your comment has been restored';
$message = 'Hooray, your comment has been restored from 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
untrashed_comment
wp-includes/comment.php 1773
do_action( 'untrashed_comment', $comment->comment_ID, $comment );