Pinoy.ca
Member
Posted 3 years ago #
One of my plugins broke when I upgrade to 2.6 yesterday. Here's the code:
// serialize and save
$recently_viewed_posts = serialize($recently_viewed_posts_array);
if (get_option('recently_viewed_posts'))
update_option('recently_viewed_posts', $recently_viewed_posts);
else
add_option('recently_viewed_posts', $recently_viewed_posts);
// get and unserialize
$recently_viewed_posts = get_option('recently_viewed_posts');
$recently_viewed_posts_array = unserialize($recently_viewed_posts);
$recently_viewed_posts becomes set as an Array, Why?? Can you see what's wrong?
Steveorevo
Member
Posted 3 years ago #
I had the same problem. Looks like it automatically unserializes the information for you. I don't know if the previous versions of WordPress were meant to do this by default and if the un/serialize was just redundant on our part. Can anyone answer that? I implemented a fix with get_option to just ignore unserialize if the version is 2.6 (or 2.6.1)...
global $wp_version;
if (strpos($wp_version,"2.6")!==false){
$this->options = get_option("stuff");
}else{
$this->options = unserialize(get_option("stuff"));
}
Steveorevo
Member
Posted 3 years ago #
Doing this will break 2.6.1, they apparently fixed the problem. I would suggest using this code instead:
global $wp_version;
if ($wp_version=="2.6"){
$this->options = get_option("stuff");
}else{
$this->options = unserialize(get_option("stuff"));
}
This will ensure that you only use the already unserialized code in version 2.6.