switch_blog
Fires when the blog is switched.
Usage
add_action( 'switch_blog', 'wp_kama_switch_blog_action', 10, 3 );
/**
* Function for `switch_blog` action-hook.
*
* @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().
*
* @return void
*/
function wp_kama_switch_blog_action( $new_blog_id, $prev_blog_id, $context ){
// action...
}
- $new_blog_id(int)
- New blog ID.
- $prev_blog_id(int)
- Previous blog ID.
- $context(string)
- Additional context. Accepts 'switch' when called from switch_to_blog() or 'restore' when called from restore_current_blog().
Changelog
| Since 3.0.0 | Introduced. |
| Since 5.4.0 | The $context parameter was added. |
Where the hook is called
switch_blog
switch_blog
wp-includes/ms-blogs.php 527
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
wp-includes/ms-blogs.php 541
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
wp-includes/ms-blogs.php 575
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
wp-includes/ms-blogs.php 590
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
Where the hook is used in WordPress
wp-includes/class-wp-roles.php 381
remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 );
wp-includes/class-wp-roles.php 385
add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 );
wp-includes/ms-default-filters.php 37
add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 );
wp-includes/ms-site.php 934
remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 );
wp-includes/ms-site.php 944
add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 );