Changeset 1310

Show
Ignore:
Timestamp:
05/23/08 17:31:51 (3 months ago)
Author:
donncha
Message:

Experimental: warn if blog_id is changed without switch_to_blog() being called because it results in cache pollution

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/functions.php

    r1294 r1310  
    204204 
    205205        if ( $switched != false || defined('WP_INSTALLING') != false ) { 
    206                 wp_cache_delete($setting, 'options'); 
    207                 wp_cache_delete('notoptions', 'options'); 
    208                 wp_cache_delete('alloptions', 'options'); 
     206                global $blog_id, $switched_to; 
     207                if( $switched_to != $blog_id && function_exists('error_log') ) { 
     208                        $msg = "{$_SERVER[ 'HTTP_HOST' ]}{$_SERVER[ 'REQUEST_URI' ]} blog_id changed without calling switch_to_blog(). Current value: $blog_id"; 
     209                        if( defined( 'ERRORLOGFILE' ) ) { 
     210                                error_log( $msg, 3, CONSTANT( 'ERRORLOGFILE' ) ); 
     211                        } else { 
     212                                error_log( $msg ); 
     213                        } 
     214                } 
     215                //wp_cache_delete($setting, 'options'); 
     216                //wp_cache_delete('notoptions', 'options'); 
     217                //wp_cache_delete('alloptions', 'options'); 
    209218        } 
    210219 
  • trunk/wp-includes/wpmu-functions.php

    r1308 r1310  
    323323 
    324324function switch_to_blog( $new_blog ) { 
    325         global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache
     325        global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache, $switched_to
    326326 
    327327        if ( empty($new_blog) ) 
     
    340340        $prev_blog_id = $blog_id; 
    341341        $blog_id = $new_blog; 
     342        $switched_to = $blog_id; 
    342343 
    343344        if( is_object( $wp_roles ) ) { 
     
    355356 
    356357function restore_current_blog() { 
    357         global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache
     358        global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache, $switched_to
    358359 
    359360        if ( !$switched ) 
     
    368369        $blog_id = $blog; 
    369370        $table_prefix = $wpdb->prefix; 
     371        $switched_to = $blog_id; 
    370372 
    371373        if( is_object( $wp_roles ) ) {