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.

Built from https://develop.svn.wordpress.org/trunk@52045


git-svn-id: http://core.svn.wordpress.org/trunk@51637 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-11-08 15:34:59 +00:00
parent c2a7d2a773
commit 4ba2fd6f0e
2 changed files with 9 additions and 10 deletions

View File

@ -2135,19 +2135,18 @@ function is_post_type_viewable( $post_type ) {
/**
* Filters whether a post type is considered "viewable".
*
* The returned filtered value must be a boolean type to ensure
* `is_post_type_viewable()` only returns a boolean. This strictness
* is by design to maintain backwards-compatibility and guard against
* potential type errors in PHP 8.1+. Non-boolean values (even falsey
* and truthy values) will result in the function returning false.
*
* @since 5.9.0
*
* @param bool $is_viewable Whether the post type is "viewable".
* @param bool $is_viewable Whether the post type is "viewable" (strict type).
* @param WP_Post_Type $post_type Post type object.
*/
$is_viewable = apply_filters( 'is_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;
return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
}
/**

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-52044';
$wp_version = '5.9-alpha-52045';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.