WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 7 days ago

#49380 assigned enhancement

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

Reported by: peterwilsoncc Owned by: peterwilsoncc
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: close
Focuses: Cc:

Description (last modified by SergeyBiryukov)

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_type_viewable() and is_post_status_viewable().

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

Change History (8)

#2 @SergeyBiryukov
7 weeks ago

  • Description modified (diff)

#3 @prbot
7 weeks ago

whyisjake commented on PR #217:

Words.

#4 @whyisjake
6 weeks ago

  • Keywords has-unit-tests has-patch added; needs-patch needs-unit-tests removed
  • Milestone changed from Awaiting Review to 5.5
  • Owner set to whyisjake
  • Status changed from new to accepted

I like the direction here!

#5 @SergeyBiryukov
6 weeks ago

The PR looks good to me.

#6 @whyisjake
5 weeks ago

  • Keywords commit added

#7 @peterwilsoncc
13 days ago

Need to review this further, as "viewable" actually refers to publicly queryable, as opposed to public, I just need to double check is_post_viewable() makes sense.

I think is_*_public() functions would also make sense but that can be another ticket for another day.

#8 @peterwilsoncc
7 days ago

  • Keywords close added; has-unit-tests has-patch commit removed
  • Milestone changed from 5.5 to Future Release
  • Owner changed from whyisjake to peterwilsoncc
  • Status changed from accepted to assigned

Reviewing WP::parse_query, it doesn't look like the post status object's publicly_queryable property is used anywhere.

Removing from milestone and the commit keyword as a result. I'll close it once I've got clarification.

Note: See TracTickets for help on using tickets.