Make WordPress Core

Changeset 52045


Ignore:
Timestamp:
11/08/2021 03:33:10 PM (3 years ago)
Author:
hellofromTonya
Message:

Posts/Post Types: Improves the 'is_post_type_viewable' filter boolean return.

As a follow-up to [52024], simplifies the strict boolean type check to conserve memory and processing. Also includes an explanation of why a strict boolean is required as the returned filtered value. This commit is consistent with the implementation in [52043].

Follow-up to [33666], [36402], [52024].

Props hellofromTonya, peterwilsoncc, cybr, jrf.
Fixes #49628.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r52043 r52045  
    21362136     * Filters whether a post type is considered "viewable".
    21372137     *
     2138     * The returned filtered value must be a boolean type to ensure
     2139     * `is_post_type_viewable()` only returns a boolean. This strictness
     2140     * is by design to maintain backwards-compatibility and guard against
     2141     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     2142     * and truthy values) will result in the function returning false.
     2143     *
    21382144     * @since 5.9.0
    21392145     *
    2140      * @param bool         $is_viewable Whether the post type is "viewable".
     2146     * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
    21412147     * @param WP_Post_Type $post_type   Post type object.
    21422148     */
    2143     $is_viewable = apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
    2144 
    2145     // Make sure the filtered value is a boolean type before returning it.
    2146     if ( ! is_bool( $is_viewable ) ) {
    2147         return false;
    2148     }
    2149 
    2150     return $is_viewable;
     2149    return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
    21512150}
    21522151
Note: See TracChangeset for help on using the changeset viewer.