restore_current_blog

The timeline below displays how wordpress function restore_current_blog has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Restores the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
        // If we still have items in the switched stack, consider ourselves still 'switched'.
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('blog-details', 'blog-id-cache', 'blog-lookup', 'blog_meta', 'global-posts', 'networks', 'network-queries', 'sites', 'site-details', 'site-options', 'site-queries', 'site-transient', 'theme_files', 'rss', 'users', 'user-queries', 'user_meta', 'useremail', 'userlogins', 'userslugs'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins', 'theme_json'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
    // If we still have items in the switched stack, consider ourselves still 'switched'.
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.2

/**
 * Restores the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
        // If we still have items in the switched stack, consider ourselves still 'switched'.
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('blog-details', 'blog-id-cache', 'blog-lookup', 'blog_meta', 'global-posts', 'networks', 'network-queries', 'sites', 'site-details', 'site-options', 'site-queries', 'site-transient', 'rss', 'users', 'user-queries', 'user_meta', 'useremail', 'userlogins', 'userslugs'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins', 'theme_json'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
    // If we still have items in the switched stack, consider ourselves still 'switched'.
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 6.4

/**
 * Restores the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global string          $wp_template_path
 * @global string          $wp_stylesheet_path
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
        // If we still have items in the switched stack, consider ourselves still 'switched'.
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    $GLOBALS['wp_template_path'] = null;
    $GLOBALS['wp_stylesheet_path'] = null;
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('blog-details', 'blog-id-cache', 'blog-lookup', 'blog_meta', 'global-posts', 'networks', 'network-queries', 'sites', 'site-details', 'site-options', 'site-queries', 'site-transient', 'rss', 'users', 'user-queries', 'user_meta', 'useremail', 'userlogins', 'userslugs'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins', 'theme_json'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
    // If we still have items in the switched stack, consider ourselves still 'switched'.
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 6.3

/**
 * Restores the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
        // If we still have items in the switched stack, consider ourselves still 'switched'.
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('blog-details', 'blog-id-cache', 'blog-lookup', 'blog_meta', 'global-posts', 'networks', 'network-queries', 'sites', 'site-details', 'site-options', 'site-queries', 'site-transient', 'rss', 'users', 'user-queries', 'user_meta', 'useremail', 'userlogins', 'userslugs'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins', 'theme_json'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
    // If we still have items in the switched stack, consider ourselves still 'switched'.
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 6.2

/**
 * Restores the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
        // If we still have items in the switched stack, consider ourselves still 'switched'.
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('blog-details', 'blog-id-cache', 'blog-lookup', 'blog_meta', 'global-posts', 'networks', 'sites', 'site-details', 'site-options', 'site-transient', 'rss', 'users', 'useremail', 'userlogins', 'usermeta', 'user_meta', 'userslugs'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins', 'theme_json'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
    // If we still have items in the switched stack, consider ourselves still 'switched'.
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 6.1

/**
 * Restore the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
        // If we still have items in the switched stack, consider ourselves still 'switched'.
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('blog-details', 'blog-id-cache', 'blog-lookup', 'blog_meta', 'global-posts', 'networks', 'sites', 'site-details', 'site-options', 'site-transient', 'rss', 'users', 'useremail', 'userlogins', 'usermeta', 'user_meta', 'userslugs'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
    // If we still have items in the switched stack, consider ourselves still 'switched'.
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 5.4

/**
 * Restore the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
        // If we still have items in the switched stack, consider ourselves still 'switched'.
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id, 'restore');
    // If we still have items in the switched stack, consider ourselves still 'switched'.
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 5.3

/**
 * Restore the current blog, after calling switch_to_blog().
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb               WordPress database abstraction object.
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog.
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $new_blog_id = array_pop($GLOBALS['_wp_switched_stack']);
    $prev_blog_id = get_current_blog_id();
    if ($new_blog_id == $prev_blog_id) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $new_blog_id, $prev_blog_id);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($new_blog_id);
    $GLOBALS['blog_id'] = $new_blog_id;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($new_blog_id);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $new_blog_id, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 5.1

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    $blog_id = get_current_blog_id();
    if ($blog_id == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $blog_id;
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.9

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU (3.0.0)
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    $blog_id = get_current_blog_id();
    if ($blog_id == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $blog_id;
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.8

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb, $wp_roles;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    $blog_id = get_current_blog_id();
    if ($blog_id == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $blog_id;
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        $wp_roles = new WP_Roles();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.7

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb, $wp_roles;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    $blog_id = get_current_blog_id();
    if ($blog_id == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $blog_id;
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                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'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        $wp_roles = new WP_Roles();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.6

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    if ($GLOBALS['blog_id'] == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $GLOBALS['blog_id'];
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                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'));
            }
            wp_cache_add_non_persistent_groups(array('counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        wp_roles()->reinit();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.5

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    if ($GLOBALS['blog_id'] == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $GLOBALS['blog_id'];
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                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'));
            }
            wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        wp_roles()->reinit();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: .10

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    if ($GLOBALS['blog_id'] == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $GLOBALS['blog_id'];
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                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'));
            }
            wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        wp_roles()->reinit();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.3

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @global wpdb            $wpdb
 * @global array           $_wp_switched_stack
 * @global int             $blog_id
 * @global bool            $switched
 * @global string          $table_prefix
 * @global WP_Object_Cache $wp_object_cache
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    if ($GLOBALS['blog_id'] == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $GLOBALS['blog_id'];
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                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'));
            }
            wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        wp_roles()->reinit();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 4.2

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb, $wp_roles;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    if ($GLOBALS['blog_id'] == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $GLOBALS['blog_id'];
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                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'));
            }
            wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        $wp_roles->reinit();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 3.8

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb, $wp_roles;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    if ($GLOBALS['blog_id'] == $blog) {
        /** This filter is documented in wp-includes/ms-blogs.php */
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $GLOBALS['blog_id'];
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache'));
            }
            wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        $wp_roles->reinit();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    /** This filter is documented in wp-includes/ms-blogs.php */
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}

WordPress Version: 3.7

/**
 * Restore the current blog, after calling switch_to_blog()
 *
 * @see switch_to_blog()
 * @since MU
 *
 * @return bool True on success, false if we're already on the current blog
 */
function restore_current_blog()
{
    global $wpdb, $wp_roles;
    if (empty($GLOBALS['_wp_switched_stack'])) {
        return false;
    }
    $blog = array_pop($GLOBALS['_wp_switched_stack']);
    if ($GLOBALS['blog_id'] == $blog) {
        do_action('switch_blog', $blog, $blog);
        // If we still have items in the switched stack, consider ourselves still 'switched'
        $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
        return true;
    }
    $wpdb->set_blog_id($blog);
    $prev_blog_id = $GLOBALS['blog_id'];
    $GLOBALS['blog_id'] = $blog;
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    if (function_exists('wp_cache_switch_to_blog')) {
        wp_cache_switch_to_blog($blog);
    } else {
        global $wp_object_cache;
        if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
        wp_cache_init();
        if (function_exists('wp_cache_add_global_groups')) {
            if (is_array($global_groups)) {
                wp_cache_add_global_groups($global_groups);
            } else {
                wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache'));
            }
            wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
        }
    }
    if (did_action('init')) {
        $wp_roles->reinit();
        $current_user = wp_get_current_user();
        $current_user->for_blog($blog);
    }
    do_action('switch_blog', $blog, $prev_blog_id);
    // If we still have items in the switched stack, consider ourselves still 'switched'
    $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
    return true;
}