mirror of
git://develop.git.wordpress.org/
synced 2025-04-05 04:33:18 +02:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@52045 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
874c62cde2
commit
588f155406
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user