[wp-testers] Changes

Jason Webster jason at intraffic.net
Tue Jul 15 16:13:56 GMT 2008


You may want to look into the WP function maybe_unserialize().

It'll safeguard you from any caching mixups. Also of note, WP provides a 
few other handy functions w/r/t serialization, such as is_serialized().

Duane Storey wrote:
> I've having some problems with a plugin I wrote and version 2.6.  It
> now appears that when saving or getting options from wordpress, that
> somewhere an implicit serialize or unserialize is happening.
>
> Here's a bit of code with a bit of debug around it.
>
>             print_r($a);
>             $values = serialize($a);
>             print_r($values);
>             update_option('bnc_iphone_pages', $values);
>             $x = get_option('bnc_iphone_pages');
>             print_r($x);
>
> the value of $a at the beginning is:
>
> Array ( [enable-main-home] => 1 [enable-main-rss] => 1
> [enable-main-email] => 1 [enable-main-name] => 0 [enable-main-tags] =>
> 0 [enable-main-categories] => 1 [main_title] => Book.png
> [header-background-color] => 222222 [header-text-color] => eeeeee
> [link-color] => 006bb3 )
>
> After it's serialized (the second line), it looks like this:
>
> a:10:{s:16:"enable-main-home";i:1;s:15:"enable-main-rss";i:1;s:17:"enable-main-email";i:1;s:16:"enable-main-name";i:0;s:16:"enable-main-tags";i:0;s:22:"enable-main-categories";i:1;s:10:"main_title";s:8:"Book.png";s:23:"header-background-color";s:6:"222222";s:17:"header-text-color";s:6:"eeeeee";s:10:"link-color";s:6:"006bb3";}
>
> Which is an array, as expected.  Next, I updated the field in the
> database using update_option.  After, I read it back using get_option.
>  Now, when I output it, it's an array and not a serialized test
> string:
>
> Array ( [enable-main-home] => 1 [enable-main-rss] => 1
> [enable-main-email] => 1 [enable-main-name] => 0 [enable-main-tags] =>
> 0 [enable-main-categories] => 1 [main_title] => Book.png
> [header-background-color] => 222222 [header-text-color] => eeeeee
> [link-color] => 006bb3 )
>
> This causes problems because the rest of the code assumes it's
> serialized, and the unserialize method doesn't like an array being
> past it.
>
> Does anyone know if the code has changed in core for 2.6?  It looks
> like this might have to do with some cache code in the options code in
> 2.6.
>
> Thanks,
> Duane
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>   



More information about the wp-testers mailing list