Repository navigation
Random Redirects: random post type archives. - #15838
peterwilsoncc wants to merge 23 commits into
Conversation
a06ea9d to
ee8cbec
Compare
ee8cbec to
d434e33
Compare
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. |
31f654a to
2f3742d
Compare
…ected` to content tests.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved rewrite-rule precedence and conflict-detection issues can misroute /random/ requests or cause 404s, while missing post-type cleanup makes redirect tests order-dependent.
3 open issues
What changed in this PR
This PR updates random-content rewrite handling to detect conflicts with post type archives and custom routes at /random/.
Changes:
- Checks existing rewrite rules for base conflicts and adds a filter to override detection.
- Adds rewrite and redirect tests for conflicting routes, custom bases, and permalink variants.
- Restores rewrite state during test cleanup and aligns data-provider names with their tests.
| File | Description |
|---|---|
tests/phpunit/tests/wp/handleRandom.php |
Renames data providers to match test methods. |
tests/phpunit/tests/rewrite/randomRewriteRules.php |
Adds conflict-detection coverage and rewrite-state cleanup. |
tests/phpunit/tests/query/randomContentRedirect.php |
Adds request-level conflict tests and rewrite-state cleanup. |
src/wp-includes/class-wp-rewrite.php |
Adds existing-rule conflict detection, an override filter, and documentation. |
Review effort: Balanced
|
Review by Claude Opus 5.5 Medium.
|
Co-authored-by: Aaron Jorbin <aaronjorbin@users.noreply.github.com>
Co-authored-by: Aaron Jorbin <aaronjorbin@users.noreply.github.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
|
@aaronjorbin I've simplified the approach, so some of your earlier review comments are now outdated.
The PR description has the details. |

Ensures rewrite rules added to the top, including post type and taxonomy rules, take precedence over random content rules using the same regex.
extra_rules_topare omitted when the rules are generated.array_merge()kept the top rule's position but replaced its query with the random query, so a post type archive at/random/redirected to random content.^random/?$) and bottom rules behave as they do on trunk.randommay match random archive URLs. The workaround is changing the random base on the Permalinks screen.Demonstrating the tests
Removed since earlier reviews
$existing_rulesparameter ofWP_Rewrite::random_rewrite_rules().wp_rewrite_random_base_is_takenfilter. The existingrandom_rewrite_rulesfilter can remove the root rule.Trac ticket: https://core.trac.wordpress.org/ticket/66630
Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Opus 5.5 Medium
Used for: Code, tests, running code on test box. Reviewed and manually tested by me prior to marking this PR ready for review.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.