WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 7 weeks ago

#49628 reviewing feature request

Add is_post_type_viewable filter

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

Description

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 (1)

49628.diff (1.2 KB) - added by donmhico 7 weeks ago.

Download all attachments as: .zip

Change History (7)

#1 @powerbuoy
2 months ago

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

#2 @powerbuoy
2 months ago

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

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

@donmhico
7 weeks ago

#3 @donmhico
7 weeks 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
7 weeks ago

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

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

Note: See TracTickets for help on using tickets.