From 30de863dfdcffa582c3e2ba4d0007a5aa40d6311 Mon Sep 17 00:00:00 2001 From: Matt Mullenweg Date: Fri, 23 Jul 2004 09:14:30 +0000 Subject: [PATCH] Options system can now transparently handle arrays and objects. git-svn-id: https://develop.svn.wordpress.org/trunk@1478 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 9015186a38..3febba371f 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -299,7 +299,7 @@ function get_settings($setting) { if ( isset($cache_settings->$setting) ) return $cache_settings->$setting; else - return $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'"); + return @ unserialize( $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'") ); } function get_alloptions() { @@ -311,7 +311,7 @@ function get_alloptions() { if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); - $all_options->{$option->option_name} = $option->option_value; + @$all_options->{$option->option_name} = unserialize($option->option_value); } } return $all_options; @@ -319,7 +319,9 @@ function get_alloptions() { function update_option($option_name, $newvalue) { global $wpdb, $cache_settings; - $newvalue = $newvalue; + if ( is_array($newvalue) || is_object($value) ) + $newvalue = serialize($newvalue); + $newvalue = trim($newvalue); // I can't think of any situation we wouldn't want to trim // If the new and old values are the same, no need to update. @@ -335,9 +337,12 @@ function update_option($option_name, $newvalue) { // thx Alex Stapleton, http://alex.vort-x.net/blog/ -function add_option($name, $value='') { +function add_option($name, $value = '') { // Adds an option if it doesn't already exist global $wpdb; + if ( is_array($value) || is_object($value) ) + $value = serialize($value); + if(!get_settings($name)) { $name = $wpdb->escape($name); $value = $wpdb->escape($value);