08
Nov 12

WordPress Update_option and serialize

I ran into this interesting feature yesterday I was not aware of. If you are trying to put options WordPress using Update_option serializing the data before actually causes unexpected behaviour.

The catch is that WordPress already serializes data send to the function. When invoking get_option the data will be unserialized. Obviously this causes an error if you try to unserialize the whole thing after that.

In short, just push an unserialized array unto update_option and everything will be fine!

 update_option("stuff",array('foo','bar'));
$foobar = get_option("stuff");

See this blog post for more backgrounds.