Limit Comments moderation, part 2

Limit comments moderation part 2

Limit comments moderation 2

We have discussed couple of tricks to limit comments moderation in this post already and know how to hide comments moderation links and commands from user. In this post we will see:
– how to show comments to the user with ‘Author’ role from his posts only;
– how to exclude unneeded views from ‘Comments’ page, left just ‘Approved’ for example.
Try this code, adding it to your blog theme functions.php file:

if (current_user_can('author')) {  // for users with Author role only
  function limit_comments_for_user($query) {
 
    global $current_user;
 
    $query->query_vars['status'] = 'approve';  // show 'Approved' comments only
    $query->query_vars['post_author'] = $current_user->ID;  // show comments from this author posts only
  }
 
  function limit_comment_statuses($status_links) {  // hide all comments views except Approved one
 
    unset($status_links['all']);
    unset($status_links['moderated']);
    unset($status_links['spam']);
    unset($status_links['trash']);
 
    return $status_links;
  }
 
  add_filter('comment_status_links', 'limit_comment_statuses');
  add_action('pre_get_comments', 'limit_comments_for_user');
}

Tags: , ,