I am running into a problem in that I have users that can edit comments, but only those placed onto their own posts. Which is what I want. Unfortunately the edit-comments.php
page shows all comments. Is there a way to hide/remove the comments that the user can't manage anyway?
I tried:
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;
}
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'my_plugin_get_comment_list_by_user');
}
But this has no effect
post_author__in
, you don't need to mess with the raw SQL to do that when we already havepre_get_comments
andWP_Comment_Query
. It would also be much more afficient to move thecurrent_user_can
check into the function so that it isn't broken by being super early or modifications made to the user state. It would also be better to fetch the current user ID using the proper function rather than bypassing it and using a global variable developer.wordpress.org/reference/functions/get_current_user_id