Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/wp-includes/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,13 @@ function wp_old_slug_redirect() {
$link = user_trailingslashit( trailingslashit( $link ) . 'embed' );
}

$query_string = isset( $_SERVER['QUERY_STRING'] ) ? (string) $_SERVER['QUERY_STRING'] : '';

if ( '' !== $query_string ) {
$link .= false === strpos( $link, '?' ) ? '?' : '&';
$link .= $query_string;
}

/**
* Filters the old slug redirect URL.
*
Expand Down
24 changes: 24 additions & 0 deletions tests/phpunit/tests/rewrite/oldSlugRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function set_up() {

public function tear_down() {
$this->old_slug_redirect_url = null;
unset( $_SERVER['QUERY_STRING'] );

parent::tear_down();
}
Expand All @@ -55,6 +56,29 @@ public function test_old_slug_redirect() {
$this->assertSame( $permalink, $this->old_slug_redirect_url );
}

/**
* @ticket 65267
*/
public function test_old_slug_redirect_preserves_query_string() {
$old_permalink = user_trailingslashit( get_permalink( self::$post_id ) );

wp_update_post(
array(
'ID' => self::$post_id,
'post_name' => 'bar-baz',
)
);

$permalink = user_trailingslashit( get_permalink( self::$post_id ) );
$query_string = 'utm_source=flyer&foo=a%2Bb&a=1&a=2';

$this->go_to( $old_permalink . '?' . $query_string );
$_SERVER['QUERY_STRING'] = $query_string;

wp_old_slug_redirect();
$this->assertSame( $permalink . '?' . $query_string, $this->old_slug_redirect_url );
}

/**
* @ticket 36723
*/
Expand Down
Loading