Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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