Hold comments for moderation only if user is not logged in

Is there any way to allow logged-in users to post comments without them being held for moderation, while requiring that any comment from anonymous users be approved? I have developed a system for users who are members of our organization to log in automatically with their LDAP accounts, and would like for any of them to be able to comment without their comments being held for moderation. However, I want all anonymous third-party comments to be held for moderation. I don’t see any way to do that with the current comment options – I can either hold all comments for moderation, hold all comments by users without 2 approved comments, or require users to log in to comment. How can I achieve this?

Related posts

Leave a Reply

1 comment

  1. Here you go, paste this code in your themes functions.php file:

    function loggedin_approved_comment($approved)
    {
        // No need to do the check if the comment is already approved anyway.
        if (!$approved) {
            if (is_user_logged_in()) {
                // Note: 1/0, not true/false
                $approved = 1;
            }
        }
    
        return $approved;
    }
    
    // Action allows the comment automatic approval to be over-ridden.
    add_action('pre_comment_approved', 'loggedin_approved_comment');
    

    Make sure to enable Comment Moderation inside the Settings-panel of your WordPress install.