Ticket #12588: is_single.diff
File is_single.diff, 3.0 KB (added by , 15 years ago) |
---|
-
wp-includes/post.php
681 681 } 682 682 683 683 /** 684 * Check s 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. 685 685 * 686 686 * @since 3.0.0 687 * @uses get_post_type_object() 688 * 689 * @param string $types Type to check. 690 * @return bool 691 */ 692 function 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 687 700 * @uses get_post_type() 688 701 * 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. 690 703 * @param int $id Post ID. Defaults to current ID. 691 704 * @return bool 692 705 */ 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); 706 function is_post_of_type( $types, $id = false ) { 707 return in_array( get_post_type( $id ), (array) $types ); 701 708 } 702 709 703 710 /** -
wp-includes/query.php
134 134 * @param string|int $author Optional. Is current page this author. 135 135 * @return bool True if page is author or $author (if set). 136 136 */ 137 function is_author 137 function is_author($author = '') { 138 138 global $wp_query; 139 139 140 140 if ( !$wp_query->is_author ) … … 169 169 * @param string|array $category Optional. 170 170 * @return bool 171 171 */ 172 function is_category 172 function is_category($category = '') { 173 173 global $wp_query; 174 174 175 175 if ( !$wp_query->is_category ) … … 398 398 * @param mixed $page Either page or list of pages to test against. 399 399 * @return bool 400 400 */ 401 function is_page 401 function is_page($page = '') { 402 402 global $wp_query; 403 403 404 404 if ( !$wp_query->is_page ) … … 510 510 * @uses $wp_query 511 511 * 512 512 * @param mixed $post Either post or list of posts to test against. 513 * @param string|array $post_types Optional. Post type slug or slugs to check in current query. 513 514 * @return bool 514 515 */ 515 function is_single($post = '' ) {516 function is_single($post = '', $post_types = '') { 516 517 global $wp_query; 517 518 518 519 if ( !$wp_query->is_single ) 519 520 return false; 520 521 521 if ( empty( $post) )522 return true;523 524 522 $post_obj = $wp_query->get_queried_object(); 525 523 524 if ( empty($post) && !empty($post_types) ) 525 return in_array($post_obj->post_type, (array) $post_types); 526 526 527 $post = (array) $post; 527 528 528 529 if ( in_array( $post_obj->ID, $post ) ) … … 1226 1227 * 1227 1228 * @param string|array $query 1228 1229 */ 1229 function parse_query($query 1230 function parse_query($query) { 1230 1231 if ( !empty($query) || !isset($this->query) ) { 1231 1232 $this->init(); 1232 1233 if ( is_array($query) )