User levels and post visibility

I’m having a bit of trouble detecting the view-ability of post types. I’ve created a front end plugin which lists posts/pages by the author. Testing if a user can edit a certain post type is easy but I can’t figure out how to test if a user (taking their logged-in and role into account) can view another user’s posts. Here’s what I have:

$custom = get_post_types( array('_builtin' => false),'names');
foreach ( $custom as $type ) {
    $object = get_post_type_object($type);
    // TODO - is this check enough?
    if ( user_can($user,$object->cap->edit_posts) && current_user_can($object->cap->read_posts) )
        $types[] = array( 'title' => $object->labels->name, 'id' => $type );
}

Where $user is an author. The $object->cap->read_posts is not set so it always fails. This code should add a post type to an array if the author can create posts of that type and the user can read them. There are further privacy checks on a post by post basis later in the code, but that is not the issue here.

Read More

How can I solve this?

Please, no plugin recommendations.

Related posts