restore_current_blog

Restore the current blog, after calling switch_to_blog().

Description

restore_current_blog(); 

Usage

  1. if ( !function_exists( 'restore_current_blog' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-blogs.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = restore_current_blog(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-blogs.php  
  1. function restore_current_blog() { 
  2. global $wpdb, $wp_roles; 
  3.  
  4. if ( empty( $GLOBALS['_wp_switched_stack'] ) ) { 
  5. return false; 
  6.  
  7. $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); 
  8. $blog_id = get_current_blog_id(); 
  9.  
  10. if ( $blog_id == $blog ) { 
  11. /** This filter is documented in wp-includes/ms-blogs.php */ 
  12. do_action( 'switch_blog', $blog, $blog ); 
  13. // If we still have items in the switched stack, consider ourselves still 'switched' 
  14. $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 
  15. return true; 
  16.  
  17. $wpdb->set_blog_id( $blog ); 
  18. $prev_blog_id = $blog_id; 
  19. $GLOBALS['blog_id'] = $blog; 
  20. $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); 
  21.  
  22. if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 
  23. } else { 
  24. global $wp_object_cache; 
  25.  
  26. if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { 
  27. $global_groups = $wp_object_cache->global_groups; 
  28. } else { 
  29. $global_groups = false; 
  30.  
  31.  
  32. if ( function_exists( 'wp_cache_add_global_groups' ) ) { 
  33. if ( is_array( $global_groups ) ) { 
  34. wp_cache_add_global_groups( $global_groups ); 
  35. } else { 
  36. wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); 
  37. wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 
  38.  
  39. if ( did_action( 'init' ) ) { 
  40. $wp_roles = new WP_Roles(); 
  41. $current_user = wp_get_current_user(); 
  42. $current_user->for_blog( $blog ); 
  43.  
  44. /** This filter is documented in wp-includes/ms-blogs.php */ 
  45. do_action( 'switch_blog', $blog, $prev_blog_id ); 
  46.  
  47. // If we still have items in the switched stack, consider ourselves still 'switched' 
  48. $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 
  49.  
  50. return true;