How to make a post visible to only:
-
The post author, irrespective of its user role.
-
All users from a specific user role.
Other then these, no one should be able to see the post.
How should I approach this.
Note that I have only three user roles in WP. Admin, and 2 other custom roles.
Give your custom roles the capability to “read_member_posts” or whatever. Then you could apply a filter to the_content()
add_filter( 'the_content', 'my_wpse20347_filter' );
function my_wpse20347_filter( $content )
{
global $post;
if( author_can( $post->ID, 'edit_posts' ) || current_user_can( 'read_member_posts' ) )
{
return $content;
}
else
{ // Everyone else sees this in place of the content.
return '<p>Only members may view this post</p>';
}
}