• Resolved adamhart

    (@adamhart)


    I have not found any posts newer than 4 years old on this subject, but I apologize if I missed any more recent ones.

    I would like to only allow Administrators (or any role higher than subscriber) to post comments. Subscribers would be able to read the comments, however they would not be able to respond.

    I have tried various Role Management plugins, but have not found any that specifically control who can post comments. I am trying to setup a web comic and would like only the comic authors (a.k.a. the three administrators) to be able to leave comments on the comic posts. We want to limit all discussions to a message board, which is why I don’t disable user registration.

    Currently running Comicpress 1.4.9.10
    I tried the “Role Scoper” and “Role Manager” plug ins, but the didn’t help.

    Thank you for any help you can give, I am at my wit’s end.

Viewing 15 replies - 1 through 15 (of 18 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    If your theme is calling the comment form like this in comments.php:

    <?php comment_form(); ?>

    You can change it to this so only admins can comment:

    <?php
    if(is_user_logged_in() && current_user_can('administrator')) {
      comment_form();
    }
    ?>

    or for all roles but subscribers:

    <?php
    if(is_user_logged_in() && !current_user_can('subscriber')) {
      comment_form();
    }
    ?>

    Thread Starter adamhart

    (@adamhart)

    That is amazing. Thank you. That worked beautifully. You are my hero of the week.

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. Glad you got it resolved.

    Is there a way to only allow original poster and admin to comment back and forth?

    Moderator keesiemeijer

    (@keesiemeijer)

    By “original poster” you mean the author of the post?

    yes

    To give you more information – I am starting a Question/Answer site where I charge for answers – its a consultation site. I dont want others to be able to answer the questions. Only me.

    Moderator keesiemeijer

    (@keesiemeijer)

    That certainly can be done. I don’t have time right now but I will look into it tomorrow. Or maybe someone else might want to chime in.

    great – I would appreciate any help – thank you very much!

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    <?php
    $current_user_id =  get_current_user_id();
    $author_id = get_the_author_meta( 'ID' );
    if(is_user_logged_in()) {
      if(current_user_can('administrator') || ($current_user_id == $author_id)) {
        comment_form();
      }
    }
    ?>

    Im sorry – Im so new to this – does that code go in the comment.php file? and do I have to erase anything and replace with this?

    Moderator keesiemeijer

    (@keesiemeijer)

    in your comments.php file replace this:

    comment_form();

    with this:

    $current_user_id =  get_current_user_id();
    $author_id = get_the_author_meta( 'ID' );
    if(is_user_logged_in()) {
      if(current_user_can('administrator') || ($current_user_id == $author_id)) {
        comment_form();
      }
    }

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Can you look at my code above and tell me where to replace? I dont see the exact place you have instructed me to do that.

    Thank you- Im sorry for the beginner questions.

    And could you also tell me how to remove the “this is the best answer” box ?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Only allow Admins to post comments’ is closed to new replies.