WordPress.org

Ready to get started?Download WordPress

Forums

2.6 bug with get_option and update_option? (3 posts)

  1. Pinoy.ca
    Member
    Posted 5 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?

  2. Steveorevo
    Member
    Posted 5 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"));
    }
  3. Steveorevo
    Member
    Posted 5 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.

Topic Closed

This topic has been closed to new replies.

About this Topic