Ticket #16802: 16802.3.patch
File 16802.3.patch, 2.6 KB (added by , 11 years ago) |
---|
-
src/wp-includes/query.php
4227 4227 * 4228 4228 * @since 3.1.0 4229 4229 * 4230 * @param mixed $page Page ID, title, slug, or array of such.4230 * @param mixed $page Page ID, title, slug, path, or array of such. 4231 4231 * @return bool 4232 4232 */ 4233 4233 public function is_page( $page = '' ) { … … 4241 4241 4242 4242 $page = (array) $page; 4243 4243 4244 if ( in_array( $page_obj->ID, $page ) ) 4244 if ( in_array( $page_obj->ID, $page ) ) { 4245 4245 return true; 4246 elseif ( in_array( $page_obj->post_title, $page ) )4246 } elseif ( in_array( $page_obj->post_title, $page ) ) { 4247 4247 return true; 4248 else if ( in_array( $page_obj->post_name, $page ) )4248 } else if ( in_array( $page_obj->post_name, $page ) ) { 4249 4249 return true; 4250 } else { 4251 foreach ( $page as $index => $pagepath ) { 4252 $pagepath_page_obj = get_page_by_path( $pagepath ); 4253 4254 if ( $pagepath_page_obj && ( $pagepath_page_obj->ID == $page_obj->ID ) ) { 4255 return true; 4256 } 4257 } 4258 } 4250 4259 4251 4260 return false; 4252 4261 } -
tests/phpunit/tests/query/conditionals.php
709 709 $this->assertTrue( is_page( $post->post_name ) ); 710 710 } 711 711 712 /** 713 * @ticket 16802 714 */ 715 function test_is_page_with_parent() { 716 $parent_id = $this->factory->post->create( array( 717 'post_type' => 'page', 718 'post_name' => 'foo', 719 ) ); 720 $post_id = $this->factory->post->create( array( 721 'post_type' => 'page', 722 'post_name' => 'bar', 723 'post_parent' => $parent_id, 724 ) ); 725 $this->go_to( "/?page_id=$post_id" ); 726 727 $post = get_queried_object(); 728 $q = $GLOBALS['wp_query']; 729 730 $this->assertTrue( is_page() ); 731 $this->assertFalse( $q->is_single ); 732 $this->assertTrue( $q->is_page ); 733 $this->assertFalse( $q->is_attachment ); 734 $this->assertTrue( is_page( $post ) ); 735 $this->assertTrue( is_page( $post->ID ) ); 736 $this->assertTrue( is_page( $post->post_title ) ); 737 $this->assertTrue( is_page( $post->post_name ) ); 738 $this->assertTrue( is_page( 'foo/bar' ) ); 739 $this->assertFalse( is_page( $parent_id ) ); 740 $this->assertFalse( is_page( 'foo/bar/baz' ) ); 741 $this->assertFalse( is_page( 'bar/bar' ) ); 742 $this->assertFalse( is_page( 'foo' ) ); 743 } 744 712 745 function test_is_attachment() { 713 746 $post_id = $this->factory->post->create( array( 'post_type' => 'attachment' ) ); 714 747 $this->go_to( "/?attachment_id=$post_id" );