WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/restore current blog

Contents

Description

Restore the current blog, after calling switch_to_blog().

Usage

<?php restore_current_blog() ?>

Parameters

This function does not accept any parameters

Return Values

(boolean) 
True on success, False if we're already on the current blog

Examples

switch_to_blog( 5 );

/* Do stuff */

restore_current_blog();

Notes

restore_current_blog() should be called after every switch_to_blog(). If not, a global variable which monitors the switching, $GLOBALS['_wp_switched_stack'], will not be empty even if you use switch_to_blog() to return to the original blog. If $GLOBALS['_wp_switched_stack'] is not empty, WP will think it is in a switched state and can potentially return the wrong URL for the site via wp_upload_dir(). See http://wordpress.stackexchange.com/a/123516/27757

When calling switch_to_blog() repeatedly, either call restore_current_blog() each time, or save the original blog ID until the end and call switch_to_blog() with that and do:

$GLOBALS['_wp_switched_stack'] = array();
$GLOBALS['switched'] = false;

The former is probably preferable, as it is not a hack.

Change Log

Since: 3.0.0

Source File

restore_current_blog() is located in wp-includes/ms-blogs.php

Related

switch_to_blog(), ms_is_switched(), restore_current_blog(), get_current_blog_id(), wp_get_sites(), get_blog_details()

See also index of Function Reference and index of Template Tags.