Changeset 29039
- Timestamp:
- 07/09/2014 04:03:17 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r29027 r29039 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 */ … … 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; … … 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 */ … … 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 } -
trunk/tests/phpunit/tests/query/conditionals.php
r28966 r29039 693 693 } 694 694 695 /** 696 * @ticket 16802 697 */ 698 function test_is_single_with_parent() { 699 // Use custom hierarchical post type 700 $post_type = 'test_hierarchical'; 701 702 register_post_type( $post_type, array( 703 'hierarchical' => true, 704 'rewrite' => true, 705 'has_archive' => true, 706 'public' => true 707 ) ); 708 709 // Create parent and child posts 710 $parent_id = $this->factory->post->create( array( 711 'post_type' => $post_type, 712 'post_name' => 'foo' 713 ) ); 714 715 $post_id = $this->factory->post->create( array( 716 'post_type' => $post_type, 717 'post_name' => 'bar', 718 'post_parent' => $parent_id 719 ) ); 720 721 // Tests 722 $this->go_to( "/?p=$post_id&post_type=$post_type" ); 723 724 $post = get_queried_object(); 725 $q = $GLOBALS['wp_query']; 726 727 $this->assertTrue( is_single() ); 728 $this->assertFalse( $q->is_page ); 729 $this->assertTrue( $q->is_single ); 730 $this->assertFalse( $q->is_attachment ); 731 $this->assertTrue( is_single( $post ) ); 732 $this->assertTrue( is_single( $post->ID ) ); 733 $this->assertTrue( is_single( $post->post_title ) ); 734 $this->assertTrue( is_single( $post->post_name ) ); 735 $this->assertTrue( is_single( 'foo/bar' ) ); 736 $this->assertFalse( is_single( $parent_id ) ); 737 $this->assertFalse( is_single( 'foo/bar/baz' ) ); 738 $this->assertFalse( is_single( 'bar/bar' ) ); 739 $this->assertFalse( is_single( 'foo' ) ); 740 } 741 695 742 function test_is_page() { 696 743 $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); … … 708 755 $this->assertTrue( is_page( $post->post_title ) ); 709 756 $this->assertTrue( is_page( $post->post_name ) ); 757 } 758 759 /** 760 * @ticket 16802 761 */ 762 function test_is_page_with_parent() { 763 $parent_id = $this->factory->post->create( array( 764 'post_type' => 'page', 765 'post_name' => 'foo', 766 ) ); 767 $post_id = $this->factory->post->create( array( 768 'post_type' => 'page', 769 'post_name' => 'bar', 770 'post_parent' => $parent_id, 771 ) ); 772 $this->go_to( "/?page_id=$post_id" ); 773 774 $post = get_queried_object(); 775 $q = $GLOBALS['wp_query']; 776 777 $this->assertTrue( is_page() ); 778 $this->assertFalse( $q->is_single ); 779 $this->assertTrue( $q->is_page ); 780 $this->assertFalse( $q->is_attachment ); 781 $this->assertTrue( is_page( $post ) ); 782 $this->assertTrue( is_page( $post->ID ) ); 783 $this->assertTrue( is_page( $post->post_title ) ); 784 $this->assertTrue( is_page( $post->post_name ) ); 785 $this->assertTrue( is_page( 'foo/bar' ) ); 786 $this->assertFalse( is_page( $parent_id ) ); 787 $this->assertFalse( is_page( 'foo/bar/baz' ) ); 788 $this->assertFalse( is_page( 'bar/bar' ) ); 789 $this->assertFalse( is_page( 'foo' ) ); 710 790 } 711 791
Note: See TracChangeset
for help on using the changeset viewer.