switch_blog хук-событиеWP 3.0.0

Fires when the blog is switched.

Использование

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(строка)
Additional context. Accepts 'switch' when called from switch_to_blog() or 'restore' when called from restore_current_blog().

Список изменений

С версии 3.0.0 Введена.
С версии 5.4.0 The $context parameter was added.

Где вызывается хук

switch_to_blog()
switch_blog
restore_current_blog()
switch_blog
wp-includes/ms-blogs.php 526
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
wp-includes/ms-blogs.php 585
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
wp-includes/ms-blogs.php 619
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
wp-includes/ms-blogs.php 679
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );

Где используется хук в WordPress

wp-includes/class-wp-roles.php 363
remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 );
wp-includes/class-wp-roles.php 367
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 938
remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 );
wp-includes/ms-site.php 948
add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 );