[wp-trac] [WordPress Trac] #44497: get_page_link() doesn't check if a valid post object is returned before trying to access its properties
WordPress Trac
noreply at wordpress.org
Wed Mar 18 11:38:24 UTC 2026
#44497: get_page_link() doesn't check if a valid post object is returned before
trying to access its properties
-------------------------------+-----------------------------
Reporter: rodrigosprimo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: Posts, Post Types | Version:
Severity: normal | Resolution:
Keywords: needs-refresh | Focuses:
-------------------------------+-----------------------------
Comment (by rodrigosprimo):
Hi @westonruter, thanks for your input on this ticket!
Is there a particular reason you suggested returning an empty string? I'm
asking because I'm wondering if returning `false` would be better. It is a
clearer signal to callers that something went wrong, and it would be
consistent with other functions in the same file, like `get_permalink()`,
`get_post_permalink()`, and `wp_get_canonical_url()`, which all return
`false` when the post is invalid.
That said, returning `false` would technically change the current
behavior. Right now, the function returns a truthy string (`"?page_id="`
appended to the home URL) accompanied by PHP warnings. However, since that
string is a broken URL, any code that depends on its truthiness would
already produce broken links, so I guess the practical impact is minimal.
But still something to consider.
While reviewing `link-template.php` to work on this fix, I noticed that a
few other functions in the same file have the same issue as
`get_page_link()` and `_get_page_link()`:
- `permalink_anchor()`
- `get_attachment_link()`
- `the_shortlink()`
Would you prefer that I address those in this same ticket, in a separate
ticket, or are they not worth fixing?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44497#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list