[wp-trac] [WordPress Trac] #33068: get_post() returning current object if 0
WordPress Trac
noreply at wordpress.org
Thu Dec 3 13:47:47 UTC 2020
#33068: get_post() returning current object if 0
---------------------------------------+---------------------
Reporter: Rahe | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.7
Component: Posts, Post Types | Version: 3.5
Severity: normal | Resolution:
Keywords: needs-testing 2nd-opinion | Focuses:
---------------------------------------+---------------------
Changes (by johnbillion):
* keywords: needs-testing => needs-testing 2nd-opinion
Comment:
This is a risky change. There's definitely code out there that passes
integer `0` and expects to get the current post. Changing this would break
that code. [https://plugins.trac.wordpress.org/browser/wp-
graphql/tags/1.0/src/Model/Term.php?marks=76#L72 WPGraphQL does it
explicitly], there's bound to be many more instances of it implicitly or
where the value comes from a variable.
If your code does not check for emptiness before passing a value to
`get_post()` then it will not work as expected regardless of whether that
value is integer `0` or anything else empty. Maybe the unexpectedly empty
value is `null` instead of `0`, but if it's not being checked then you
can't be sure that `get_post()` will return what you expect.
Ideally `get_post()` would be strict about its accepted values but that
ship sailed fifteen years ago.
Personally this seems like a wontfix for backwards compatibility concerns.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33068#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list