Make WordPress Core

Ticket #4429: add_option_trunk.diff

File add_option_trunk.diff, 1.3 KB (added by markjaquith, 17 years ago)

add_option() fix for trunk

  • wp-includes/functions.php

     
    314314
    315315        wp_protect_special_option($name);
    316316
    317         // Make sure the option doesn't already exist we can check the cache before we ask for a db query
     317        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    318318        $notoptions = wp_cache_get('notoptions', 'options');
    319         if ( is_array($notoptions) && isset($notoptions[$name]) ) {
    320                 unset($notoptions[$name]);
    321                 wp_cache_set('notoptions', $notoptions, 'options');
    322         } elseif ( false !== get_option($name) ) {
     319        if ( !is_array($notoptions) || !isset($notoptions[$name]) )
     320                if ( false !== get_option($name) )
    323321                        return;
    324         }
    325322
    326323        $value = maybe_serialize($value);
    327324        $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
     
    334331                wp_cache_set($name, $value, 'options');
    335332        }
    336333
     334        // This option exists now
     335        $notoptions = wp_cache_get('notoptions', 'options'); // yes, again... we need it to be fresh
     336        if ( is_array($notoptions) && isset($notoptions[$name]) ) {
     337                unset($notoptions[$name]);
     338                wp_cache_set('notoptions', $notoptions, 'options');
     339        }
     340
    337341        $name = $wpdb->escape($name);
    338342        $value = $wpdb->escape($value);
    339343        $description = $wpdb->escape($description);