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
This commit is contained in:
Ryan Boren 2010-06-25 16:16:06 +00:00
parent 8c3323da0a
commit f338e835a2
1 changed files with 10 additions and 6 deletions

View File

@ -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;