From a0d734beea08d993e2aa99bcca074f86038a8371 Mon Sep 17 00:00:00 2001 From: dd32 Date: Sun, 28 Mar 2010 03:10:37 +0000 Subject: [PATCH] Do not allow empty option names. Trim leading and trailing whitespace from option names. Partial patch props ericmann. Fixes #11506 git-svn-id: http://svn.automattic.com/wordpress/trunk@13858 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 4525d20ffb..751095f0ff 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -318,6 +318,10 @@ function get_option( $option, $default = false ) { if ( false !== $pre ) return $pre; + $option = trim($option); + if ( empty($option) ) + return false; + // prevent non-existent options from triggering multiple queries if ( defined( 'WP_INSTALLING' ) && is_multisite() ) { $notoptions = array(); @@ -488,6 +492,10 @@ function wp_load_core_site_options( $site_id = null ) { function update_option( $option, $newvalue ) { global $wpdb; + $option = trim($option); + if ( empty($option) ) + return false; + wp_protect_special_option( $option ); $newvalue = sanitize_option( $option, $newvalue ); @@ -559,10 +567,14 @@ function update_option( $option, $newvalue ) { * @return null returns when finished. */ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { + global $wpdb; + if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.3' ); - global $wpdb; + $option = trim($option); + if ( empty($option) ) + return false; wp_protect_special_option( $option ); $value = sanitize_option( $option, $value );