I am trying to make things work like where author can see only them post comment in admin comment section and they can moderate as well. While admin should have all permission.
I am having one code and working fine in all terms like showing only author’s post comment but it’s not allowing to moderate. Can anyone help me to find solution where author can moderate own post comment.
Code I have:
function my_plugin_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;
};
// Ensure that editors and admins can moderate all comments
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'my_plugin_get_comment_list_by_user');
}
The default author role does not have the
moderate_comments
capabilities so you need to add that capability to the author role, so add this to your plugin: