WordPress Snippets at WPcustoms

List Comments for the author’s own posts only

Encourage your site’s author to take care of their own post’s comments. If Jane publishes a post, she will only see the comments to her posts in the admin panel.


/**
 * Snippet Name: List Comments for the author’s own posts only
 * Snippet URL: https://wpcustoms.net/snippets/list-comments-for-the-authors-own-posts-only/
 */
  function wpc_get_comment_list_by_user($clauses) {
        if (is_admin()) {
                global $user_ID, $wpdb;
                $clauses['join'] = ", wp_posts";
                $clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID";
        };
        return $clauses;
};
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'wpc_get_comment_list_by_user');
}