Having trouble with how to filter the comment listing from WordPress back-end base on something else like user role?  Read this!

Sometime you might have custom role, let’s say co-editor, setup using members plugin in your WordPress.  And then you want to achieve  showing all comments only to the user who has administrator role but user with co-editor role sees only some of the comment.  You could use the below code to overcome this saturation.

function custom_comments_clauses( $pieces ) {
// check role here
if( is_admin() && (!current_user_can( 'administrator' ) ) && current_user_can( 'co_editor' ) ) {
// add your own query here
$pieces['where'] .= " AND comment_post_ID IN ( //add your own query here )";
}
return $pieces;
}

//plug to this filter
add_filter( 'comments_clauses', 'custom_comments_clauses', 10, 1 )

One thought on “[WordPress] Back-end Comment List Filtering

Leave a reply

required

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>