- 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 )