How can I check if a visitor can read a post?

I know how to check capabilities for logged in users, with

$can_read = current_user_can('read',$post-ID);

But the above code returnes false when the user is not logged. So how can I check if the visitor has access to it?

Thanks!

Topic user-roles capabilities logging Wordpress

Category Web


Vistors usually always have the rights to access a post. Only exceptions that I know are drafts, password protected posts or post_types that are not public accessable.

You could use get_post_status() and post_password_required()

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.