is_post_type_viewable
Filters whether a post type is considered "viewable".
The returned filtered value must be a boolean type to ensure is_post_type_viewable() 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.
Usage
add_filter( 'is_post_type_viewable', 'wp_kama_is_post_type_viewable_filter', 10, 2 ); /** * Function for `is_post_type_viewable` filter-hook. * * @param bool $is_viewable Whether the post type is "viewable" (strict type). * @param WP_Post_Type $post_type Post type object. * * @return bool */ function wp_kama_is_post_type_viewable_filter( $is_viewable, $post_type ){ // filter... return $is_viewable; }
- $is_viewable(true|false)
- Whether the post type is "viewable" (strict type).
- $post_type(WP_Post_Type)
- Post type object.
Changelog
Since 5.9.0 | Introduced. |
Where the hook is called
is_post_type_viewable
wp-includes/post.php 2399
return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );