From 56f6f97125a5f052f8d1b4dcedbfa5327cc76d76 Mon Sep 17 00:00:00 2001 From: duck_ Date: Tue, 23 Aug 2011 20:24:35 +0000 Subject: [PATCH] add_site_option should not update existing options, should return a boolean and should only run actions on success. fixes #18422 git-svn-id: http://svn.automattic.com/wordpress/trunk@18587 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3b950df17d..9cbaa83309 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -569,11 +569,10 @@ function update_option( $option, $newvalue ) { * 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 + * You can create options without values and then update the values later. + * Existing options will not be updated and checks are performed to ensure 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. + * options the same as the ones which are protected. * * @package WordPress * @subpackage Option @@ -3775,6 +3774,8 @@ function get_site_option( $option, $default = false, $use_cache = true ) { /** * Add a new site option. * + * Existing options will not be updated. Note that prior to 3.3 this wasn't the case. + * * @see add_option() * @package WordPress * @subpackage Option @@ -3799,7 +3800,7 @@ function add_site_option( $option, $value ) { $cache_key = "{$wpdb->siteid}:$option"; if ( $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ) ) - return update_site_option( $option, $value ); + return false; $value = sanitize_option( $option, $value ); wp_cache_set( $cache_key, $value, 'site-options' ); @@ -3810,10 +3811,12 @@ function add_site_option( $option, $value ) { $value = $_value; } - do_action( "add_site_option_{$option}", $option, $value ); - do_action( "add_site_option", $option, $value ); - - return $result; + if ( $result ) { + do_action( "add_site_option_{$option}", $option, $value ); + do_action( "add_site_option", $option, $value ); + return true; + } + return false; } /**