Make WordPress Core

Ticket #24933: 24933.diff

File 24933.diff, 5.7 KB (added by nacin, 13 years ago)
  • 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 = $newvalue;
     238        $newvalue = maybe_serialize( $newvalue );
     239
     240        $result = $wpdb->update( $wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) );
     241        if ( ! $result )
     242                return false;
     243
    237244        $notoptions = wp_cache_get( 'notoptions', 'options' );
    238245        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    239246                unset( $notoptions[$option] );
    … …  
    240247                wp_cache_set( 'notoptions', $notoptions, 'options' );
    241248        }
    242249
    243         $_newvalue = $newvalue;
    244         $newvalue = maybe_serialize( $newvalue );
    245 
    246250        do_action( 'update_option', $option, $oldvalue, $_newvalue );
    247251        if ( ! defined( 'WP_INSTALLING' ) ) {
    248252                $alloptions = wp_load_alloptions();
    … …  
    254258                }
    255259        }
    256260
    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;
     261        do_action( "update_option_{$option}", $oldvalue, $_newvalue );
     262        do_action( 'updated_option', $option, $oldvalue, $_newvalue );
     263        return true;
    265264}
    266265
    267266/**
    … …  
    312311                if ( false !== get_option( $option ) )
    313312                        return false;
    314313
    315         $_value = $value;
    316         $value = maybe_serialize( $value );
     314        $_value = maybe_serialize( $value );
    317315        $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
    318         do_action( 'add_option', $option, $_value );
     316        do_action( 'add_option', $option, $value );
     317
     318        $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 ) );
     319        if ( ! $result )
     320                return false;
     321
    319322        if ( ! defined( 'WP_INSTALLING' ) ) {
    320323                if ( 'yes' == $autoload ) {
    321324                        $alloptions = wp_load_alloptions();
    322                         $alloptions[$option] = $value;
     325                        $alloptions[$option] = $_value;
    323326                        wp_cache_set( 'alloptions', $alloptions, 'options' );
    324327                } else {
    325                         wp_cache_set( $option, $value, 'options' );
     328                        wp_cache_set( $option, $_value, 'options' );
    326329                }
    327330        }
    328331
    … …  
    333336                wp_cache_set( 'notoptions', $notoptions, 'options' );
    334337        }
    335338
    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;
     339        do_action( "add_option_{$option}", $option, $value );
     340        do_action( 'added_option', $option, $value );
     341        return true;
    344342}
    345343
    346344/**
    … …  
    829827
    830828                $value = sanitize_option( $option, $value );
    831829
     830                $_value = maybe_serialize( $value );
     831                $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $_value ) );
     832
     833                if ( ! $result )
     834                        return false;
     835
    832836                wp_cache_set( $cache_key, $value, 'site-options' );
    833837
    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 
    839838                // This option exists now
    840839                $notoptions = wp_cache_get( 'notoptions', 'site-options' ); // yes, again... we need it to be fresh
    841840                if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    … …  
    934933                $result = update_option( $option, $value );
    935934        } else {
    936935                $value = sanitize_option( $option, $value );
    937                 $cache_key = "{$wpdb->siteid}:$option";
    938                 wp_cache_set( $cache_key, $value, 'site-options' );
    939936
    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;
     937                $_value = maybe_serialize( $value );
     938                $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) );
     939
     940                if ( $result ) {
     941                        $cache_key = "{$wpdb->siteid}:$option";
     942                        wp_cache_set( $cache_key, $value, 'site-options' );
     943                }
    944944        }
    945945
    946946        if ( $result ) {