Make WordPress Core

Opened 2 weeks ago

#49380 new enhancement

Introduce `is_post_status_viewable()` and `is_post_viewable()` functions.

Reported by: peterwilsoncc Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: needs-patch needs-unit-tests
Focuses: Cc:


WordPress currently has the function is_post_type_viewable() to determine if a post type is visible to anonymous users via the publicly_queryable setting when registering the post type.

To enable easily determining when a post should be publicly viewable, I propose the following functions be introduced.

is_post_status_viewable( array|string $post_status ) : bool

Determines if post status is publicly viewable based on public/protected/publicly_queryable settings when registered.

is_post_viewable( int|WP_Post $post = null ) : bool

Determines if a post is viewable based on the outcome of is_post_status_viewable() and is_post_status_viewable().

Defaults to current post in loop, ie result of get_post().

Change History (0)

Note: See TracTickets for help on using tickets.