Make WordPress Core


Ignore:
Timestamp:
10/15/2015 06:48:22 AM (9 years ago)
Author:
SergeyBiryukov
Message:

In WP::parse_request() and url_to_postid(), if a post slug clashes with a trashed page, return the post instead of the page.

Props kovshenin, SergeyBiryukov, igmoweb.
Fixes #21970.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rewrite.php

    r34890 r35195  
    307307        $this->assertFalse( is_home() );
    308308    }
     309
     310    /**
     311     * @ticket 21970
     312     */
     313    function test_url_to_postid_with_post_slug_that_clashes_with_a_trashed_page() {
     314        $this->set_permalink_structure( '/%postname%/' );
     315
     316        $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_status' => 'trash' ) );
     317        $post_id = $this->factory->post->create( array( 'post_title' => get_post( $page_id )->post_title ) );
     318       
     319        $this->assertEquals( $post_id, url_to_postid( get_permalink( $post_id ) ) );
     320
     321        $this->set_permalink_structure();
     322    }
     323
     324    /**
     325     * @ticket 21970
     326     */
     327    function test_parse_request_with_post_slug_that_clashes_with_a_trashed_page() {
     328        $this->set_permalink_structure( '/%postname%/' );
     329
     330        $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_status' => 'trash' ) );
     331        $post_id = $this->factory->post->create( array( 'post_title' => get_post( $page_id )->post_title ) );
     332       
     333        $this->go_to( get_permalink( $post_id ) );
     334
     335        $this->assertTrue( is_single() );
     336        $this->assertFalse( is_404() );
     337
     338        $this->set_permalink_structure();
     339    }
     340
    309341}
Note: See TracChangeset for help on using the changeset viewer.