[wp-trac] [WordPress Trac] #35658: Provide additional data for registered meta through register_meta()

WordPress Trac noreply at wordpress.org
Tue Jun 28 02:25:06 UTC 2016


#35658: Provide additional data for registered meta through register_meta()
-------------------------------------------------+-------------------------
 Reporter:  jeremyfelt                           |       Owner:  jeremyfelt
     Type:  enhancement                          |      Status:  assigned
 Priority:  normal                               |   Milestone:  4.6
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  needs-unit-tests needs-testing has-  |     Focuses:
  patch rest-api                                 |
-------------------------------------------------+-------------------------

Comment (by MikeSchinkel):

 Looking the most recent patch (35658.4.diff) on line 967 I notice the
 addition of a a `$subtype`.

 That worries me because it portends a proliferation of extra optional
 parameters having to be passed around making function signatures more
 complicated and harder to remember.

 Our team went down that path with our Sunrise library several years ago
 and it was probably the biggest architectural mistake we made.  What we
 found was that we ended up having to pass two values around as we were
 building plugins and it was an explosion of complexity that you can start
 to see in the patch. I explained it
 [https://bitbucket.org/newclarity/sunrise-1/overview '''here'''].

 Of course it took several years painful experience to realize we had made
 that mistake; it really did seem like a great idea at the time.

 What we found wat that moving to a single value that encapsulated
 subvalues worked much better.

 So instead please consider creating a combined type in one string in the
 form "{type}:{subtype}", or just "{type}" which defaults "{subtype}" to
 "any".

 I have created an updated patch as [/attachment/ticket/35658/35658.5.diff
 35658.5.diff] that adds a `WP_Object_Type` class to WordPress core. It has
 a `__toString()` method so it can be used as a string.  Using this class
 makes it easy to add subtype support in a backward compatible way to any
 functions that currently support a post type or other type and it gets rid
 of duplicate code like the following from the patch because it makes it
 the responsibility of the `WP_Object_Type` object to police itself:

 {{{
 if ( empty( $object_subtype ) || 'post' !== $object_type ) {
                 $object_subtype = $object_type;
 }

 if ( ! in_array( $object_type, array( 'post', 'comment', 'user', 'term' )
 ) ) {
         return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key.
 Not a core object type.' ) );
 }
 }}}

 BTW, we built this class so we could implement Object Relationships and it
 is really needed there ''(which hopefully WordPress will add sometime
 soon.)''

 I am really hoping the core committers will consider this.  There is about
 7 years worth of WordPress-specific engineering behind this use-case.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35658#comment:63>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list