Using WordPress ‘comment_reply_to_unapproved_comment’ PHP action

The comment_reply_to_unapproved_comment WordPress action fires when a comment reply is attempted to an unapproved comment.

Usage

add_action('comment_reply_to_unapproved_comment', 'your_custom_function', 10, 2);

function your_custom_function($comment_post_id, $comment_parent) {
    // your custom code here
}

Parameters

  • $comment_post_id (int) – Post ID.
  • $comment_parent (int) – Parent comment ID.

More information

See WordPress Developer Resources: comment_reply_to_unapproved_comment

Examples

Notify admin about a reply to an unapproved comment

Send an email to the administrator when someone replies to an unapproved comment.

function notify_admin_unapproved_comment_reply($comment_post_id, $comment_parent) {
    $admin_email = get_option('admin_email');
    $subject = 'Reply to Unapproved Comment';
    $message = 'A reply was made to an unapproved comment on post ID ' . $comment_post_id . '. Parent comment ID is ' . $comment_parent . '.';
    wp_mail($admin_email, $subject, $message);
}

add_action('comment_reply_to_unapproved_comment', 'notify_admin_unapproved_comment_reply', 10, 2);

Prevent replies to unapproved comments

Disallow users from replying to unapproved comments by redirecting them to a custom page.

function prevent_reply_to_unapproved_comment($comment_post_id, $comment_parent) {
    wp_redirect(home_url('/no-reply-allowed/'));
    exit;
}

add_action('comment_reply_to_unapproved_comment', 'prevent_reply_to_unapproved_comment', 10, 2);