Ticket #24612: 24612.2.patch
File 24612.2.patch, 2.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/query.php
1833 1833 } 1834 1834 1835 1835 if ( '' != $qv['pagename'] ) { 1836 $this->queried_object = get_page_by_path($qv['pagename']); 1837 if ( !empty($this->queried_object) ) 1836 $this->queried_object = get_page_by_path( $qv['pagename'] ); 1837 1838 if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) { 1839 if ( preg_match( "/^[^%]*%(?:postname)%/", get_option( 'permalink_structure' ) ) ) { 1840 // See if we also have a post with the same slug 1841 $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' ); 1842 if ( $post ) { 1843 $this->queried_object = $post; 1844 $this->is_page = false; 1845 $this->is_single = true; 1846 } 1847 } 1848 } 1849 1850 if ( ! empty( $this->queried_object ) ) { 1838 1851 $this->queried_object_id = (int) $this->queried_object->ID; 1839 else 1840 unset($this->queried_object); 1852 } else { 1853 unset( $this->queried_object ); 1854 } 1841 1855 1842 1856 if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) { 1843 1857 $this->is_page = false; -
tests/phpunit/tests/query/conditionals.php
767 767 $this->assertFalse( $q->is_single( $p2 ) ); 768 768 } 769 769 770 /** 771 * @ticket 24612 772 */ 773 public function test_is_single_with_slug_that_clashes_with_attachment() { 774 $this->set_permalink_structure( '/%postname%/' ); 775 776 $attachment_id = $this->factory->post->create( array( 777 'post_type' => 'attachment', 778 ) ); 779 780 $post_id = $this->factory->post->create( array( 781 'post_title' => get_post( $attachment_id )->post_title 782 ) ); 783 784 $this->go_to( get_permalink( $post_id ) ); 785 786 $q = $GLOBALS['wp_query']; 787 788 $this->assertTrue( $q->is_single() ); 789 $this->assertTrue( $q->is_single( $post_id ) ); 790 $this->assertFalse( $q->is_attachment() ); 791 $this->assertFalse( $q->is_404() ); 792 793 $this->set_permalink_structure(); 794 } 795 770 796 function test_is_page() { 771 797 $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 772 798 $this->go_to( "/?page_id=$post_id" );