is_post_status_viewable

函数
is_post_status_viewable ( $post_status )
参数
  • (string|stdClass) $post_status Post status name or object.
    Required:
返回值
  • (bool) Whether the post status should be considered viewable.
定义位置
相关方法
is_post_type_viewableis_post_publicly_viewableget_post_status_objectregister_post_statusget_post_statuses
引入
5.7.0
弃用
-

is_post_status_viewable: 这个函数检查一个特定的文章状态是否可以查看。它把文章的状态作为一个参数,如果该状态是可查看的,则返回true,如果不是,则返回false。

确定一个文章状态是否被认为是"可查看"。

对于内置的文章状态,如发布和私人,将评估’public’值。对于所有其他的,将使用’public_queryable’值。

function is_post_status_viewable( $post_status ) {
	if ( is_scalar( $post_status ) ) {
		$post_status = get_post_status_object( $post_status );

		if ( ! $post_status ) {
			return false;
		}
	}

	if (
		! is_object( $post_status ) ||
		$post_status->internal ||
		$post_status->protected
	) {
		return false;
	}

	$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 );
}

常见问题

FAQs
查看更多 >