最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Hold comments for moderation only if user is not logged in

programmeradmin3浏览0评论

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?

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?

Share Improve this question asked Feb 4, 2011 at 8:04 nhinklenhinkle 1451 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

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.

发布评论

评论列表(0)

  1. 暂无评论