[wp-trac] [WordPress Trac] #61950: add_*_meta()/get_*_meta() undocumented type juggling for some meta values
WordPress Trac
noreply at wordpress.org
Wed Aug 28 18:21:08 UTC 2024
#61950: add_*_meta()/get_*_meta() undocumented type juggling for some meta values
--------------------------------+-----------------------------
Reporter: rodrigosprimo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version:
Severity: normal | Keywords:
Focuses: docs |
--------------------------------+-----------------------------
While working on a new WPCS sniff related to the `get_*_meta()` functions
(https://github.com/WordPress/WordPress-Coding-Standards/pull/2465), I
noticed there is some undocumented type juggling for some meta values.
For example, WP returns an empty string for an object meta created as
`false`.
Here are all the cases that I found:
||=Value added via `add_*_meta()`=||=Value returned by `get_*_meta()`=||
|| `false` || `''` ||
|| `true` || `'1'` ||
|| `0` || `'0'` ||
|| `1.5` || `'1.5'` ||
I haven't checked, but I believe this behavior was not introduced
recently, so changing it would be a breaking change and not really an
option. That being said, I suggest that the DocBlock for those functions
is updated to document this behavior explicitly. It is probably a good
idea to add some tests as well to prevent unexpected changes in the
future.
The description of the `$meta_value` parameter of those functions is
"Metadata value. Must be serializable if non-scalar." An initial
suggestion is to change it to mention the special cases listed above.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61950>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list