Make WordPress Core

Ticket #24933: 24933.2.diff

File 24933.2.diff, 6.0 KB (added by ocean90, 13 years ago)

$_newvalue = maybe_serialize( $newvalue );

  • src/wp-includes/meta.php

     
    151151        if ( 'post' == $meta_type )
    152152                do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    153153
    154         $wpdb->update( $table, $data, $where );
     154        $result = $wpdb->update( $table, $data, $where );
     155        if ( ! $result )
     156                return false;
    155157
    156158        wp_cache_delete($object_id, $meta_type . '_meta');
    157159
    … …  
    435437                        do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    436438
    437439                // Run the update query, all fields in $data are %s, $where is a %d.
    438                 $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' );
     440                $result = $wpdb->update( $table, $data, $where, '%s', '%d' );
     441                if ( ! $result )
     442                        return false;
    439443
    440444                // Clear the caches.
    441445                wp_cache_delete($object_id, $meta_type . '_meta');
    … …  
    445449                if ( 'post' == $meta_type )
    446450                        do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    447451
    448                 return $result;
     452                return true;
    449453        }
    450454
    451455        // And if the meta was not found.
  • src/wp-includes/option.php

     
    234234        if ( false === $oldvalue )
    235235                return add_option( $option, $newvalue );
    236236
     237        $_newvalue = maybe_serialize( $newvalue );
     238
     239        $result = $wpdb->update( $wpdb->options, array( 'option_value' => $_newvalue ), array( 'option_name' => $option ) );
     240        if ( ! $result )
     241                return false;
     242
    237243        $notoptions = wp_cache_get( 'notoptions', 'options' );
    238244        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    239245                unset( $notoptions[$option] );
    240246                wp_cache_set( 'notoptions', $notoptions, 'options' );
    241247        }
    242248
    243         $_newvalue = $newvalue;
    244         $newvalue = maybe_serialize( $newvalue );
    245 
    246         do_action( 'update_option', $option, $oldvalue, $_newvalue );
     249        do_action( 'update_option', $option, $oldvalue, $newvalue );
    247250        if ( ! defined( 'WP_INSTALLING' ) ) {
    248251                $alloptions = wp_load_alloptions();
    249252                if ( isset( $alloptions[$option] ) ) {
    250                         $alloptions[$option] = $newvalue;
     253                        $alloptions[$option] = $_newvalue;
    251254                        wp_cache_set( 'alloptions', $alloptions, 'options' );
    252255                } else {
    253                         wp_cache_set( $option, $newvalue, 'options' );
     256                        wp_cache_set( $option, $_newvalue, 'options' );
    254257                }
    255258        }
    256259
    257         $result = $wpdb->update( $wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) );
    258 
    259         if ( $result ) {
    260                 do_action( "update_option_{$option}", $oldvalue, $_newvalue );
    261                 do_action( 'updated_option', $option, $oldvalue, $_newvalue );
    262                 return true;
    263         }
    264         return false;
     260        do_action( "update_option_{$option}", $oldvalue, $newvalue );
     261        do_action( 'updated_option', $option, $oldvalue, $newvalue );
     262        return true;
    265263}
    266264
    267265/**
    … …  
    312310                if ( false !== get_option( $option ) )
    313311                        return false;
    314312
    315         $_value = $value;
    316         $value = maybe_serialize( $value );
     313        $_value = maybe_serialize( $value );
    317314        $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
    318         do_action( 'add_option', $option, $_value );
     315        do_action( 'add_option', $option, $value );
     316
     317        $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 ) );
     318        if ( ! $result )
     319                return false;
     320
    319321        if ( ! defined( 'WP_INSTALLING' ) ) {
    320322                if ( 'yes' == $autoload ) {
    321323                        $alloptions = wp_load_alloptions();
    322                         $alloptions[$option] = $value;
     324                        $alloptions[$option] = $_value;
    323325                        wp_cache_set( 'alloptions', $alloptions, 'options' );
    324326                } else {
    325                         wp_cache_set( $option, $value, 'options' );
     327                        wp_cache_set( $option, $_value, 'options' );
    326328                }
    327329        }
    328330
    … …  
    333335                wp_cache_set( 'notoptions', $notoptions, 'options' );
    334336        }
    335337
    336         $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 ) );
    337 
    338         if ( $result ) {
    339                 do_action( "add_option_{$option}", $option, $_value );
    340                 do_action( 'added_option', $option, $_value );
    341                 return true;
    342         }
    343         return false;
     338        do_action( "add_option_{$option}", $option, $value );
     339        do_action( 'added_option', $option, $value );
     340        return true;
    344341}
    345342
    346343/**
    … …  
    829826
    830827                $value = sanitize_option( $option, $value );
    831828
     829                $_value = maybe_serialize( $value );
     830                $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $_value ) );
     831
     832                if ( ! $result )
     833                        return false;
     834
    832835                wp_cache_set( $cache_key, $value, 'site-options' );
    833836
    834                 $_value = $value;
    835                 $value = maybe_serialize( $value );
    836                 $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value ) );
    837                 $value = $_value;
    838 
    839837                // This option exists now
    840838                $notoptions = wp_cache_get( 'notoptions', 'site-options' ); // yes, again... we need it to be fresh
    841839                if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    … …  
    934932                $result = update_option( $option, $value );
    935933        } else {
    936934                $value = sanitize_option( $option, $value );
    937                 $cache_key = "{$wpdb->siteid}:$option";
    938                 wp_cache_set( $cache_key, $value, 'site-options' );
    939935
    940                 $_value = $value;
    941                 $value = maybe_serialize( $value );
    942                 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) );
    943                 $value = $_value;
     936                $_value = maybe_serialize( $value );
     937                $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) );
     938
     939                if ( $result ) {
     940                        $cache_key = "{$wpdb->siteid}:$option";
     941                        wp_cache_set( $cache_key, $value, 'site-options' );
     942                }
    944943        }
    945944
    946945        if ( $result ) {