Opened 22 months ago
Last modified 18 months ago
#60646 new defect (bug)
Docs: Incorrect return type specified for get_post_custom with negative post ID value
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | trivial | Version: | 5.8 |
| Component: | Posts, Post Types | Keywords: | good-first-bug has-patch |
| Focuses: | docs | Cc: |
Description
On the documentation page for get_post_custom, the return type section says:
"False for an invalid $post_id (non-numeric, zero, or negative value)."
https://developer.wordpress.org/reference/functions/get_post_custom/
However, the function applies absint to the $post_id. So if its value would be negative (i.e. -10), this would be converted a positive value (10), and get_post_meta would be called for that post. This post ID can then either exists (resulting in an array being returned) or not (empty string).
Perhaps a negative numerical value should not converted? There's a potential for mix-ups? If we keep the code as is, the docs should probably specify that negative values are converted to positive.
Change History (4)
This ticket was mentioned in PR #6237 on WordPress/wordpress-develop by @nant82.
21 months ago
#3
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/60646
- Docblock of functions
get_post_meta()andget_post_custom()edited to correspond to negative value of the parameter $post_id - Default value added in docblock of
get_post_custom()for parameter $post_id
The incorrect docs were added in [52795] / #55249
It was added because the underlying
get_post_metaandget_metadata_rawfunctions have the same note about negative values. Introduced in [50641] / #51797. Thus setting the version here to 5.8.So the problem is a bit more widespread and the docblock needs to be updated for more functions than just
get_post_custom. There are about 8 occurrences of "(non-numeric, zero, or negative value)" in core at the moment .