[wp-trac] [WordPress Trac] #38323: Reconsider $object_subtype handling in `register_meta()`
WordPress Trac
noreply at wordpress.org
Mon Feb 6 20:51:20 UTC 2017
#38323: Reconsider $object_subtype handling in `register_meta()`
-------------------------------------------------+-------------------------
Reporter: flixos90 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
Component: Options, Meta APIs | Review
Severity: normal | Version:
Keywords: has-patch needs-unit-tests 2nd- | Resolution:
opinion | Focuses:
-------------------------------------------------+-------------------------
Comment (by flixos90):
I worked on a new patch [attachment:38323.3.diff] with an updated behavior
taking the previous comments into account and works quite differently from
the original patch.
The patch introduces a new class `WP_Meta_Key` that improves how the
registered meta information is stored. It could possibly be used to get
rid of the global `$wp_meta_keys` too (through a static property) although
the current patch doesn't do this.
In the patch the `$wp_meta_keys` global is still indexed by object type
and then by meta key, similar like it is now. However instead of storing
the array of `$args` for each `$meta_key`, an instance of `WP_Meta_Key` is
stored, that includes all registered information for that key, whether
global for an entire object type or specific to an object subtype. The
class also ensures that it is impossible to register a meta key for an
object type if that meta key is already registered for that object type in
any other way, so it eliminates the problem of possibly having a meta key
being registered for both the entire object type and a specific subtype of
that object type. When retrieving registered meta for a specific subtype
though, the class methods automatically fall back to meta registered to
the entire object type if meta for the subtype is not available.
A short note on the naming: I called each set of `$args` for a meta key a
"definition set". I don't think it's a great name, but I didn't wanna
spend time thinking about a better one for now, and this can easily be
refactored later.
@kadamwhite Let's definitely chat on how to handle this topic. Regarding
using `register_meta()` vs `register_post_type()`, I think
`register_meta()` is a more suitable location to manage these. Also, I
know it's probably a bit too early for a patch since we still need to
figure out several things, but I was in the mood to try things out. :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38323#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list