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

WordPress Trac noreply at wordpress.org
Wed Feb 28 20:24:17 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 azaozz):

 Replying to [comment:3 diegoliv]:
 > 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.

 This is the exact bit that uses `maybe_unserialize()`.

 > Is there any strong reason not to allow this same behavior for meta data
 updated through the REST API?

 Well, if we want to avoid stuff like `maybe_json_decode()` :)

 I wish there was an easy way to specify the format of an encoded string in
 the meta table, but there isn't. The only other option is to "guess" the
 encoding, which is..... subpar.

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


More information about the wp-trac mailing list