WordPress.org

Make WordPress Core

Ticket #12588: is_singular.diff

File is_singular.diff, 3.0 KB (added by scribu, 8 years ago)

add $post_type parameter to is_singular()

  • 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/**
  • wp-includes/query.php

     
    134134 * @param string|int $author Optional. Is current page this author.
    135135 * @return bool True if page is author or $author (if set).
    136136 */
    137 function is_author ($author = '') {
     137function is_author($author = '') {
    138138        global $wp_query;
    139139
    140140        if ( !$wp_query->is_author )
     
    169169 * @param string|array $category Optional.
    170170 * @return bool
    171171 */
    172 function is_category ($category = '') {
     172function is_category($category = '') {
    173173        global $wp_query;
    174174
    175175        if ( !$wp_query->is_category )
     
    398398 * @param mixed $page Either page or list of pages to test against.
    399399 * @return bool
    400400 */
    401 function is_page ($page = '') {
     401function is_page($page = '') {
    402402        global $wp_query;
    403403
    404404        if ( !$wp_query->is_page )
     
    518518        if ( !$wp_query->is_single )
    519519                return false;
    520520
    521         if ( empty( $post) )
     521        if ( empty($post) )
    522522                return true;
    523523
    524524        $post_obj = $wp_query->get_queried_object();
     
    541541 * @since 1.5.0
    542542 * @uses $wp_query
    543543 *
     544 * @param string|array $post_types Optional. Post type slug or slugs to check in current query.
    544545 * @return bool
    545546 */
    546 function is_singular() {
     547function is_singular($post_types = '') {
    547548        global $wp_query;
    548549
    549         return $wp_query->is_singular;
     550        if ( !$wp_query->is_singular )
     551                return false;
     552
     553        if ( empty($post_types) )
     554                return true;
     555
     556        $post_obj = $wp_query->get_queried_object();
     557
     558        return in_array($post_obj->post_type, (array) $post_types);
    550559}
    551560
    552561/**
     
    12261235         *
    12271236         * @param string|array $query
    12281237         */
    1229         function parse_query($query ) {
     1238        function parse_query($query) {
    12301239                if ( !empty($query) || !isset($this->query) ) {
    12311240                        $this->init();
    12321241                        if ( is_array($query) )