Make WordPress Core

Ticket #25015: 25015.patch

File 25015.patch, 2.9 KB (added by jdgrimes, 11 years ago)

First pass at this. Moves the cache updating to inside the if ( $result ) blocks.

  • src/wp-includes/option.php

     
    244244        $newvalue = maybe_serialize( $newvalue );
    245245
    246246        do_action( 'update_option', $option, $oldvalue, $_newvalue );
    247         if ( ! defined( 'WP_INSTALLING' ) ) {
    248                 $alloptions = wp_load_alloptions();
    249                 if ( isset( $alloptions[$option] ) ) {
    250                         $alloptions[$option] = $newvalue;
    251                         wp_cache_set( 'alloptions', $alloptions, 'options' );
    252                 } else {
    253                         wp_cache_set( $option, $newvalue, 'options' );
    254                 }
    255         }
    256247
    257248        $result = $wpdb->update( $wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) );
    258249
    259250        if ( $result ) {
     251                if ( ! defined( 'WP_INSTALLING' ) ) {
     252                        $alloptions = wp_load_alloptions();
     253                        if ( isset( $alloptions[ $option ] ) ) {
     254                                $alloptions[ $option ] = $newvalue;
     255                                wp_cache_set( 'alloptions', $alloptions, 'options' );
     256                        } else {
     257                                wp_cache_set( $option, $newvalue, 'options' );
     258                        }
     259                }
     260
    260261                do_action( "update_option_{$option}", $oldvalue, $_newvalue );
    261262                do_action( 'updated_option', $option, $oldvalue, $_newvalue );
    262263                return true;
     
    316317        $value = maybe_serialize( $value );
    317318        $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
    318319        do_action( 'add_option', $option, $_value );
    319         if ( ! defined( 'WP_INSTALLING' ) ) {
    320                 if ( 'yes' == $autoload ) {
    321                         $alloptions = wp_load_alloptions();
    322                         $alloptions[$option] = $value;
    323                         wp_cache_set( 'alloptions', $alloptions, 'options' );
    324                 } else {
    325                         wp_cache_set( $option, $value, 'options' );
    326                 }
    327         }
    328320
    329         // This option exists now
    330         $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
    331         if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    332                 unset( $notoptions[$option] );
    333                 wp_cache_set( 'notoptions', $notoptions, 'options' );
    334         }
    335 
    336321        $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $value, $autoload ) );
    337322
    338323        if ( $result ) {
     324                if ( ! defined( 'WP_INSTALLING' ) ) {
     325                        if ( 'yes' == $autoload ) {
     326                                $alloptions = wp_load_alloptions();
     327                                $alloptions[ $option ] = $value;
     328                                wp_cache_set( 'alloptions', $alloptions, 'options' );
     329                        } else {
     330                                wp_cache_set( $option, $value, 'options' );
     331                        }
     332                }
     333
     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[ $option ] ) ) {
     337                        unset( $notoptions[ $option ] );
     338                        wp_cache_set( 'notoptions', $notoptions, 'options' );
     339                }
     340
    339341                do_action( "add_option_{$option}", $option, $_value );
    340342                do_action( 'added_option', $option, $_value );
    341343                return true;