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

WordPress Trac noreply at wordpress.org
Fri Aug 10 07:00:45 UTC 2018


#43392: Support associative array type in register_meta()
--------------------------------+------------------------------
 Reporter:  diegoliv            |       Owner:  (none)
     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:7 mnelson4]:

 Lets break this up a bit:

 > Input from the API client needs to always be a JSON array,
 Good.

 > which is easily converted into a PHP array, and then can be stored
 easily via serialization.
 Bad. :)

 Why would you convert one way of storing an object into a string (JSON) to
 another way of storing the same object into a string (serialization)? This
 doesn't solve any of the shortcomings as it still adds an associative
 array to the DB that needs to be serialized before storing.

 Note: the problem here is not with `maybe_serialize()` when saving to the
 DB, it is with `maybe_unserialize()` when retrieving the data from the DB.

 As mentioned before (and in many other places) the ideal solution would be
 to add another field to the meta table(s) where we can store the data
 format. It can be a `TINYINT` (0 to 255) that only takes 1 byte of space.
 I know, large sites with huge tables will still hate this, but...?

 Another possible (but much worse) solution would be to prepend or append
 the encoding format to the actual string at the last moment, and remove it
 as soon as the data is retrieved. This has the disadvantage of introducing
 some back-compat problems (perhaps only with SQL exports and imports) but
 is not "totally impossible" to implement.

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


More information about the wp-trac mailing list