
Limit comments moderation 2
– 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');
}
