WordPress Authors and Comments on Their Posts

Comments Authors

We had a question this week from a PublishPress customer who wanted to understand the relationship between authors and their WordPress posts. They wanted to know if authors could see – or perhaps even manage – comments on other people's posts.

This tutorial is a guide to understanding the control that users have over comments on posts they have written. You can also follow this link if you want a guide to moderating comments in WordPress.


The Default Behavior for Authors and Comments

To show how WordPress works, I've set up a test site with three posts. One of them is my post, as I'm using the “author” account. This user is in the “Author” user role. The other posts were written by different users. Each post has one comment.

My Post
My Post

When I login as the author, I can go to the “Comments” area of WordPress and see all the comments, even for posts I haven't written.

Comments All
Comments All

However, there is one important difference for comments on my post. I can moderate comments on my post using these links: Unapprove / Reply / Quick Edit / Edit / Spam / Trash.

Comments Interacting
Comments Interacting

These settings will change depending on the user role:

  • Subscriber: A user in this role can not see or moderate any comments.
  • Contributor: A user in this role can see all comments, but can not moderate any comments.
  • Author: A user in this role can see all comments, but only moderate comments on their posts.
  • Editor: A user in this role can see and moderate all comments.
  • Administrator: A user in this role can see and moderate all comments.

How to Control Access to Comments

If you want to decide who can view and moderate comments, you need the PublishPress Capabilities plugin.

On the “Capabilities” screen, you can see the three capabilities that control comments:

  • edit_posts: This controls access to the “Comments” screen.
  • moderate_comments: This controls access to Unapprove / Reply / Quick Edit etc
  • edit_others_posts: This controls access to Unapprove / Reply / Quick Edit etc on posts that are not yours.
Comment Capabilities
Comment Capabilities

How to Hide Comments from Other Posts

If you want to hide comments on posts that the author didn't write, you can add this code to your theme's functions.php file:

function my_plugin_get_comment_list_by_user($clauses) {
        if (is_admin()) {
                global $user_ID, $wpdb;
                $clauses['join'] = ", ".$wpdb->base_prefix."posts";
                $clauses['where'] .= " AND ".$wpdb->base_prefix."posts.post_author = ".$user_ID." AND ".$wpdb->base_prefix."comments.comment_post_ID = ".$wpdb->base_prefix."posts.ID";
        };
        return $clauses;
};

You can also extend this code so that Administrators and Editors (anyone with the edit_others_posts) capability can still see all the comments.

if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'my_plugin_get_comment_list_by_user');
}

This image below shows how the Comments screen looks after this final change. The only flaw is that the number 3 does appear in the counters at the top of the screen. However, it's not possible to see the comments for anyone else's posts.

My Comments Only
My Comments Only

Tags: Administrator Role, Author Role, Contributor Role, Editor Role, Quick Edit, Subscriber Role, WordPress Authors, WordPress Comments


Leave a Reply

Your email address will not be published. Required fields are marked *

Professional publishing plugins for WordPress! Get PublishPress

  • SUBSCRIBE TO OUR NEWSLETTER
  • SEARCH THIS SITE