read_post meta capability for anonymous users

read_post is a meta capability that can be used to check if a user can read a post. It can be used, for example, like this:

if ( current_user_can(‘read_post’, $post_ID) ) {
// do something

No role has this capability. It will be mapped to read_posts, read_private_posts or even other set of native capabilites depending on the context. Is current user the author of this post? Is this post private? What is the post status? It will do all verifications, even if the post has a custom post status.

Apparently, this type of verification, using this meta_cap, will only work when checking upon a specific user.

What about anonymous user?

Is there a way to use something similar to current_user_can(‘read_post’, $post_ID) that will work when there is no current user?

Of course I could do all the checking myself. Is the post public or not? and so on. But my question is, is there a way to do so whithout having to repeat all the logic that the map_meta_cap filter for read_post already implements so well?

Am I missing something?

Read more here:: read_post meta capability for anonymous users

Leave a Reply

Your email address will not be published. Required fields are marked *