• Hi

    I have a school blog running at the moment and thought that I have set it up so that every post and every comment gets moderated by an administrator before it appears. I realise that administrator comments and posts do no need moderation. Students share the same logon for a particular class. All students are set with the contributor role.

    The query I have is with regards to comments. If a contributor writes a comment on a different contributor’s post, it will require moderation as expected.

    However, if a contributor posts a comment on their own post, it doesn’t require moderation. This is potentially dangerous for me as this is a common thing that can happen, so the blog is open to abuse.

    I have the check box ‘An administrator must always approve the comment ‘ in the Discussion settings of the site. This does not appear to work when a contributor comments on their own post.

    I’m wondering if there is a way around this? Thanks for any suggestions in advance.

    Mike

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can add a filter to set the approval or moderation of comments. Here is a sample:

    function set_comment_approval($approved,$commentdata) {
       if (current_user_can('administrator')) {
          return $approved;
       }
       return 0;  // Hold for moderation
    }
    add_filter('pre_comment_approved','set_comment_approval',2);

    This function will set all comments to be held for moderation unless the current user is an admin.

    EDIT: It would probably be wise to check $approved for a value of 1 (approved) and only return 0 if the comment is otherwise approved (UNTESTED).

    function set_comment_approval($approved,$commentdata) {
       if (current_user_can('administrator')) {
          return $approved;
       }
       if ($approved == 1) {
          return 0;  // Hold for moderation
       }
       return $approved;
    }
    add_filter('pre_comment_approved','set_comment_approval',2);
    Thread Starter mikeazzo

    (@mikeazzo)

    Thanks for the response. I’ve tried both sets of code and while the functionality works great, there is an error displayed on the screen after posting a comment:

    Warning: Missing argument 2 for set_comment_approval() in e:\inetpub\vhosts\newburypark.redbridge.sch.uk\httpdocs\Blog\wp-content\themes\retromania\functions.php on line 14

    Warning: Cannot modify header information – headers already sent by (output started at e:\inetpub\vhosts\newburypark.redbridge.sch.uk\httpdocs\Blog\wp-content\themes\retromania\functions.php:14) in e:\inetpub\vhosts\newburypark.redbridge.sch.uk\httpdocs\Blog\wp-includes\pluggable.php on line 886

    The comment will still work and requires moderation.

    Thank you

    Not sure why I didn’t get that error – possibly a different version of WP.

    In any case, please try this:

    function set_comment_approval($approved) {
       if (current_user_can('administrator')) {
          return $approved;
       }
       if ($approved == 1) {
          return 0;  // Hold for moderation
       }
       return $approved;
    }
    add_filter('pre_comment_approved','set_comment_approval');
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Question regarding Moderation of Comments’ is closed to new replies.