Comments: Approve when admin Replies, from the Front end

Thank you for reading,

In the admin panel, when a comment is awaiting moderation, you can “Approve and Reply” in the same action.

However, in the front end, if you show the awaiting comments to the admin, and she hits Reply, the comment wont approve.

Does anybody know how to get the proper link, or where modify the code, to auto-approve comments when the admin replies ?

Why: I’m creating the site for a client, and trying to make it as easy as posible so she won’t need to learn WP’s admin panel.

1 Answer
1

Well… All you have to do is to check what hooks are available during comment posting.

The one I think might be helpful is wp_insert_comment. So you could do something like this:

function my_wp_insert_comment($id, $comment) {
    if ( is_admin() && $comment->comment_parent ) {
        if ( wp_get_comment_status( $comment->comment_parent ) == 'unapproved' )
            wp_set_comment_status( $comment->comment_parent, 'approve' );
    }
}
add_action('wp_insert_comment', 'my_wp_insert_comment', 10, 2);

Just place this code in function.php file of your theme. This function will be called every time a comment is inserted into database. No matter how (from admin area, front end or by some plugin, etc.)

Leave a Comment