Repository navigation
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. |
Applies patch from WordPress#9040 to fix get_boundary_post() function when called from non-singular pages
|
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:
|
lancewillett
left a comment
There was a problem hiding this comment.
Removing the ! $post guard also allows get_boundary_post( true ) to continue without a current post. The same-term branch then dereferences $post->ID. Please retain a missing-post guard for that path and cover it alongside the intended non-singular success case.
AI review · gpt-6
lancewillett
left a comment
There was a problem hiding this comment.
The missing-post guard is restored, and the new regression exercises the exact failing path. The boundary and neighboring adjacent-post tests pass locally in randomized single-site and multisite runs: 22 tests, 114 assertions per mode, with no skips. Removing only the guard reproduces the null-property error; restoring it passes the same focused case. Current CI is green.
Optional: the existing adjacent-post suite already covers single-post and same-term first/last IDs, so those overlapping assertions can be trimmed without adding more cases. The missing-post and non-singular checks provide the useful new coverage.
AI review · gpt-6
There was a problem hiding this comment.
🟡 Changes recommended
The tests omit boundary-post retrieval without a current post when $in_same_term = false, allowing an unconditional ! $post guard regression to pass unnoticed.
1 open issue
What changed in this PR
Extends get_boundary_post() to work on non-singular pages, addressing Trac #22957, and adds regression tests for boundary selection and existing behavior.
Changes:
- Removes the single-post restriction and requires a current post only for same-term queries.
- Adds tests for homepage, archive, single-post, same-term, missing-post, and invalid-taxonomy behavior.
| File | Description |
|---|---|
tests/phpunit/tests/link/getBoundaryPost.php |
Adds boundary-post tests across page contexts and parameter combinations. |
src/wp-includes/link-template.php |
Relaxes page-context restrictions while retaining taxonomy and same-term validation. |
Review effort: Balanced
| $this->go_to( home_url( '/?s=no-matching-posts' ) ); | ||
| $this->assertNull( get_post(), 'This test should be running without a current post.' ); | ||
|
|
||
| $this->assertNull( get_boundary_post( true ) ); |
Allow `get_boundary_post()` to return the first or last post on non-singular pages. Retain the missing-post guard when `$in_same_term` needs a current post, and continue rejecting unknown taxonomies. Add coverage for non-singular lookups and the missing-post case. Developed in: #9200, #9040 Props pathawks, sirlouen, iamadisingh, mukesh27, devasheeshkaul. Fixes #22957. git-svn-id: https://develop.svn.wordpress.org/trunk@65151 602fd350-edb4-49c9-b593-d223f7449a82
Allow `get_boundary_post()` to return the first or last post on non-singular pages. Retain the missing-post guard when `$in_same_term` needs a current post, and continue rejecting unknown taxonomies. Add coverage for non-singular lookups and the missing-post case. Developed in: WordPress/wordpress-develop#9200, WordPress/wordpress-develop#9040 Props pathawks, sirlouen, iamadisingh, mukesh27, devasheeshkaul. Fixes #22957. Built from https://develop.svn.wordpress.org/trunk@65151 git-svn-id: http://core.svn.wordpress.org/trunk@64300 1a063a9b-81f0-0310-95a4-ce76da25c4cd

Trac ticket: #22957
Patch used: #9040
Description
Added unit tests that verify
get_boundary_post()works correctly from non-singular pages (homepage, archive pages) and maintains backward compatibility with single post pages.Testing Instructions:
Run the following command to verify the tests:
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.