Permalinks: Preserve query arguments in old slug redirects#12633
Permalinks: Preserve query arguments in old slug redirects#12633ArkaPrabhaChowdhury wants to merge 2 commits into
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
This PR updates wp_old_slug_redirect() so that when WordPress redirects from an old post slug to the current permalink, it preserves the original request’s query string (e.g., tracking parameters), and adds a PHPUnit regression test to validate the behavior.
Changes:
- Append request query arguments to the redirect destination URL in
wp_old_slug_redirect(). - Add a PHPUnit regression test covering query-argument preservation for old-slug redirects.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/wp-includes/query.php |
Preserves request query arguments by appending $_GET to the computed redirect URL. |
tests/phpunit/tests/rewrite/oldSlugRedirect.php |
Adds regression coverage ensuring query arguments survive an old-slug redirect. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( ! empty( $_GET ) ) { | ||
| $link = add_query_arg( wp_unslash( $_GET ), $link ); | ||
| } |
| public function test_old_slug_redirect_preserves_query_arguments() { | ||
| $query_args = array( | ||
| 'utm_source' => 'test1', | ||
| 'utm_medium' => 'test2', | ||
| 'utm_campaign' => 'test3', | ||
| ); | ||
| $old_permalink = add_query_arg( $query_args, user_trailingslashit( get_permalink( self::$post_id ) ) ); |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Trac ticket: https://core.trac.wordpress.org/ticket/40032 | Preserves request query arguments when wp_old_slug_redirect() redirects an old post slug, with focused PHPUnit regression coverage.