[wp-hackers] How do you store multiple plugin options

Mike Schinkel mikeschinkel at newclarity.net
Wed Mar 24 20:21:39 UTC 2010

On Mar 24, 2010, at 3:43 PM, Otto wrote:
> On Wed, Mar 24, 2010 at 2:34 PM, Mike Schinkel
> <mikeschinkel at newclarity.net> wrote:
>> ...it will corrupt the data from PHP's unserialize perspective because the string lengths will no longer be correct.
>> Is there some other way to update PHP Serialized arrays directly in MySQL that I do not know about?
> No, you just don't have to care about that. Unserializing an array
> with a wrong string length generates a Notice error, but the
> unserialize is still successful. And the maybe_unserialize() function
> suppresses errors on the call to unserialize. So it'll still work and
> the string size will get fixed the next time the option is updated.

Thanks for the clarification.

So does WordPress do maybe_unserialize() everywhere it unserializes to ensure the errors are suppressed?

My takeaway is that it's an acceptable hack at time while at other times it can result in data of actual data.  For example, if I wanted to change one but not all similar values in a complex option I could easily overwrite other data that I hadn't intended to overwrite.

So all options in one array, though having numerous benefits, are not a panacea and are not appropriate in all cases.


More information about the wp-hackers mailing list