- if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings
- return true;
- return false;
-}
-
-/**
- * Retrieve option value based on setting name.
- *
- * If the option does not exist or does not have a value, then the return value
- * will be false. This is useful to check whether you need to install an option
- * and is commonly used during installation of plugin options and to test
- * whether upgrading is required.
- *
- * You can "short-circuit" the retrieval of the option from the database for
- * your plugin or core options that aren't protected. You can do so by hooking
- * into the 'pre_option_$option' with the $option being replaced by the option
- * name. You should not try to override special options, but you will not be
- * prevented from doing so.
- *
- * There is a second filter called 'option_$option' with the $option being
- * replaced with the option name. This gives the value as the only parameter.
- *
- * If the option was serialized, when the option was added and, or updated, then
- * it will be unserialized, when it is returned.
- *
- * @since 1.5.0
- * @package WordPress
- * @subpackage Option
- * @uses apply_filters() Calls 'pre_option_$optionname' false to allow
- * overwriting the option value in a plugin.
- * @uses apply_filters() Calls 'option_$optionname' with the option name value.
- *
- * @param string $setting Name of option to retrieve. Should already be SQL-escaped
- * @return mixed Value set for the option.
- */
-function get_option( $setting, $default = false ) {
- global $wpdb;
-
- // Allow plugins to short-circuit options.
- $pre = apply_filters( 'pre_option_' . $setting, false );
- if ( false !== $pre )
- return $pre;
-
- // prevent non-existent options from triggering multiple queries
- $notoptions = wp_cache_get( 'notoptions', 'options' );
- if ( isset( $notoptions[$setting] ) )
- return $default;
-
- $alloptions = wp_load_alloptions();
-
- if ( isset( $alloptions[$setting] ) ) {
- $value = $alloptions[$setting];
- } else {
- $value = wp_cache_get( $setting, 'options' );
-
- if ( false === $value ) {
- if ( defined( 'WP_INSTALLING' ) )
- $suppress = $wpdb->suppress_errors();
- // expected_slashed ($setting)
- $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" );
- if ( defined( 'WP_INSTALLING' ) )
- $wpdb->suppress_errors($suppress);
-
- if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
- $value = $row->option_value;
- wp_cache_add( $setting, $value, 'options' );
- } else { // option does not exist, so we must cache its non-existence
- $notoptions[$setting] = true;
- wp_cache_set( 'notoptions', $notoptions, 'options' );
- return $default;
- }
- }
- }
-
- // If home is not set use siteurl.
- if ( 'home' == $setting && '' == $value )
- return get_option( 'siteurl' );
-
- if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )
- $value = untrailingslashit( $value );
-
- return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
-}
-
-/**
- * Protect WordPress special option from being modified.
- *
- * Will die if $option is in protected list. Protected options are 'alloptions'
- * and 'notoptions' options.
- *
- * @since 2.2.0
- * @package WordPress
- * @subpackage Option
- *
- * @param string $option Option name.
- */
-function wp_protect_special_option( $option ) {
- $protected = array( 'alloptions', 'notoptions' );
- if ( in_array( $option, $protected ) )
- die( sprintf( __( '%s is a protected WP option and may not be modified' ), esc_html( $option ) ) );
-}
-
-/**
- * Print option value after sanitizing for forms.
- *
- * @uses attr Sanitizes value.
- * @since 1.5.0
- * @package WordPress
- * @subpackage Option
- *
- * @param string $option Option name.
- */
-function form_option( $option ) {
- echo esc_attr(get_option( $option ) );
-}
-
-/**
- * Retrieve all autoload options or all options, if no autoloaded ones exist.
- *
- * This is different from wp_load_alloptions() in that this function does not
- * cache its results and will retrieve all options from the database every time
- *
- * it is called.
- *
- * @since 1.0.0
- * @package WordPress
- * @subpackage Option
- * @uses apply_filters() Calls 'pre_option_$optionname' hook with option value as parameter.
- * @uses apply_filters() Calls 'all_options' on options list.
- *
- * @return array List of all options.
- */
-function get_alloptions() {
- global $wpdb;
- $show = $wpdb->hide_errors();
- if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
- $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
- $wpdb->show_errors($show);
-
- foreach ( (array) $options as $option ) {
- // "When trying to design a foolproof system,
- // never underestimate the ingenuity of the fools :)" -- Dougal
- if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
- $option->option_value = untrailingslashit( $option->option_value );
- $value = maybe_unserialize( $option->option_value );
- $all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value );
- }
- return apply_filters( 'all_options', $all_options );
-}
-
-/**
- * Loads and caches all autoloaded options, if available or all options.
- *
- * This is different from get_alloptions(), in that this function will cache the
- * options and will return the cached options when called again.
- *
- * @since 2.2.0
- * @package WordPress
- * @subpackage Option
- *
- * @return array List all options.
- */
-function wp_load_alloptions() {
- global $wpdb;
-
- $alloptions = wp_cache_get( 'alloptions', 'options' );
-
- if ( !$alloptions ) {
- $suppress = $wpdb->suppress_errors();
- if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
- $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
- $wpdb->suppress_errors($suppress);
- $alloptions = array();
- foreach ( (array) $alloptions_db as $o )
- $alloptions[$o->option_name] = $o->option_value;
- wp_cache_add( 'alloptions', $alloptions, 'options' );
- }
- return $alloptions;
-}
-
-/**
- * Update the value of an option that was already added.
- *
- * 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.
- *
- * 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 autoloaded, then you need to use the add_option().
- *
- * Before the option is updated, then the filter named
- * 'pre_update_option_$option_name', with the $option_name as the $option_name
- * parameter value, will be called. The hook should accept two parameters, the
- * first is the new value and the second is the old value. Whatever is
- * returned will be used as the new value.
- *
- * After the value has been updated the action named 'update_option_$option_name'
- * will be called. This action receives two parameters the first being the old
- * value and the second the new value.
- *
- * @since 1.0.0
- * @package WordPress
- * @subpackage Option
- *
- * @param string $option_name Option name. Expected to not be SQL-escaped
- * @param mixed $newvalue Option value.
- * @return bool False if value was not updated and true if value was updated.
- */
-function update_option( $option_name, $newvalue ) {
- global $wpdb;
-
- wp_protect_special_option( $option_name );
-
- $safe_option_name = esc_sql( $option_name );
- $newvalue = sanitize_option( $option_name, $newvalue );
-
- $oldvalue = get_option( $safe_option_name );
-
- $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );
-
- // If the new and old values are the same, no need to update.
- if ( $newvalue === $oldvalue )
- return false;
-
- 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) )