[wp-trac] [WordPress Trac] #38323: Reconsider $object_subtype handling in `register_meta()`

WordPress Trac noreply at wordpress.org
Wed Apr 5 22:47:41 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:  rest-api
-------------------------------------------------+-------------------------

Comment (by flixos90):

 Replying to [comment:24 jnylen0]:
 > - Does `WP_User` also inherit from `WP_Object_Type`?  Probably not, but
 doesn't this indicate that `WP_Object_Type` is not actually an ancestor
 class of all the things it describes?

 `WP_User` does not and should not, but if Core ever introduces a
 `WP_User_Type` or similar, that would in my understanding.

 > - What is the functionality that's being factored out into the base
 class?  It needs to be common to as many object types as possible, at
 least the classes that inherit from it.

 `WP_Post_Type` and `WP_Taxonomy` are the only subtype classes that
 currently exist, and they already have several things in common that we
 could abstract out into `WP_Object_Type` (the constructor as well as the
 `set_props()`, `add_hooks()` and `remove_hooks()` methods for example) -
 however I think it should rather be a `WP_Subtype` class that would
 contain these methods (as mentioned in my previous comment as an
 alternative). Correcting my previous approach, I think `WP_Object_Type`
 should stand on its own as a pointer to an object type, but ''not'' a
 subtype. `WP_Subtype` should be an abstract base class that `WP_Post_Type`
 and `WP_Taxonomy` inherit; this addresses the concerns that an object type
 and subtype are something different. `register_meta()` can then just check
 whether it is a `WP_Object_Type` or `WP_Subtype` and then call the methods
 to determine which object type/subtype of object type.

 > - What if, in the future, we wanted to support registering meta for
 multiple object types at once (e.g. `post` of a certain type '''and'''
 `user`)?  Even if we don't implement this right away, this seems like
 another place where this abstraction falls apart.

 I think we could add support for that by allowing an array of objects to
 be passed to `register_meta()` once we need it.

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


More information about the wp-trac mailing list