is_post_type_viewable

函式
is_post_type_viewable ( $post_type )
引數
  • (string|WP_Post_Type) $post_type Post type name or object.
    Required:
返回值
  • (bool) Whether the post type should be considered viewable.
定義位置
相關方法
is_post_status_viewableis_post_publicly_viewableis_post_type_hierarchicalis_post_type_archiveis_taxonomy_viewable
引入
4.4.0
棄用
-

is_post_type_viewable – 這個函式檢查一個給定的文章型別是否可以公開檢視。如果文章型別是可公開檢視的,則返回true,否則返回false。

確定一個文章型別是否被認為是”viewable”。

對於內建的文章型別,如文章和頁面,將評估”public”值。對於所有其他型別,將使用’public_queryable’值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function is_post_type_viewable( $post_type ) {
if ( is_scalar( $post_type ) ) {
$post_type = get_post_type_object( $post_type );
if ( ! $post_type ) {
return false;
}
}
if ( ! is_object( $post_type ) ) {
return false;
}
$is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
/**
* 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" (strict type).
* @param WP_Post_Type $post_type Post type object.
*/
return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
}
function is_post_type_viewable( $post_type ) { if ( is_scalar( $post_type ) ) { $post_type = get_post_type_object( $post_type ); if ( ! $post_type ) { return false; } } if ( ! is_object( $post_type ) ) { return false; } $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); /** * 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" (strict type). * @param WP_Post_Type $post_type Post type object. */ return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type ); }
function is_post_type_viewable( $post_type ) {
	if ( is_scalar( $post_type ) ) {
		$post_type = get_post_type_object( $post_type );

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

	if ( ! is_object( $post_type ) ) {
		return false;
	}

	$is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );

	/**
	 * 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" (strict type).
	 * @param WP_Post_Type $post_type   Post type object.
	 */
	return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
}

常見問題

FAQs
檢視更多 >