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

WordPress Trac noreply at wordpress.org
Mon Nov 13 01:24:14 UTC 2017


#38323: Reconsider $object_subtype handling in `register_meta()`
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  5.0
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-unit-tests 2nd-      |     Focuses:  rest-api
  opinion                                        |
-------------------------------------------------+-------------------------
Changes (by flixos90):

 * milestone:  Awaiting Review => 5.0


Comment:

 [attachment:38323.4.diff] is a refreshed patch based on
 [attachment:38323.diff]. @kadamwhite and I recently revisited this ticket
 and agreed that, for the first iteration the patch should remain simple to
 focus on the functionality. We could still add a class structure to some
 of it at a later stage, if it makes sense.

 Compared to the original things the following things are changed:

 * The new function `get_object_subtype()` now uses logic that is currently
 part of `map_meta_cap()` already. I just noticed that while reviewing, so
 apparently this part of core still supports object subtypes already (maybe
 this was overlooked in the revert [38095]?). Anyway, that's good for us -
 I took the logic from there and put it in the new function, which as
 mentioned before is now also used by several other metadata functions that
 interact with an object ID. In addition, there's a new filter
 `get_object_subtype_{$object_type}` that allows devs to enhance the
 function for custom object types they might possibly have built (think
 about a custom database table where each object has an ID and the core
 metadata API should be used to extend it with arbitrary additional data).
 * The `sanitize_{$object_type}_meta_{$meta_key}` filter is not passed the
 subtype (as in the original patch), since it should only be used for
 sanitization that is independent of a subtype. We might consider adding
 that back in at some point (because it ''can'' have a purpose), but let's
 leave it out for now for simplicity's sake and since the other new filter
 already covers that use-case.
 * Version numbers have been updated to use 5.0.

 We should start working on unit tests soon. The tests in
 [attachment:38323.2.diff] do not actually test any subtype behavior, but
 they may very well be useful as a foundation for writing those ones that
 deal with the REST API part. We still need basic tests for
 `register_meta()` and the other related functions dealing with object
 subtypes.

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


More information about the wp-trac mailing list