[wp-trac] [WordPress Trac] #45329: get_post_permalink tries is_wp_error on get_post which it will never be
WordPress Trac
noreply at wordpress.org
Wed Jul 20 15:39:33 UTC 2022
#45329: get_post_permalink tries is_wp_error on get_post which it will never be
------------------------------------------+-----------------------------
Reporter: renegeuze | Owner: SergeyBiryukov
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 6.1
Component: Posts, Post Types | Version:
Severity: normal | Resolution: fixed
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+-----------------------------
Changes (by SergeyBiryukov):
* owner: (none) => SergeyBiryukov
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"53733" 53733]:
{{{
#!CommitTicketReference repository="" revision="53733"
Posts, Post Types: Correct the check for non-existing post in
`get_post_permalink()`.
The function was erroneously calling `is_wp_error()` on the result of a
`get_post()` call, which returns `null` on failure, and never returns a
`WP_Error` object.
Previously, passing a non-existing post ID to the function would result in
a home URL being returned and a few `Attempt to read property "post_type,
post_name, hierarchical..." on null` PHP warnings.
This commit ensures `get_post_permalink()` returns `false` on failure,
which brings parity with `get_permalink()`.
Includes a unit test to confirm the correct behavior.
Follow-up to [12923], [13023], [32606].
Props renegeuze, manzoorwani.jk.
Fixes #45329.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45329#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list