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

WordPress Trac noreply at wordpress.org
Sat Feb 24 16:17:32 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
--------------------------------+------------------------------
Changes (by azaozz):

 * keywords:   => close


Comment:

 Hi @diegoliv thanks for the suggestions.

 Imho this works quite well as it is now.

 > You need to turn your javascript object into a string (JSON.stringify)
 if you want to store it on the database.

 Correct, or you can use another format like CSV if it makes more sense for
 your particular case.

 > You need to handle sanitization yourself

 Correct, that's the best way to do it. You know what data to expect and
 when it would be "out of bounds".

 > If you get the metadata using get_post_meta(), it won't apply
 maybe_unserialize() before returning the metadata, you need to do it
 yourself.

 `maybe_unserialize()` is a terrible way to do things. It only exists
 because of back compat. The less it's used -- the better.

 Storing the data in a string format of your choice is the proper way here
 simply because you know what format to expect and how to sanitize it. I
 wish we could do that for all meta :)

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


More information about the wp-trac mailing list