Changeset 25664
- Timestamp:
- 10/02/2013 08:42:39 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/option.php
r25451 r25664 209 209 * 210 210 * @param string $option Option name. Expected to not be SQL-escaped. 211 * @param mixed $ newvalue Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.211 * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. 212 212 * @return bool False if value was not updated and true if value was updated. 213 213 */ 214 function update_option( $option, $ newvalue ) {214 function update_option( $option, $value ) { 215 215 global $wpdb; 216 216 … … 221 221 wp_protect_special_option( $option ); 222 222 223 if ( is_object( $newvalue) )224 $ newvalue = clone $newvalue;225 226 $ newvalue = sanitize_option( $option, $newvalue );227 $old value = get_option( $option );228 $ newvalue = apply_filters( 'pre_update_option_' . $option, $newvalue, $oldvalue );223 if ( is_object( $value ) ) 224 $value = clone $value; 225 226 $value = sanitize_option( $option, $value ); 227 $old_value = get_option( $option ); 228 $value = apply_filters( 'pre_update_option_' . $option, $value, $old_value ); 229 229 230 230 // If the new and old values are the same, no need to update. 231 if ( $newvalue === $oldvalue ) 232 return false; 233 234 if ( false === $oldvalue ) 235 return add_option( $option, $newvalue ); 231 if ( $value === $old_value ) 232 return false; 233 234 if ( false === $old_value ) 235 return add_option( $option, $value ); 236 237 $serialized_value = maybe_serialize( $value ); 238 239 $result = $wpdb->update( $wpdb->options, array( 'option_value' => $serialized_value ), array( 'option_name' => $option ) ); 240 if ( ! $result ) 241 return false; 236 242 237 243 $notoptions = wp_cache_get( 'notoptions', 'options' ); … … 241 247 } 242 248 243 $_newvalue = $newvalue; 244 $newvalue = maybe_serialize( $newvalue ); 245 246 do_action( 'update_option', $option, $oldvalue, $_newvalue ); 249 do_action( 'update_option', $option, $old_value, $value ); 247 250 if ( ! defined( 'WP_INSTALLING' ) ) { 248 251 $alloptions = wp_load_alloptions(); 249 252 if ( isset( $alloptions[$option] ) ) { 250 $alloptions[ $option] = $newvalue;253 $alloptions[ $option ] = $serialized_value; 251 254 wp_cache_set( 'alloptions', $alloptions, 'options' ); 252 255 } else { 253 wp_cache_set( $option, $newvalue, 'options' ); 254 } 255 } 256 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; 256 wp_cache_set( $option, $serialized_value, 'options' ); 257 } 258 } 259 260 do_action( "update_option_{$option}", $old_value, $value ); 261 do_action( 'updated_option', $option, $old_value, $value ); 262 return true; 265 263 } 266 264 … … 313 311 return false; 314 312 315 $_value = $value; 316 $value = maybe_serialize( $value ); 313 $serialized_value = maybe_serialize( $value ); 317 314 $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, $serialized_value, $autoload ) ); 318 if ( ! $result ) 319 return false; 320 319 321 if ( ! defined( 'WP_INSTALLING' ) ) { 320 322 if ( 'yes' == $autoload ) { 321 323 $alloptions = wp_load_alloptions(); 322 $alloptions[ $option] = $value;324 $alloptions[ $option ] = $serialized_value; 323 325 wp_cache_set( 'alloptions', $alloptions, 'options' ); 324 326 } else { 325 wp_cache_set( $option, $ value, 'options' );327 wp_cache_set( $option, $serialized_value, 'options' ); 326 328 } 327 329 } … … 334 336 } 335 337 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; 344 341 } 345 342 … … 830 827 $value = sanitize_option( $option, $value ); 831 828 829 $serialized_value = maybe_serialize( $value ); 830 $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 831 832 if ( ! $result ) 833 return false; 834 832 835 wp_cache_set( $cache_key, $value, 'site-options' ); 833 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 836 839 837 // This option exists now … … 916 914 wp_protect_special_option( $option ); 917 915 918 $old value = get_site_option( $option );919 $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old value );920 921 if ( $value === $old value )922 return false; 923 924 if ( false === $old value )916 $old_value = get_site_option( $option ); 917 $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value ); 918 919 if ( $value === $old_value ) 920 return false; 921 922 if ( false === $old_value ) 925 923 return add_site_option( $option, $value ); 926 924 … … 935 933 } else { 936 934 $value = sanitize_option( $option, $value ); 937 $cache_key = "{$wpdb->siteid}:$option"; 938 wp_cache_set( $cache_key, $value, 'site-options' ); 939 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; 935 936 $serialized_value = maybe_serialize( $value ); 937 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_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 } 944 943 } 945 944 946 945 if ( $result ) { 947 do_action( "update_site_option_{$option}", $option, $value, $old value );948 do_action( "update_site_option", $option, $value, $old value );946 do_action( "update_site_option_{$option}", $option, $value, $old_value ); 947 do_action( "update_site_option", $option, $value, $old_value ); 949 948 return true; 950 949 }
Note: See TracChangeset
for help on using the changeset viewer.