Simplify is_post_type and is_post_type_hierarchical. Make them work like their taxonomy counterparts. see #12588.

git-svn-id: https://develop.svn.wordpress.org/trunk@14521 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2010-05-08 22:10:28 +00:00
parent 7ea215494e
commit fd9b4855e6
1 changed files with 12 additions and 22 deletions

View File

@ -666,38 +666,28 @@ function get_post_stati( $args = array(), $output = 'names', $operator = 'and' )
* @since 3.0.0 * @since 3.0.0
* @see get_post_type_object * @see get_post_type_object
* *
* @param string|int|object $post Post type name, post id, or a post object. * @param string $post Post type name
* @return bool true if post type is hierarchical, else false. * @return bool Whether post type is hierarchical.
*/ */
function is_post_type_hierarchical( $post = false ) { function is_post_type_hierarchical( $post_type ) {
if ( is_string($post) && $is_post_type = get_post_type_object($post) ) if ( ! is_post_type( $post_type ) )
return $is_post_type->hierarchical;
$ptype = get_post( $post );
if ( $ptype && $is_post_type = get_post_type_object($ptype->post_type) )
return $is_post_type->hierarchical;
return false; return false;
$post_type = get_post_type_object( $post_type );
return $post_type->hierarchical;
} }
/** /**
* Checks if a post type is registered. Can also check if the current or specified post is of a post type. * Checks if a post type is registered.
* *
* @since 3.0.0 * @since 3.0.0
* @uses get_post_type() * @uses get_post_type()
* *
* @param string|array $types Type or types to check. Defaults to all post types. * @param string Post type name
* @param int $id Post ID. Defaults to current ID. * @return bool Whether post type is registered.
* @return bool
*/ */
function is_post_type( $types = false, $id = false ) { function is_post_type( $post_type ) {
if ( $id ) { return (bool) get_post_type_object( $post_type );
$types = ( $types === false ) ? get_post_types() : (array) $types;
return in_array( get_post_type( $id ), $types );
}
return (bool) get_post_type_object($types);
} }
/** /**