Make WordPress Core

Changeset 36128


Ignore:
Timestamp:
12/31/2015 03:00:33 AM (9 years ago)
Author:
pento
Message:

Redirects: Prevent redirects if a queried object exists.

After [34659], it became possible to cause an incorrect redirect, by changing the slug of a post, then creating a new post with the old slug. The correct behaviour is to prevent redirecting to the old post.

Props dd32, pento.

Fixes #35031 for trunk.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r36127 r36128  
    49574957    global $wp_query, $wp_rewrite;
    49584958
     4959    if ( get_queried_object() ) {
     4960        return;
     4961    }
     4962
    49594963    if ( '' !== $wp_query->query_vars['name'] ) :
    49604964        global $wpdb;
  • trunk/tests/phpunit/tests/rewrite/oldSlugRedirect.php

    r35242 r36128  
    151151    }
    152152
     153    /**
     154     * @ticket 35031
     155     */
     156    public function test_old_slug_doesnt_redirect_when_reused() {
     157        $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) );
     158
     159        wp_update_post( array(
     160            'ID' => $this->post_id,
     161            'post_name' => 'bar-baz',
     162        ) );
     163
     164        $new_post_id = self::factory()->post->create( array(
     165            'post_title'   => 'Foo Bar',
     166            'post_name'   => 'foo-bar',
     167        ) );
     168
     169        $permalink = user_trailingslashit( get_permalink( $new_post_id ) );
     170
     171        $this->assertEquals( $old_permalink, $permalink );
     172
     173        $this->go_to( $old_permalink );
     174        wp_old_slug_redirect();
     175        $this->assertNull( $this->old_slug_redirect_url );
     176    }
     177
    153178    public function filter_old_slug_redirect_url( $url ) {
    154179        $this->old_slug_redirect_url = $url;
Note: See TracChangeset for help on using the changeset viewer.