Make WordPress Core

Opened 19 months ago

Last modified 2 days ago

#49628 reviewing feature request

Add is_post_type_viewable filter

Reported by: powerbuoy Owned by: SergeyBiryukov
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.3.2
Component: Posts, Post Types Keywords: has-patch needs-dev-note
Focuses: administration Cc:


It would be great if we could hook into is_post_type_viewable() and override the check.

We've created a new config for post types; has_single, which works very much like has_archive only it disables single pages for a post-type (useful for post-types such as office or employee which usually in our cases only have archive pages).

However, even though the post-type shows a 404 on single (using template_redirect), inside the admin the "View"-links and "Permalink" settings still show up. It seems the easiest way to hide everything related to single pages is to simply return false from is_post_type_viewable().

Attachments (3)

49628.diff (1.2 KB) - added by donmhico 18 months ago.
49628.2.diff (1.2 KB) - added by deepaklalwani 15 months ago.
Update filter and $post_type parameter description
49628.3.diff (1.2 KB) - added by audrasjb 2 days ago.
Posts, Post Types: Introduce post_type_viewable hook to filter the result of is_post_type_viewable() function.

Download all attachments as: .zip

Change History (11)

#1 @powerbuoy
19 months ago

Thinking about it, an even better solution would probably be to add official support for has_single :)

#2 @powerbuoy
19 months ago

Found a duplicate of that: #43347 but seems abandoned. Perhaps adding an is_post_type_viewable filter will be easier?

Last edited 19 months ago by SergeyBiryukov (previous) (diff)

18 months ago

#3 @donmhico
18 months ago

  • Keywords has-patch added

Hi @powerbuoy,

Thank you for the ticket. 49628.diff introduces a new filter post_type_viewable which exposes $post_type to allow users to return either true or false depending on their needs.

#4 @SergeyBiryukov
18 months ago

  • Milestone changed from Awaiting Review to 5.5
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#6 @peterwilsoncc
18 months ago

@donmhico Minor note for the docs, when the filter is called $post_type will always be a WP_Post_Type object. If the function was passed a string it will be converted by that point.

15 months ago

Update filter and $post_type parameter description

#7 @SergeyBiryukov
15 months ago

  • Milestone changed from 5.5 to Future Release

Thanks for the patch! Moving to a future release for now to handle with #49380.

Last edited 15 months ago by SergeyBiryukov (previous) (diff)

2 days ago

Posts, Post Types: Introduce post_type_viewable hook to filter the result of is_post_type_viewable() function.

#8 @audrasjb
2 days ago

  • Keywords needs-dev-note added
  • Milestone changed from Future Release to 5.9

49628.3.diff refreshes the previous patch against trunk, rephrases a bit the docblocks wording and update the @since info.

Moving for 5.9 consideration.

This will also need a small note in the "Miscellaneous changes" dev note.

Note: See TracTickets for help on using tickets.