From cc39667fc14023254b659afb6db12b5fb4fa10e7 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Mon, 8 Nov 2021 15:21:59 +0000 Subject: [PATCH] Posts/Post Types: Introduce 'is_post_status_viewable ' filter in `is_post_status_viewable()`. Introduces a new filter 'is_post_status_viewable' which allows overriding the check. The function's return signature is a boolean type. This commit ensures the return signature remains unchanged by requirinng a strict boolean type of the returned filtered value. Why? * To maintain this signature and backwards-compatibility. * To future prepare for PHP 8.1 and beyond. An explanation is included in the filter's DocBlock. Follow-up to [50130]. Props audrasjb, hellofromTonya, peterwilsoncc. Fixes #54375. Built from https://develop.svn.wordpress.org/trunk@52043 git-svn-id: http://core.svn.wordpress.org/trunk@51635 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 19 ++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 841f61c77f..41c0c4664c 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2157,6 +2157,7 @@ function is_post_type_viewable( $post_type ) { * For all others, the 'publicly_queryable' value will be used. * * @since 5.7.0 + * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result. * * @param string|stdClass $post_status Post status name or object. * @return bool Whether the post status should be considered viewable. @@ -2177,7 +2178,23 @@ function is_post_status_viewable( $post_status ) { return false; } - return $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public ); + $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public ); + + /** + * Filters whether a post status is considered "viewable". + * + * The returned filtered value must be a boolean type to ensure + * `is_post_status_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 status is "viewable" (strict type). + * @param stdClass $post_status Post status object. + */ + return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 813b61f606..74b04f3d94 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52042'; +$wp_version = '5.9-alpha-52043'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.