WordPress.org

Make WordPress Core

Ticket #12588: is_post_of_type.diff

File is_post_of_type.diff, 1.2 KB (added by scribu, 8 years ago)

introduce is_post_of_type()

  • wp-includes/post.php

     
    681681}
    682682
    683683/**
    684  * Checks if a post type is registered. Can also check if the current or specified post is of a post type.
     684 * Check if a post type is registered.
    685685 *
    686686 * @since 3.0.0
     687 * @uses get_post_type_object()
     688 *
     689 * @param string $types Type to check.
     690 * @return bool
     691 */
     692function is_post_type( $type ) {
     693        return (bool) get_post_type_object($type);
     694}
     695
     696/**
     697 * Check if the current or specified post is of a given post type.
     698 *
     699 * @since 3.0.0
    687700 * @uses get_post_type()
    688701 *
    689  * @param string|array $types Type or types to check. Defaults to all post types.
     702 * @param string|array $types Type or types to check.
    690703 * @param int $id Post ID. Defaults to current ID.
    691704 * @return bool
    692705 */
    693 function is_post_type( $types = false, $id = false ) {
    694         if ( $id ) {
    695                 $types = ( $types === false ) ? get_post_types() : (array) $types;
    696 
    697                 return in_array( get_post_type( $id ), $types );
    698         }
    699 
    700         return (bool) get_post_type_object($types);
     706function is_post_of_type( $types, $id = false ) {
     707        return in_array( get_post_type( $id ), (array) $types );
    701708}
    702709
    703710/**