WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Only allow Admins to post comments (19 posts)

  1. adamhart
    Member
    Posted 2 years ago #

    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.

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    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();
    }
    ?>
  3. adamhart
    Member
    Posted 2 years ago #

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

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    You're welcome. Glad you got it resolved.

  5. clauduke
    Member
    Posted 2 years ago #

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

  6. keesiemeijer
    moderator
    Posted 2 years ago #

    By "original poster" you mean the author of the post?

  7. clauduke
    Member
    Posted 2 years ago #

    yes

  8. clauduke
    Member
    Posted 2 years ago #

    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.

  9. keesiemeijer
    moderator
    Posted 2 years ago #

    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.

  10. clauduke
    Member
    Posted 2 years ago #

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

  11. keesiemeijer
    moderator
    Posted 2 years ago #

    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();
      }
    }
    ?>
  12. clauduke
    Member
    Posted 2 years ago #

    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?

  13. keesiemeijer
    moderator
    Posted 2 years ago #

    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();
      }
    }
  14. clauduke
    Member
    Posted 2 years ago #

    [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]

  15. clauduke
    Member
    Posted 2 years ago #

    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.

  16. clauduke
    Member
    Posted 2 years ago #

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

  17. keesiemeijer
    moderator
    Posted 2 years ago #

    Can you paste and submit the full code of comment.php into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

  18. clauduke
    Member
    Posted 2 years ago #

    http://pastebin.com/Qk6tHfNq

    Can you let me know if this worked ?

  19. clauduke
    Member
    Posted 2 years ago #

    Hello were you able to view the code?

Topic Closed

This topic has been closed to new replies.

About this Topic