Ticket #16802: 16802.diff
File 16802.diff, 3.6 KB (added by , 11 years ago) |
---|
-
src/wp-includes/query.php
4311 4311 * 4312 4312 * @since 3.1.0 4313 4313 * 4314 * @param mixed $page Page ID, title, slug, or array of such.4314 * @param mixed $page Page ID, title, slug, path, or array of such. 4315 4315 * @return bool 4316 4316 */ 4317 4317 public function is_page( $page = '' ) { … … 4325 4325 4326 4326 $page = (array) $page; 4327 4327 4328 if ( in_array( $page_obj->ID, $page ) ) 4328 if ( in_array( $page_obj->ID, $page ) ) { 4329 4329 return true; 4330 elseif ( in_array( $page_obj->post_title, $page ) )4330 } elseif ( in_array( $page_obj->post_title, $page ) ) { 4331 4331 return true; 4332 else if ( in_array( $page_obj->post_name, $page ) )4332 } else if ( in_array( $page_obj->post_name, $page ) ) { 4333 4333 return true; 4334 } else { 4335 foreach ( $page as $pagepath ) { 4336 if ( ! strpos( $pagepath, '/' ) ) { 4337 continue; 4338 } 4339 $pagepath_obj = get_page_by_path( $pagepath ); 4340 4341 if ( $pagepath_obj && ( $pagepath_obj->ID == $page_obj->ID ) ) { 4342 return true; 4343 } 4344 } 4345 } 4334 4346 4335 4347 return false; 4336 4348 } … … 4392 4404 * 4393 4405 * @since 3.1.0 4394 4406 * 4395 * @param mixed $post Post ID, title, slug, or array of such.4407 * @param mixed $post Post ID, title, slug, path, or array of such. 4396 4408 * @return bool 4397 4409 */ 4398 4410 public function is_single( $post = '' ) { … … 4406 4418 4407 4419 $post = (array) $post; 4408 4420 4409 if ( in_array( $post_obj->ID, $post ) ) 4421 if ( in_array( $post_obj->ID, $post ) ) { 4410 4422 return true; 4411 elseif ( in_array( $post_obj->post_title, $post ) )4423 } elseif ( in_array( $post_obj->post_title, $post ) ) { 4412 4424 return true; 4413 elseif ( in_array( $post_obj->post_name, $post ) )4425 } elseif ( in_array( $post_obj->post_name, $post ) ) { 4414 4426 return true; 4415 4427 } else { 4428 foreach ( $post as $postpath ) { 4429 if ( ! strpos( $postpath, '/' ) ) { 4430 continue; 4431 } 4432 $postpath_obj = get_page_by_path( $postpath, OBJECT, $post_obj->post_type ); 4433 4434 if ( $postpath_obj && ( $postpath_obj->ID == $post_obj->ID ) ) { 4435 return true; 4436 } 4437 } 4438 } 4416 4439 return false; 4417 4440 } 4418 4441 -
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" );