is_post_status_viewable
云策文档标注
概述
is_post_status_viewable 是一个 WordPress 过滤器,用于控制文章状态是否被视为“可查看”。它要求返回严格的布尔值以确保函数行为一致。
关键要点
- 过滤器名称:is_post_status_viewable
- 返回类型:必须为布尔值(true 或 false),非布尔值将导致函数返回 false
- 设计目的:保持向后兼容性,防止 PHP 8.1+ 中的类型错误
- 参数:$is_viewable(布尔值,表示是否可查看)和 $post_status(文章状态对象)
- 引入版本:WordPress 5.9.0
代码示例
return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
原文内容
Filters whether a post status is considered “viewable”.
Description
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.
Parameters
$is_viewablebool-
Whether the post status is “viewable” (strict type).
$post_statusstdClass-
Post status object.
Source
return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |