-
- if ( false === $oldvalue ) {
- add_option( $option_name, $newvalue );
- return true;
- }
-
- $notoptions = wp_cache_get( 'notoptions', 'options' );
- if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) {
- unset( $notoptions[$option_name] );
- wp_cache_set( 'notoptions', $notoptions, 'options' );
- }
-
- $_newvalue = $newvalue;
- $newvalue = maybe_serialize( $newvalue );
-
- do_action( 'update_option', $option_name, $oldvalue, $newvalue );
- $alloptions = wp_load_alloptions();
- if ( isset( $alloptions[$option_name] ) ) {
- $alloptions[$option_name] = $newvalue;
- wp_cache_set( 'alloptions', $alloptions, 'options' );
- } else {
- wp_cache_set( $option_name, $newvalue, 'options' );
- }
-
- $wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );
-
- if ( $wpdb->rows_affected == 1 ) {
- do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
- do_action( 'updated_option', $option_name, $oldvalue, $_newvalue );
- return true;
- }
- return false;
-}
-
-/**
- * Add a new option.
- *
- * You do not need to serialize values, if the value needs to be serialize, then
- * it will be serialized before it is inserted into the database. Remember,
- * resources can not be serialized or added as an option.
- *
- * You can create options without values and then add values later. Does not
- * check whether the option has already been added, but does check that you
- * aren't adding a protected WordPress option. Care should be taken to not name
- * options, the same as the ones which are protected and to not add options
- * that were already added.
- *
- * The filter named 'add_option_$optionname', with the $optionname being
- * replaced with the option's name, will be called. The hook should accept two
- * parameters, the first is the option name, and the second is the value.
- *
- * @package WordPress
- * @subpackage Option
- * @since 1.0.0
- * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
- *
- * @param string $name Option name to add. Expects to NOT be SQL escaped.
- * @param mixed $value Optional. Option value, can be anything.
- * @param mixed $deprecated Optional. Description. Not used anymore.
- * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
- * @return null returns when finished.
- */
-function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
- global $wpdb;
-
- wp_protect_special_option( $name );
- $safe_name = esc_sql( $name );
- $value = sanitize_option( $name, $value );
-
- // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
- $notoptions = wp_cache_get( 'notoptions', 'options' );
- if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
- if ( false !== get_option( $safe_name ) )
- return;
-
- $value = maybe_serialize( $value );
- $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
- do_action( 'add_option', $name, $value );
- if ( 'yes' == $autoload ) {
- $alloptions = wp_load_alloptions();
- $alloptions[$name] = $value;
- wp_cache_set( 'alloptions', $alloptions, 'options' );
- } else {
- wp_cache_set( $name, $value, 'options' );
- }
-
- // This option exists now
- $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
- if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) {
- unset( $notoptions[$name] );
- wp_cache_set( 'notoptions', $notoptions, 'options' );
- }
-
- $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`)", $name, $value, $autoload ) );
-
- do_action( "add_option_{$name}", $name, $value );
- do_action( 'added_option', $name, $value );
-
- return;
-}
-
-/**
- * Removes option by name and prevents removal of protected WordPress options.
- *
- * @package WordPress
- * @subpackage Option
- * @since 1.2.0
- *
- * @param string $name Option name to remove.
- * @return bool True, if succeed. False, if failure.
- */
-function delete_option( $name ) {
- global $wpdb;
-
- wp_protect_special_option( $name );
-
- // Get the ID, if no ID then return
- // expected_slashed ($name)
- $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" );
- if ( is_null($option) )
- return false;
- do_action( 'delete_option', $name );
- // expected_slashed ($name)
- $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
- if ( 'yes' == $option->autoload ) {
- $alloptions = wp_load_alloptions();
- if ( isset( $alloptions[$name] ) ) {
- unset( $alloptions[$name] );
- wp_cache_set( 'alloptions', $alloptions, 'options' );
- }
- } else {
- wp_cache_delete( $name, 'options' );
- }
- do_action( 'deleted_option', $name );
- return true;
-}
-
-/**
- * Delete a transient
- *
- * @since 2.8.0
- * @package WordPress
- * @subpackage Transient
- *
- * @param string $transient Transient name. Expected to not be SQL-escaped
- * @return bool true if successful, false otherwise
- */
-function delete_transient($transient) {
- global $_wp_using_ext_object_cache, $wpdb;
-
- if ( $_wp_using_ext_object_cache ) {
- return wp_cache_delete($transient, 'transient');
- } else {
- $transient = '_transient_' . esc_sql($transient);
- return delete_option($transient);
- }
-}
-
-/**
- * Get the value of a transient
- *
- * If the transient does not exist or does not have a value, then the return value
- * will be false.
- *
- * @since 2.8.0
- * @package WordPress
- * @subpackage Transient
- *
- * @param string $transient Transient name. Expected to not be SQL-escaped
- * @return mixed Value of transient
- */
-function get_transient($transient) {
- global $_wp_using_ext_object_cache, $wpdb;
-
- $pre = apply_filters( 'pre_transient_' . $transient, false );
- if ( false !== $pre )
- return $pre;
-
- if ( $_wp_using_ext_object_cache ) {
- $value = wp_cache_get($transient, 'transient');
- } else {
- $transient_option = '_transient_' . esc_sql($transient);
- // If option is not in alloptions, it is not autoloaded and thus has a timeout
- $alloptions = wp_load_alloptions();
- if ( !isset( $alloptions[$transient_option] ) ) {
- $transient_timeout = '_transient_timeout_' . esc_sql($transient);
- if ( get_option($transient_timeout) < time() ) {
- delete_option($transient_option);
- delete_option($transient_timeout);
- return false;
- }
- }
-
- $value = get_option($transient_option);
- }
-
- return apply_filters('transient_' . $transient, $value);
-}
-
-/**
- * Set/update the value of a transient
- *
- * You do not need to serialize values, if the value needs to be serialize, then
- * it will be serialized before it is set.
- *
- * @since 2.8.0
- * @package WordPress
- * @subpackage Transient
- *
- * @param string $transient Transient name. Expected to not be SQL-escaped
- * @param mixed $value Transient value.
- * @param int $expiration Time until expiration in seconds, default 0
- * @return bool False if value was not set and true if value was set.
- */
-function set_transient($transient, $value, $expiration = 0) {
- global $_wp_using_ext_object_cache, $wpdb;
-
- if ( $_wp_using_ext_object_cache ) {
- return wp_cache_set($transient, $value, 'transient', $expiration);
- } else {
- $transient_timeout = '_transient_timeout_' . $transient;
- $transient = '_transient_' . $transient;
- $safe_transient = esc_sql($transient);
- if ( false === get_option( $safe_transient ) ) {
- $autoload = 'yes';
- if ( 0 != $expiration ) {
- $autoload = 'no';
- add_option($transient_timeout, time() + $expiration, '', 'no');
- }
- return add_option($transient, $value, '', $autoload);
- } else {
- if ( 0 != $expiration )
- update_option($transient_timeout, time() + $expiration);
- return update_option($transient, $value);
- }
- }
-}
-
-/**
- * Saves and restores user interface settings stored in a cookie.
- *
- * Checks if the current user-settings cookie is updated and stores it. When no
- * cookie exists (different browser used), adds the last saved cookie restoring
- * the settings.
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.7.0
- */
-function wp_user_settings() {
-
- if ( ! is_admin() )
- return;
-
- if ( defined('DOING_AJAX') )
- return;
-
- if ( ! $user = wp_get_current_user() )
- return;
-
- $settings = get_user_option( 'user-settings', $user->ID, false );
-
- if ( isset( $_COOKIE['wp-settings-' . $user->ID] ) ) {
- $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] );
-
- if ( ! empty( $cookie ) && strpos( $cookie, '=' ) ) {
- if ( $cookie == $settings )
- return;
-
- $last_time = (int) get_user_option( 'user-settings-time', $user->ID, false );
- $saved = isset( $_COOKIE['wp-settings-time-' . $user->ID]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user->ID] ) : 0;
-
- if ( $saved > $last_time ) {
- update_user_option( $user->ID, 'user-settings', $cookie, false );
- update_user_option( $user->ID, 'user-settings-time', time() - 5, false );
- return;
- }
- }
- }
-
- setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH );
- setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH );
- $_COOKIE['wp-settings-' . $user->ID] = $settings;
-}
-
-/**
- * Retrieve user interface setting value based on setting name.
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.7.0
- *
- * @param string $name The name of the setting.
- * @param string $default Optional default value to return when $name is not set.
- * @return mixed the last saved user setting or the default value/false if it doesn't exist.
- */
-function get_user_setting( $name, $default = false ) {
-
- $all = get_all_user_settings();
-
- return isset($all[$name]) ? $all[$name] : $default;
-}
-
-/**
- * Add or update user interface setting.
- *
- * Both $name and $value can contain only ASCII letters, numbers and underscores.
- * This function has to be used before any output has started as it calls setcookie().
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.8.0
- *
- * @param string $name The name of the setting.
- * @param string $value The value for the setting.
- * @return bool true if set successfully/false if not.
- */
-function set_user_setting( $name, $value ) {
-
- if ( headers_sent() )