[wp-trac] [WordPress Trac] #58249: Improve "get_metadata_raw()" by Delegating "$single" Handling to Filter
WordPress Trac
noreply at wordpress.org
Wed May 3 23:19:44 UTC 2023
#58249: Improve "get_metadata_raw()" by Delegating "$single" Handling to Filter
--------------------------------+-----------------------------
Reporter: donglijun | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------------+-----------------------------
In the current implementation of the `get_metadata_raw()` function, after
obtaining the result from the `get_{$meta_type}_metadata` filter, the code
checks `$single` and `is_array()` and may
[https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/meta.php#L633 return the first element of the result instead of
the entire result]. This can cause unnecessary ambiguity when the
retrieved meta value from filter is an array which is serialized and
stored in database.
It appears that `get_metadata_raw()` assumes the
`get_{$meta_type}_metadata` filter will
[https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/meta.php#L657 unserialize the meta value], but not handle the
`$single` parameter.
To improve clarity and efficiency, I recommend delegating the
responsibility of handling the `$single` logic to the
`get_{$meta_type}_metadata` filter. This change will streamline the
`get_metadata_raw()` function and provide more consistent handling of meta
values.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58249>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list