1

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');
}
2

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:

function add_theme_caps() {
        $role = get_role( 'author' ); // gets the author role
        $role->add_cap( 'moderate_comments' ); // would allow the author to moderate comments
}
add_action( 'admin_init', 'add_theme_caps');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.