Repository navigation
Random Redirects: random post type archives. - #15838
peterwilsoncc wants to merge 24 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. |
aaronjorbin
left a comment
There was a problem hiding this comment.
Generally looks good. A couple of places where a more strict than current core phpstan flagged.
| * | ||
| * @return array<string, array{0: string, 1: array<string, mixed>}> | ||
| */ | ||
| public static function data_post_type_archive_at_the_random_base_is_not_redirected(): array { |
There was a problem hiding this comment.
nit: This is extremely close to data_single_post_of_a_post_type_at_the_random_base_is_not_redirected. I think combining the two could make maintaince a bit easier.
Co-authored-by: Aaron Jorbin <aaronjorbin@users.noreply.github.com>
|
Superseded by #15959 |
…les. A post type whose archive is at the random base, by name, rewrite slug or `has_archive`, kept its rewrite rule but had the rule's query replaced by the random content query. As a result `/random/` either redirected to random content or returned a 404 instead of displaying the post type archive. The same applied to any rule a plugin added to the top using the same regex as a random content rule. Random content rules using the same regex as a rule added to the top, including post type and taxonomy rules, are now omitted when the rewrite rules are generated. Developed in: #15959 and #15838 Follow-up to r64402. Props peterwilsoncc, jorbin, ssebuwufumoses, aryanjasala. Fixes #66630. See #64498. git-svn-id: https://develop.svn.wordpress.org/trunk@65441 602fd350-edb4-49c9-b593-d223f7449a82
…les. A post type whose archive is at the random base, by name, rewrite slug or `has_archive`, kept its rewrite rule but had the rule's query replaced by the random content query. As a result `/random/` either redirected to random content or returned a 404 instead of displaying the post type archive. The same applied to any rule a plugin added to the top using the same regex as a random content rule. Random content rules using the same regex as a rule added to the top, including post type and taxonomy rules, are now omitted when the rewrite rules are generated. Developed in: WordPress/wordpress-develop#15959 and WordPress/wordpress-develop#15838 Follow-up to r64402. Props peterwilsoncc, jorbin, ssebuwufumoses, aryanjasala. Fixes #66630. See #64498. Built from https://develop.svn.wordpress.org/trunk@65441 git-svn-id: http://core.svn.wordpress.org/trunk@64580 1a063a9b-81f0-0310-95a4-ce76da25c4cd

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.