wppaste
WordPress

do_action( 'switch_blog', int $new_blog_id, int $prev_blog_id, string $context )

Since
MU (3.0.0), 5.4.0
Fires when the blog is switched.

Compatibility

WordPress
since 5.4.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Parameters

$new_blog_idint
New blog ID.
$prev_blog_idint
Previous blog ID.
$contextstring
Additional context. Accepts 'switch' when called from switch_to_blog() or 'restore' when called from restore_current_blog().

Where this hook fires · 4

  • wp-includes/ms-blogs.php:522switch_to_blog()
  • wp-includes/ms-blogs.php:582switch_to_blog()
  • wp-includes/ms-blogs.php:616restore_current_blog()
  • wp-includes/ms-blogs.php:677restore_current_blog()

Source code

		 *		 * @param int    $new_blog_id  New blog ID.		 * @param int    $prev_blog_id Previous blog ID.		 * @param string $context      Additional context. Accepts 'switch' when called from switch_to_blog()		 *                             or 'restore' when called from restore_current_blog().		 */		do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' ); 		$GLOBALS['switched'] = true; 		return true;	}

Changelog

Introduced in 5.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.4.0
The $context parameter was added.from the docblock
MU (3.0.0)
MU (3.0.0)from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.