WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 3 months ago

#49628 reviewing feature request

Add is_post_type_viewable filter

Reported by: powerbuoy Owned by: SergeyBiryukov
Milestone: Future Release 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 (2)

49628.diff (1.2 KB) - added by donmhico 6 months ago.
49628.2.diff (1.2 KB) - added by deepaklalwani 3 months ago.
Update filter and $post_type parameter description

Download all attachments as: .zip

Change History (9)

#1 @powerbuoy
7 months ago

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

#2 @powerbuoy
7 months ago

Found a duplicate of that: https://core.trac.wordpress.org/ticket/43347 but seems abandoned. Perhaps adding an is_post_type_viewable filter will be easier?

Version 0, edited 7 months ago by powerbuoy (next)

@donmhico
6 months ago

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

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

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

@deepaklalwani
3 months ago

Update filter and $post_type parameter description

#7 @SergeyBiryukov
3 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 3 months ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.