Sorry for the confusion. Yes, contributors can view other people’s draft posts; however, they can only see the titles, not the content. This is expected behavior.
Unfortunately, there is no quick and easy fix for this.
The solution below appears to restrict contributors from viewing other users’ posts (they can only see their own posts in the admin area), but it doesn’t always work correctly, as it sometimes shows an incorrect post count in the admin panel.
// Restrict contributors to only view and edit their own posts
function restrict_contributor_posts( $query ) {
if ( ! is_admin() || ! $query->is_main_query() || ! current_user_can( 'contributor' ) ) {
return;
}
global $pagenow;
// Restrict contributors to only see their own posts in the post list
if ( $pagenow == 'edit.php' ) {
$query->set( 'author', get_current_user_id() );
}
}
add_action( 'pre_get_posts', 'restrict_contributor_posts' );
I’ve packaged it into a WordPress plugin so that you can install and try it. However, I bear no responsibility for its use (please proceed at your own risk): https://filebin.net/pq95kjuy25r1boop
-
This reply was modified 3 months ago by
Anton Vlasenko. Reason: improved code