deleted_commentaction-hookWP 2.9.0

Fires immediately after a comment is deleted from the database (before the cache is cleared).

After the hook fires, wp_delete_comment() performs the following actions:

The hook fires only when deleting from the Trash (permanent deletion). If a comment is first moved to the Trash, this hook will not fire! The similar trashed_comment hook fires when a comment is moved to the Trash.

Usage

add_action( 'deleted_comment', 'wp_kama_deleted_comment_action', 10, 2 );

/**
 * Function for `deleted_comment` action-hook.
 * 
 * @param string     $comment_id The comment ID as a numeric string.
 * @param WP_Comment $comment    The deleted comment.
 *
 * @return void
 */
function wp_kama_deleted_comment_action( $comment_id, $comment ){

	// action...
}
$comment_id(int)
The comment ID.
$comment(WP_Comment)
The deleted comment object.

Examples

#1 Send an email to the author of a deleted comment

add_action( 'deleted_comment', 'send_email_commentator_after_deletion' );

function send_email_commentator_after_deletion( $comment_id ) {
	$email   = get_comment_author_email( $comment_id );
	$subject = 'Your comment was deleted';
	$message = 'For some reason, your comment was deleted.';

	wp_mail( $email, $subject, $message );
}

Changelog

Since 2.9.0 Introduced.
Since 4.9.0 Added the $comment parameter.

Where the hook is called

wp_delete_comment()
deleted_comment
wp-includes/comment.php 1615
do_action( 'deleted_comment', $comment->comment_ID, $comment );

Where the hook is used in WordPress

Usage not found.