From f338e835a212c2c007944be18808fe17d6a87d06 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 25 Jun 2010 16:16:06 +0000 Subject: [PATCH] Don't perform current user ops in switch_to_blog() or restore_current_blog() if init hasn't fired. Avoids wp_get_current_user() not defined error when those functions are run before init. Ops on current user prior to init are meaningless anyway. see #13934 git-svn-id: https://develop.svn.wordpress.org/trunk@15331 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/ms-blogs.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index be650f3a4f..48c2082193 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -407,9 +407,11 @@ function switch_to_blog( $new_blog, $validate = false ) { $wpdb->suppress_errors( false ); } - $current_user = wp_get_current_user(); - if ( is_object( $current_user ) ) - $current_user->for_blog( $blog_id ); + if ( ! did_action('init') ) { + $current_user = wp_get_current_user(); + if ( is_object( $current_user ) ) + $current_user->for_blog( $blog_id ); + } if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) $global_groups = $wp_object_cache->global_groups; @@ -461,9 +463,11 @@ function restore_current_blog() { $wpdb->suppress_errors( false ); } - $current_user = wp_get_current_user(); - if ( is_object( $current_user ) ) - $current_user->for_blog( $blog_id ); + if ( ! did_action('init') ) { + $current_user = wp_get_current_user(); + if ( is_object( $current_user ) ) + $current_user->for_blog( $blog_id ); + } if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) $global_groups = $wp_object_cache->global_groups;