The is_post_status_viewable WordPress PHP Filter determines if a post status is considered “viewable”.
Usage
add_filter('is_post_status_viewable', 'your_custom_function', 10, 2); function your_custom_function($is_viewable, $post_status) { // your custom code here return $is_viewable; }
Parameters
- $is_viewable (bool): Whether the post status is “viewable” (strict type).
- $post_status (stdClass): Post status object.
More information
See WordPress Developer Resources: is_post_status_viewable
Examples
Make private posts viewable
Make private posts viewable to logged-in users.
add_filter('is_post_status_viewable', 'make_private_posts_viewable', 10, 2); function make_private_posts_viewable($is_viewable, $post_status) { if ($post_status->name === 'private' && is_user_logged_in()) { return true; } return $is_viewable; }
Make draft posts viewable for admins
Allow administrators to view draft posts.
add_filter('is_post_status_viewable', 'make_draft_posts_viewable_for_admins', 10, 2); function make_draft_posts_viewable_for_admins($is_viewable, $post_status) { if ($post_status->name === 'draft' && current_user_can('administrator')) { return true; } return $is_viewable; }
Block all viewable statuses
Block all post statuses from being viewable.
add_filter('is_post_status_viewable', 'block_all_viewable_statuses', 10, 2); function block_all_viewable_statuses($is_viewable, $post_status) { return false; }
Make custom post status viewable
Make a custom post status ‘approved’ viewable.
add_filter('is_post_status_viewable', 'make_approved_posts_viewable', 10, 2); function make_approved_posts_viewable($is_viewable, $post_status) { if ($post_status->name === 'approved') { return true; } return $is_viewable; }
Make future posts viewable for editors
Allow editors to view future posts.
add_filter('is_post_status_viewable', 'make_future_posts_viewable_for_editors', 10, 2); function make_future_posts_viewable_for_editors($is_viewable, $post_status) { if ($post_status->name === 'future' && current_user_can('editor')) { return true; } return $is_viewable; }