summaryrefslogtreecommitdiffstats
path: root/wp-includes/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-includes/functions.php')
-rw-r--r--wp-includes/functions.php25
1 files changed, 18 insertions, 7 deletions
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 67787e1..60a5730 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -203,6 +203,7 @@ function is_serialized_string($data) {
/* Options functions */
+// expects $setting to already be SQL-escaped
function get_option($setting) {
global $wpdb, $switched, $current_blog;
@@ -311,16 +312,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;
}
@@ -358,21 +362,21 @@ 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 cache before we ask for a db query
+ // 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]) ) {
- unset($notoptions[$name]);
- wp_cache_set('notoptions', $notoptions, 'options');
- } elseif ( false !== get_option($name) ) {
+ if ( !is_array($notoptions) || !isset($notoptions[$name]) )
+ if ( false !== get_option($safe_name) )
return;
- }
$value = maybe_serialize($value);
+ $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
if ( 'yes' == $autoload ) {
$alloptions = wp_load_alloptions();
@@ -382,6 +386,13 @@ function add_option($name, $value = '', $description = '', $autoload = 'yes') {
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');
+ }
+
$name = $wpdb->escape($name);
$value = $wpdb->escape($value);
$description = $wpdb->escape($description);