[wp-trac] [WordPress Trac] #43392: Support associative array type in register_meta()

WordPress Trac noreply at wordpress.org
Tue Feb 27 04:51:13 UTC 2018


#43392: Support associative array type in register_meta()
--------------------------------+------------------------------
 Reporter:  diegoliv            |       Owner:
     Type:  enhancement         |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:  4.9.4
 Severity:  normal              |  Resolution:
 Keywords:  close               |     Focuses:  rest-api
--------------------------------+------------------------------

Comment (by diegoliv):

 Hey @azaozz thank you for the response! I think I agree with you regarding
 `maybe_unserialize()` and about handling sanitization yourself if you're
 returning a more complex object. But what about a simple JSON object? a
 JSON object is not the same thing as a javascript object. A JS object
 might have simple properties or functions as properties. This would not be
 a good object to store in the database, of course. But a plain JSON object
 is really equivalent as an associative array in PHP. It's just a
 collection of simple properties like `'key' : 'value'`. Returning this
 kind of object through Ajax, you end up with an associative array anyways
 (inside the `$_POST` or `$_REQUEST` globals).

 We can easily save associative arrays already with `update_post_meta()`.
 Just throw an array as the value and WP automatically saves it into a
 proper format (a serialized string) on the database. And using
 `get_post_meta()`, your serialized array is automatically converted back
 into an array. Is there any strong reason not to allow this same behavior
 for meta data updated through the REST API?

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


More information about the wp-trac mailing list