update_option [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| 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
- update_option - WordPress Codex
Use the function update_option() to update a named option/value pair to the options database table. The option_name value is escaped with $wpdb->escape ...
codex.wordpress.org - WordPress › Support » Tags — update_option
(forgot?) Register · WordPress › Support » update_option ...
wordpress.org - PHPXRef 0.7 : WordPress : Function Reference: update_option()
Function and Method Cross Reference. update_option(). Defined at: /wp-includes /option.php -> line 191. Referenced 121 times: ...
phpxref.ftwr.co.uk - WordPress functions.php: how to apply update_option()? - Stack ...
Start with the Wordpress codex. Visit the plugin API (which is really what you are doing) that explains Hooks, Actions and Filters. Then see the Action ...
stackoverflow.com
User discussions [ wordpress.org ]
- roryrothon on "update_option from an array populated"
- Andrea_r on "Clone theme settings"
- expromo on "Clone theme settings"
- esmi on "update_option appears on every page in my site"
- jacquisouth on "update_option appears on every page in my site"
- Ipstenu on "update_option appears on every page in my site"
- jacquisouth on "update_option appears on every page in my site"
- hhanna on "Programming widget in sidebar by default"
- hhanna on "Programming widget in sidebar by default"
- bellasys on "Database Write Anomaly: value over-written after update function closes"