Skip to content

Commit

Permalink
add_option()/update_option() should pass the option name to get_optio…
Browse files Browse the repository at this point in the history
…n() pre-escaped. fixes #4690 for 2.2.x

git-svn-id: http://svn.automattic.com/wordpress/branches/2.2@5830 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
markjaquith committed Aug 1, 2007
1 parent 77a94e8 commit 113de8f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function is_serialized_string($data) {

/* Options functions */

// expects $setting to already be SQL-escaped
function get_option($setting) {
global $wpdb;

Expand Down Expand Up @@ -302,16 +303,19 @@ function wp_load_alloptions() {
return $alloptions;
}

// expects $option_name to NOT be SQL-escaped
function update_option($option_name, $newvalue) {
global $wpdb;

wp_protect_special_option($option_name);

$safe_option_name = $wpdb->escape($option_name);

if ( is_string($newvalue) )
$newvalue = trim($newvalue);

// If the new and old values are the same, no need to update.
$oldvalue = get_option($option_name);
$oldvalue = get_option($safe_option_name);
if ( $newvalue === $oldvalue ) {
return false;
}
Expand Down Expand Up @@ -349,15 +353,17 @@ function update_option($option_name, $newvalue) {
}

// thx Alex Stapleton, http://alex.vort-x.net/blog/
// expects $name to NOT be SQL-escaped
function add_option($name, $value = '', $description = '', $autoload = 'yes') {
global $wpdb;

wp_protect_special_option($name);
$safe_name = $wpdb->escape($name);

// 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($name) )
if ( false !== get_option($safe_name) )
return;

$value = maybe_serialize($value);
Expand Down

0 comments on commit 113de8f

Please sign in to comment.