fix: page-by-URI over-resolution and homepage resolution in subdirectory installs#3965
Merged
Conversation
…URIs Typed `idType: URI` fields (page, post, contentNode, and other post type single fields) pre-seed the target `post_type` into the query vars before running WP_Query. When the requested path does not match a rewrite rule, parse_request() flags a 404 but the pre-seeded `post_type` turns the request into an unbounded query, so WP_Query returns an arbitrary post. nodeByUri, which passes no extra query vars, correctly returns null for the same path. The 404 guard in resolve_uri() was gated on `empty( $extra_query_vars )`, so it only ran for nodeByUri and never for typed fields. Refine the guard to bail on a 404 unless the request is an explicit slug lookup (idType: SLUG), which passes a `name` and intentionally resolves by post_name without requiring the full path to match a rewrite rule. Adds a regression test asserting typed idType:URI and nodeByUri resolve a hierarchical page consistently: a partial/wrong-hierarchy URI returns null for both, and a same-slug-different-parent URI resolves the correct node. Closes #3042
When WordPress is installed in a subdirectory, the full home URL (e.g. `/blog/`) resolved to null. Only a literal `/` was treated as the home page; for the full home URL, parse_request() strips the home path and leaves an empty request, which resolve_uri() did not recognize as home. Detect the home page from the parsed request (an empty `$wp->request` with no node- or archive-identifying query var) in addition to the literal `/`, so the full home URL resolves regardless of the subdirectory name. The detection only applies when permalink parsing ran, so plain-permalink installs keep relying on the literal `/` check. Adds a regression test that simulates several subdirectory names (including a nested path) and asserts the full home URL resolves the front page while a real page below the home still resolves normally. Closes #3775
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jun 19, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3965 +/- ##
=======================================
Coverage 83.6% 83.6%
- Complexity 5330 5337 +7
=======================================
Files 286 286
Lines 22866 22901 +35
=======================================
+ Hits 19111 19151 +40
+ Misses 3755 3750 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two related URI-resolution bugs in
NodeResolver. They are shipped together because both live inresolve_uri()and the regression tests for each must not regress the other (the homepage-in-subdirectory case is on #3042's don't-regress list).#3042 — typed
idType: URIfields over-resolve partial/wrong-hierarchy URIsTyped
idType: URIfields (page,post,contentNode, and the per-post-type single fields) pre-seed the targetpost_typeinto the query vars before runningWP_Query. When the requested path does not match a rewrite rule,parse_request()flags a404, but the pre-seededpost_typeturns the request into an unbounded query, soWP_Queryreturns an arbitrary post.nodeByUri, which passes no extra query vars, correctly returnsnullfor the same path.The
404guard inresolve_uri()was gated onempty( $extra_query_vars ), so it only ran fornodeByUriand never for typed fields. The guard is refined to bail on a404unless the request is an explicit slug lookup (idType: SLUG), which passes anameand intentionally resolves bypost_namewithout requiring the full path to match a rewrite rule.Result:
page(id: "/child/", idType: URI)now returnsnullfor a partial or wrong-hierarchy path (matchingnodeByUri), while the correct full path still resolves, including same-slug-different-parent pages.#3775 — homepage returns null via its full URL in subdirectory installs
When WordPress is installed in a subdirectory, the full home URL (e.g.
/blog/) resolved tonull. Only a literal/was treated as the home page; for the full home URL,parse_request()strips the home path and leaves an empty request thatresolve_uri()did not recognize as the home page.The home page is now detected from the parsed request (an empty
$wp->requestwith no node- or archive-identifying query var) in addition to the literal/, so the full home URL resolves regardless of the subdirectory name. The detection only applies when permalink parsing ran, so plain-permalink installs keep relying on the literal/check.Tests
PageByUriTest::testTypedUriFieldIsConsistentWithNodeByUriForHierarchyasserts typedidType: URIandnodeByUriresolve a hierarchical page consistently: a partial/wrong-hierarchy URI returnsnullfor both, and a same-slug-different-parent URI resolves the correct node. Fails before the Querying Page by URI doest require correct URI field #3042 fix.NodeByUriTest::testHomePageResolvesByFullUrlInSubdirectoryInstallsimulates several subdirectory names (blog,wp-in-subdirectory, and a nestedcms/site) and asserts the full home URL resolves the front page while a real page below the home still resolves normally. Fails before the Getting a page by url fails when the page is the homepage, and worpress is installed inside a folder #3775 fix.Both fixes were verified to leave the existing
NodeByUriTest,PageByUriTest, andNodeBySlugTestsuites green, and the don't-regress cases (#3582 percent-encoding, #2191 date archives) continue to pass. PHPCS and PHPStan (level 8) are clean.Closes #3042
Closes #3775