Ticket #18244: update_option.diff
| File update_option.diff, 1.9 KB (added by , 14 years ago) |
|---|
-
wp-includes/functions.php
507 507 * 508 508 * @param string $option Option name. Expected to not be SQL-escaped. 509 509 * @param mixed $newvalue Option value. Expected to not be SQL-escaped. 510 * @param bool $autoload Optional. Default is enabled, but will not overwrite previous value unless forced. Whether to load the option when WordPress starts up. 510 511 * @return bool False if value was not updated and true if value was updated. 511 512 */ 512 function update_option( $option, $newvalue ) {513 function update_option( $option, $newvalue, $autoload = 'default' ) { 513 514 global $wpdb; 514 515 516 // If autoload is not set explicitly, do not overwrite previous value 517 if( $autoload == 'default' ) { 518 $replace_autoload = false; 519 $autoload = 'yes'; 520 } else { 521 $replace_autoload = true; 522 } 523 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes'; 524 515 525 $option = trim($option); 516 526 if ( empty($option) ) 517 527 return false; … … 530 540 return false; 531 541 532 542 if ( false === $oldvalue ) 533 return add_option( $option, $newvalue );543 return add_option( $option, $newvalue, '', $autoload ); 534 544 535 545 $notoptions = wp_cache_get( 'notoptions', 'options' ); 536 546 if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { … … 551 561 wp_cache_set( $option, $_newvalue, 'options' ); 552 562 } 553 563 } 564 565 $updates = array( 'option_value' => $newvalue ); 566 if( $replace_autoload ) 567 $updates[ 'autoload' ] = $autoload; 568 569 $result = $wpdb->update( $wpdb->options, $updates, array( 'option_name' => $option ) ); 554 570 555 $result = $wpdb->update( $wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) );556 557 571 if ( $result ) { 558 572 do_action( "update_option_{$option}", $oldvalue, $_newvalue ); 559 573 do_action( 'updated_option', $option, $oldvalue, $_newvalue );