Make WordPress Core

Opened 9 months ago

Closed 3 months ago

#49380 closed enhancement (wontfix)

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

Reported by: peterwilsoncc Owned by: peterwilsoncc
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
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 (10)

#2 @SergeyBiryukov
7 months ago

  • Description modified (diff)

#3 @prbot
7 months ago

whyisjake commented on PR #217:


#4 @whyisjake
7 months 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
7 months ago

The PR looks good to me.

#6 @whyisjake
6 months ago

  • Keywords commit added

#7 @peterwilsoncc
6 months 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
5 months 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.

#9 @peterwilsoncc
3 months ago

  • Keywords close removed
  • Milestone Future Release deleted

@SergeyBiryukov @whyisjake

Closing this off as post_status is not publicly queryable (it's in WP::$private_query_vars rather than $public_query_vars).

This can probably be dealt with if Post Statuses move beyond the simple standard class.

#10 @peterwilsoncc
3 months ago

  • Resolution set to wontfix
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.