[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 23:09:39 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: 6.7
Component: Options, Meta APIs | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses: docs
------------------------------------------+---------------------
Comment (by azaozz):
> there is some undocumented type juggling for some meta values
Yep, this is pretty much the same behavior when saving and retrieving
options. As the [https://codex.wordpress.org/Database_Description
meta_value columns] are set to `LONGTEXT`, all values seem to be converted
to strings on saving to the DB. Then non-serialized values are returned as
read from the DB.
> I believe this behavior was not introduced recently
Right. This has been like that "forever" afaik.
> I suggest that the DocBlock for those functions is updated to document
this behavior explicitly
Yea, don't think anything else can be done at this point. I actually tried
to make options saving and retrieving to respect data types, but at the
end there were too many edge cases that it became risky and not practical.
A good docblock update for the different meta fields (post, comment, user,
site, etc.) would include the full description about what's going on, and
probably mention that the unexpected types can be avoided at the cost of a
tiny bit more processing if the data is serialized. JSON encoding would
also work in most cases, but may behave a bit unexpectedly when
differentiating between objects and associative arrays.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61950#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list