[wp-trac] [WordPress Trac] #39959: Clarify parameters for callbacks for `register_rest_field()`

WordPress Trac noreply at wordpress.org
Thu Feb 23 22:49:40 UTC 2017


#39959: Clarify parameters for callbacks for `register_rest_field()`
--------------------------+----------------------------
 Reporter:  flixos90      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  REST API      |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+----------------------------
 There is an issue going on with `register_rest_field()` in combination
 with the `WP_REST_Meta_Fields` classes: The method
 `WP_REST_Meta_Fields::register_field()` uses callbacks that accept an
 object ID only. However, the REST controller methods that handle the
 additional fields always pass an object to these callbacks.

 Working with metadata via the REST API is still possible now, since the
 `WP_REST_Meta_Fields::register_field()` method is never used in Core,
 instead metadata is handled manually by each controller. So it is now a
 minor issue, but I think we should figure out what kind of parameters the
 `register_rest_field()` callbacks can accept (I could not find anything
 clear in the documentation) and then actually use
 `WP_REST_Meta_Fields::register_field()`, as I don't think there's a point
 in handling meta manually if we have this method already available in a
 more abstracted way.

 Furthermore, this inconsistency gets more critical once developers start
 writing their own endpoints for custom object types that use their own
 metadata table. One might assume that the `WP_REST_Meta_Fields` base class
 can be leveraged to handle meta automatically, but because of the
 inconsistencies now, doing this would likely cause fatal errors and
 confusion.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39959>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list