Allow is_post_type_viewable()
to accept a post type name.
Previously, it accepted only a post type object. Props spacedmonkey. Fixes #35609. git-svn-id: https://develop.svn.wordpress.org/trunk@36402 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
81d3d79c1f
commit
af5a3b663f
@ -1665,12 +1665,20 @@ function set_post_type( $post_id = 0, $post_type = 'post' ) {
|
||||
* For all others, the 'publicly_queryable' value will be used.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @since 4.5.0 Added the ability to pass a post type name in addition to object.
|
||||
*
|
||||
* @param object $post_type_object Post type object.
|
||||
* @param object $post_type Post type name or object.
|
||||
* @return bool Whether the post type should be considered viewable.
|
||||
*/
|
||||
function is_post_type_viewable( $post_type_object ) {
|
||||
return $post_type_object->publicly_queryable || ( $post_type_object->_builtin && $post_type_object->public );
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,4 +71,24 @@ class Tests_Post_IsPostTypeViewable extends WP_UnitTestCase {
|
||||
$page = get_post_type_object( 'page' );
|
||||
$this->assertTrue( is_post_type_viewable( $page ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35609
|
||||
*/
|
||||
public function test_should_accept_post_type_name() {
|
||||
register_post_type( 'wptests_pt', array(
|
||||
'publicly_queryable' => true,
|
||||
'_builtin' => false,
|
||||
'public' => false,
|
||||
) );
|
||||
|
||||
$this->assertTrue( is_post_type_viewable( 'wptests_pt' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35609
|
||||
*/
|
||||
public function test_should_return_false_for_bad_post_type_name() {
|
||||
$this->assertFalse( is_post_type_viewable( 'foo' ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user