Ticket #12588: is_singular.diff
File is_singular.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 ) … … 518 518 if ( !$wp_query->is_single ) 519 519 return false; 520 520 521 if ( empty( 521 if ( empty($post) ) 522 522 return true; 523 523 524 524 $post_obj = $wp_query->get_queried_object(); … … 541 541 * @since 1.5.0 542 542 * @uses $wp_query 543 543 * 544 * @param string|array $post_types Optional. Post type slug or slugs to check in current query. 544 545 * @return bool 545 546 */ 546 function is_singular( ) {547 function is_singular($post_types = '') { 547 548 global $wp_query; 548 549 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); 550 559 } 551 560 552 561 /** … … 1226 1235 * 1227 1236 * @param string|array $query 1228 1237 */ 1229 function parse_query($query 1238 function parse_query($query) { 1230 1239 if ( !empty($query) || !isset($this->query) ) { 1231 1240 $this->init(); 1232 1241 if ( is_array($query) )