Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




update_option [ WordPress Function ]

update_option ( $option, $newvalue )
Parameters:
  • (string) $option Option name. Expected to not be SQL-escaped.
  • (mixed) $newvalue Option value. Expected to not be SQL-escaped.
Uses:
Returns:
  • (bool) False if value was not updated and true if value was updated.
Defined at:



Update the value of an option that was already added.

You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is inserted into the database. Remember, resources can not be serialized or added as an option.

If the option does not exist, then the option will be added with the option value, but you will not be able to set whether it is autoloaded. If you want to set whether an option is autoloaded, then you need to use the add_option().

Source


<?php
function update_option$option$newvalue ) {
    global 
$wpdb;

    
$option trim($option);
    if ( empty(
$option) )
        return 
false;

    
wp_protect_special_option$option );

    if ( 
is_object($newvalue) )
        
$newvalue = clone $newvalue;

    
$newvalue sanitize_option$option$newvalue );
    
$oldvalue get_option$option );
    
$newvalue apply_filters'pre_update_option_' $option$newvalue$oldvalue );

    
// If the new and old values are the same, no need to update.
    
if ( $newvalue === $oldvalue )
        return 
false;

    if ( 
false === $oldvalue )
        return 
add_option$option$newvalue );

    
$notoptions wp_cache_get'notoptions''options' );
    if ( 
is_array$notoptions ) && isset( $notoptions[$option] ) ) {
        unset( 
$notoptions[$option] );
        
wp_cache_set'notoptions'$notoptions'options' );
    }

    
$_newvalue $newvalue;
    
$newvalue maybe_serialize$newvalue );

    
do_action'update_option'$option$oldvalue$_newvalue );
    if ( ! 
defined'WP_INSTALLING' ) ) {
        
$alloptions wp_load_alloptions();
        if ( isset( 
$alloptions[$option] ) ) {
            
$alloptions[$option] = $_newvalue;
            
wp_cache_set'alloptions'$alloptions'options' );
        } else {
            
wp_cache_set$option$_newvalue'options' );
        }
    }

    
$result $wpdb->update$wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) );

    if ( 
$result ) {
        
do_action"update_option_{$option}"$oldvalue$_newvalue );
        
do_action'updated_option'$option$oldvalue$_newvalue );
        return 
true;
    }
    return 
false;
}
?>

Examples [ wp-snippets.com ]

Top Google Search Results

More ...

0 User Note(s)

None yet. Be the first!

Add New ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics