From 4ba2fd6f0e496c35a1e03fbae88925fb6e63e6a6 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Mon, 8 Nov 2021 15:34:59 +0000 Subject: [PATCH] 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 --- wp-includes/post.php | 17 ++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 41c0c4664c..f578e4ce35 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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 ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index f3aa4fe38e..306e9b575d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.