summaryrefslogtreecommitdiffstats
path: root/wp-includes/functions.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-06-04 16:01:24 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-06-04 16:01:24 +0000
commit899a7b1051be3c5d45d4aa25419b14106cf6661b (patch)
tree953185099055b9facd9c749b9a523627ef451eaa /wp-includes/functions.php
parent2a639e32577b2bd38b6f12399e1b8f47deee23ec (diff)
downloadwordpress-mu-899a7b1051be3c5d45d4aa25419b14106cf6661b.tar.gz
wordpress-mu-899a7b1051be3c5d45d4aa25419b14106cf6661b.tar.xz
wordpress-mu-899a7b1051be3c5d45d4aa25419b14106cf6661b.zip
WordPress.com object cache merge
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1320 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/functions.php')
-rw-r--r--wp-includes/functions.php178
1 files changed, 76 insertions, 102 deletions
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 7533faa..6d37b02 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -197,56 +197,15 @@ function is_serialized_string( $data ) {
function get_option( $setting ) {
global $wpdb, $switched, $current_blog;
+ $wpdb->hide_errors();
// Allow plugins to short-circuit options.
$pre = apply_filters( 'pre_option_' . $setting, false );
if ( false !== $pre )
return $pre;
- global $blog_id;
- if( $wpdb->blogid != $blog_id && function_exists('error_log') ) {
- $msg = "{$_SERVER[ 'HTTP_HOST' ]}{$_SERVER[ 'REQUEST_URI' ]} blog_id changed without calling switch_to_blog(). Current value: $blog_id";
- if( defined( 'ERRORLOGFILE' ) ) {
- error_log( $msg, 3, CONSTANT( 'ERRORLOGFILE' ) );
- } else {
- error_log( $msg );
- }
- }
- if ( $switched != false || defined('WP_INSTALLING') != false ) {
- //wp_cache_delete($setting, 'options');
- //wp_cache_delete('notoptions', 'options');
- //wp_cache_delete('alloptions', 'options');
- }
-
- // prevent non-existent options from triggering multiple queries
- $notoptions = wp_cache_get( 'notoptions', 'options' );
- if ( isset( $notoptions[$setting] ) )
- return false;
-
- $alloptions = wp_load_alloptions();
-
- if ( isset( $alloptions[$setting] ) ) {
- $value = $alloptions[$setting];
- } else {
- $value = wp_cache_get( $setting, 'options' );
-
- if ( false === $value ) {
- if ( defined( 'WP_INSTALLING' ) )
- $supress = $wpdb->suppress_errors();
- // expected_slashed ($setting)
- $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" );
- if ( defined( 'WP_INSTALLING' ) )
- $wpdb->suppress_errors($suppress);
-
- if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
- $value = $row->option_value;
- wp_cache_add( $setting, $value, 'options' );
- } else { // option does not exist, so we must cache its non-existence
- $notoptions[$setting] = true;
- wp_cache_set( 'notoptions', $notoptions, 'options' );
- return false;
- }
- }
- }
+ $value = _get_option_cache( $setting );
+ if ( false === $value )
+ return false;
// If home is not set use siteurl.
if ( 'home' == $setting && '' == $value )
@@ -255,6 +214,9 @@ function get_option( $setting ) {
if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )
$value = untrailingslashit( $value );
+ if (! unserialize($value) )
+ $value = stripslashes( $value );
+
return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
}
@@ -290,22 +252,67 @@ function get_alloptions() {
function wp_load_alloptions() {
global $wpdb;
+ global $_wp_alloptions;
+ global $blog_id;
- $alloptions = wp_cache_get( 'alloptions', 'options' );
-
- if ( !$alloptions ) {
- $suppress = $wpdb->suppress_errors();
- if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
- $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
- $wpdb->suppress_errors($suppress);
- $alloptions = array();
- foreach ( (array) $alloptions_db as $o )
- $alloptions[$o->option_name] = $o->option_value;
- wp_cache_add( 'alloptions', $alloptions, 'options' );
+ if ( !empty($_wp_alloptions[$blog_id]) )
+ return $_wp_alloptions[$blog_id];
+
+ $alloptions = wp_cache_get('alloptions', 'options');
+
+ if ( false !== $alloptions ) {
+ $_wp_alloptions[$blog_id] = $alloptions;
+ return $alloptions;
}
- return $alloptions;
+
+ $_wp_alloptions[$blog_id] = array();
+
+ $suppress = $wpdb->suppress_errors();
+ if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
+ $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
+ $wpdb->suppress_errors($suppress);
+ foreach ( (array) $alloptions_db as $o )
+ $_wp_alloptions[$blog_id][$o->option_name] = $o->option_value;
+
+ wp_cache_set('alloptions', $_wp_alloptions[$blog_id], 'options');
+
+ return $_wp_alloptions[$blog_id];
}
+function _get_option_cache( $setting ) {
+ global $_wp_alloptions;
+ global $blog_id;
+
+ wp_load_alloptions();
+
+ if ( isset($_wp_alloptions[$blog_id][$setting]) )
+ return $_wp_alloptions[$blog_id][$setting];
+
+ return false;
+}
+
+function _set_option_cache( $setting, $value ) {
+ global $_wp_alloptions;
+ global $blog_id;
+
+ wp_load_alloptions();
+
+ $_wp_alloptions[$blog_id][$setting] = $value;
+
+ wp_cache_delete('alloptions', 'options');
+}
+
+function _delete_option_cache( $setting ) {
+ global $_wp_alloptions;
+ global $blog_id;
+
+ wp_load_alloptions();
+
+ if ( isset($_wp_alloptions[$blog_id][$setting]) )
+ unset($_wp_alloptions[$blog_id][$setting]);
+
+ wp_cache_delete('alloptions', 'options');
+}
// expects $option_name to NOT be SQL-escaped
function update_option( $option_name, $newvalue ) {
@@ -326,22 +333,10 @@ function update_option( $option_name, $newvalue ) {
return true;
}
- $notoptions = wp_cache_get( 'notoptions', 'options' );
- if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) {
- unset( $notoptions[$option_name] );
- wp_cache_set( 'notoptions', $notoptions, 'options' );
- }
-
$_newvalue = $newvalue;
$newvalue = maybe_serialize( $newvalue );
- $alloptions = wp_load_alloptions();
- if ( isset( $alloptions[$option_name] ) ) {
- $alloptions[$option_name] = $newvalue;
- wp_cache_set( 'alloptions', $alloptions, 'options' );
- } else {
- wp_cache_set( $option_name, $newvalue, 'options' );
- }
+ _set_option_cache($option_name, $newvalue);
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", $newvalue, $option_name ) );
if ( $wpdb->rows_affected == 1 ) {
@@ -361,29 +356,13 @@ function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
$safe_name = $wpdb->escape( $name );
$value = sanitize_option( $name, $value );
- // 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( $safe_name ) )
- return;
+ if ( false !== get_option( $safe_name ) )
+ return;
$value = maybe_serialize( $value );
$autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
- if ( 'yes' == $autoload ) {
- $alloptions = wp_load_alloptions();
- $alloptions[$name] = $value;
- wp_cache_set( 'alloptions', $alloptions, 'options' );
- } else {
- 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' );
- }
+ _set_option_cache( $name, $value );
$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s)", $name, $value, $autoload ) );
@@ -397,22 +376,17 @@ function delete_option( $name ) {
wp_protect_special_option( $name );
+ _delete_option_cache( $name );
+
// Get the ID, if no ID then return
// expected_slashed ($name)
$option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
if ( is_null($option) || !$option->option_id )
return false;
+
// expected_slashed ($name)
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
- if ( 'yes' == $option->autoload ) {
- $alloptions = wp_load_alloptions();
- if ( isset( $alloptions[$name] ) ) {
- unset( $alloptions[$name] );
- wp_cache_set( 'alloptions', $alloptions, 'options' );
- }
- } else {
- wp_cache_delete( $name, 'options' );
- }
+
return true;
}
@@ -954,9 +928,10 @@ function do_feed_atom( $for_comments ) {
function do_robots() {
global $current_blog;
- header( 'Content-Type: text/plain; charset=utf-8' );
- do_action('do_robotstxt');
+ header('Content-Type: text/plain; charset=utf-8');
+
+ do_action( 'do_robotstxt' );
if ( '0' == $current_blog->public ) {
echo "User-agent: *\n";
@@ -1191,6 +1166,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = NULL ) {
$upload[ 'error' ] = $upload_bits_error;
return $upload;
}
+
$filename = wp_unique_filename( $upload['path'], $name );
$new_file = $upload['path'] . "/$filename";
@@ -1455,7 +1431,6 @@ function _config_wp_siteurl( $url = '' ) {
return $url;
}
-
function _mce_set_direction( $input ) {
global $wp_locale;
@@ -1468,7 +1443,6 @@ function _mce_set_direction( $input ) {
return $input;
}
-
function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;