Make WordPress Core

Ticket #4429: add_option_branches_2.2.diff

File add_option_branches_2.2.diff, 1.4 KB (added by markjaquith, 17 years ago)

add_option() fix for 2.2.x

  • wp-includes/functions.php

     
    354354
    355355        wp_protect_special_option($name);
    356356
    357         // Make sure the option doesn't already exist we can check the cache before we ask for a db query
     357        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    358358        $notoptions = wp_cache_get('notoptions', 'options');
    359         if ( is_array($notoptions) && isset($notoptions[$name]) ) {
    360                 unset($notoptions[$name]);
    361                 wp_cache_set('notoptions', $notoptions, 'options');
    362         } elseif ( false !== get_option($name) ) {
     359        if ( !is_array($notoptions) || !isset($notoptions[$name]) )
     360                if ( false !== get_option($name) )
    363361                        return;
    364         }
    365362
    366363        $value = maybe_serialize($value);
     364        $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
    367365
    368366        if ( 'yes' == $autoload ) {
    369367                $alloptions = wp_load_alloptions();
     
    373371                wp_cache_set($name, $value, 'options');
    374372        }
    375373
     374        // This option exists now
     375        $notoptions = wp_cache_get('notoptions', 'options'); // yes, again... we need it to be fresh
     376        if ( is_array($notoptions) && isset($notoptions[$name]) ) {
     377                unset($notoptions[$name]);
     378                wp_cache_set('notoptions', $notoptions, 'options');
     379        }
     380
    376381        $name = $wpdb->escape($name);
    377382        $value = $wpdb->escape($value);
    378383        $description = $wpdb->escape($description);