Make WordPress Core

Changeset 36129


Ignore:
Timestamp:
12/31/2015 03:08:28 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.

Merge of [36128] to the 4.4 branch.

Fixes #35031.

Location:
branches/4.4
Files:
2 edited

Legend:

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

    r35690 r36129  
    49874987    global $wp_query, $wp_rewrite;
    49884988
     4989    if ( get_queried_object() ) {
     4990        return;
     4991    }
     4992
    49894993    if ( '' !== $wp_query->query_vars['name'] ) :
    49904994        global $wpdb;
  • branches/4.4/tests/phpunit/tests/rewrite/oldSlugRedirect.php

    r35242 r36129  
    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.