[wp-trac] [WordPress Trac] #49628: Add is_post_type_viewable filter

WordPress Trac noreply at wordpress.org
Thu Nov 4 23:02:08 UTC 2021


#49628: Add is_post_type_viewable filter
-------------------------------------------------+-------------------------
 Reporter:  powerbuoy                            |       Owner:
                                                 |  SergeyBiryukov
     Type:  feature request                      |      Status:  reviewing
 Priority:  normal                               |   Milestone:  5.9
Component:  Posts, Post Types                    |     Version:  5.3.2
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-dev-note needs-      |     Focuses:
  refresh                                        |  administration
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * keywords:  has-patch needs-dev-note => has-patch needs-dev-note needs-
     refresh


Comment:

 There's a risk of a backwards-compatiblity break in directly returning the
 filtered value. Why? There are currently no checks to ensure a boolean
 value is returned through the filter before returning from this function.

 I suggest:

 {{{#!php
 $is_viewable = apply_filters( 'post_type_viewable', $is_viewable,
 $post_type );

 // Make sure the filtered value is a boolean type before returning it.
 if ( ! is_bool( $is_viewable ) {
     return false;
 }

 return $is_viewable;
 }}}

 Notice that if it's not a `boolean` data type, it returns `false`. This is
 a safer approach than attempting to type cast to bool when the return
 value could be of any data type.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49628#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list