I’m checking out how a particular plugin works and noticed that it stores its data for option_value in wp_options in this array format…
a:2:{i:20;a:2:{s:8:”original”;s:15:”20.original.jpg”;s:9:”thumbnail”;s:12:”20.thumb.jpg”;}i:8;a:2:{s:8:”original”;s:14:”8.original.png”;s:9:”thumbnail”;s:11:”8.thumb.png”;}}
I like this method, since it only uses a single row to hold my custom data, uninstall cleanup is easy. Is there a standard way to do a get/set operation on a custom field that results in this syntax?
Update: Thanks to Denis and the others who’ve added responses.
Here’s an excellent tutorial on this method in case anyone else has this question > http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Just pass an array when updating your option. It will be serialized automatically.
Method 2
The serialization is done automatically, but if you want to know how to do this manually the function to look at is called serialize()
Method 3
As per other answers (un)serialization is performed automatically on more complex data formats (arrays, objects) when options are stored or retrieved. This also applies to transients and other functionality.
Technically this is performed by internal usage maybe_serialize() and maybe_unserialize() functions that try to determine if data needs to be processed or passed as is.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0