Move checks for `post_type` being an array inline. See [25291], [25292], #18614.

git-svn-id: https://develop.svn.wordpress.org/trunk@25312 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2013-09-10 03:01:10 +00:00
parent 9ece28e545
commit e72ffa5d96
5 changed files with 27 additions and 13 deletions

View File

@ -579,7 +579,10 @@ function wp_title($sep = '»', $display = true, $seplocation = '') {
// If there's a post type archive
if ( is_post_type_archive() ) {
$post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
$post_type_object = get_post_type_object( $post_type );
if ( ! $post_type_object->has_archive )
$title = post_type_archive_title( '', false );
}
@ -706,7 +709,11 @@ function post_type_archive_title( $prefix = '', $display = true ) {
if ( ! is_post_type_archive() )
return;
$post_type_obj = get_post_type_object( get_query_var( 'post_type' ) );
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
$post_type_obj = get_post_type_object( $post_type );
$title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
if ( $display )
@ -1689,7 +1696,11 @@ function feed_links_extra( $args = array() ) {
$href = get_post_comments_feed_link( $post->ID );
}
} elseif ( is_post_type_archive() ) {
$post_type_obj = get_post_type_object( get_query_var( 'post_type' ) );
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
$post_type_obj = get_post_type_object( $post_type );
$title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
$href = get_post_type_archive_feed_link( $post_type_obj->name );
} elseif ( is_category() ) {

View File

@ -1058,9 +1058,6 @@ function get_post_type( $post = null ) {
function get_post_type_object( $post_type ) {
global $wp_post_types;
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
if ( empty($wp_post_types[$post_type]) )
return null;

View File

@ -3076,7 +3076,10 @@ class WP_Query {
_make_cat_compat( $this->queried_object );
}
} elseif ( $this->is_post_type_archive ) {
$this->queried_object = get_post_type_object( $this->get('post_type') );
$post_type = $this->get( 'post_type' );
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
$this->queried_object = get_post_type_object( $post_type );
} elseif ( $this->is_posts_page ) {
$page_for_posts = get_option('page_for_posts');
$this->queried_object = get_post( $page_for_posts );
@ -3152,7 +3155,10 @@ class WP_Query {
if ( empty( $post_types ) || ! $this->is_post_type_archive )
return (bool) $this->is_post_type_archive;
$post_type_object = get_post_type_object( $this->get( 'post_type' ) );
$post_type = $this->get( 'post_type' );
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
$post_type_object = get_post_type_object( $post_type );
return in_array( $post_type_object->name, (array) $post_types );
}

View File

@ -80,7 +80,11 @@ function get_archive_template() {
* @return string
*/
function get_post_type_archive_template() {
$obj = get_post_type_object( get_query_var( 'post_type' ) );
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
$obj = get_post_type_object( $post_type );
if ( ! $obj->has_archive )
return '';

View File

@ -699,16 +699,12 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
$this->go_to( "/$cpt_name/" );
$this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
$this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
$this->assertEquals( get_queried_object(), get_post_type_object( array( $cpt_name ) ) );
$this->assertEquals( get_queried_object(), get_post_type_object( array( $cpt_name, 'post' ) ) );
add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) );
$this->go_to( "/$cpt_name/" );
$this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
$this->assertEquals( get_queried_object(), get_post_type_object( 'post' ) );
$this->assertEquals( get_queried_object(), get_post_type_object( array( 'post' ) ) );
$this->assertEquals( get_queried_object(), get_post_type_object( array( 'post', $cpt_name ) ) );
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) );
}