Multisite: Add `$context` parameter to `switch_blog` action.

The action is fired by both `switch_to_blog()` and `restore_current_blog()`, and previously it was difficult for callback functions to determine which function had fired it.

Props SergeyBiryukov, johnbillion, jeremyfelt.
Fixes #49265.

Built from https://develop.svn.wordpress.org/trunk@47105


git-svn-id: http://core.svn.wordpress.org/trunk@46905 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
iandunn 2020-01-22 20:53:05 +00:00
parent f34eef4437
commit 2974f78157
2 changed files with 10 additions and 7 deletions

View File

@ -508,11 +508,14 @@ function switch_to_blog( $new_blog_id, $deprecated = null ) {
* Fires when the blog is switched.
*
* @since MU (3.0.0)
* @since 5.4.0 The `$context` parameter was added.
*
* @param int $new_blog_id New blog ID.
* @param int $prev_blog_id Previous blog ID.
* @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 );
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
$GLOBALS['switched'] = true;
return true;
}
@ -544,7 +547,7 @@ function switch_to_blog( $new_blog_id, $deprecated = null ) {
}
/** This filter is documented in wp-includes/ms-blogs.php */
do_action( 'switch_blog', $new_blog_id, $prev_blog_id );
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
$GLOBALS['switched'] = true;
return true;
@ -577,7 +580,7 @@ function restore_current_blog() {
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 );
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;
@ -611,7 +614,7 @@ function restore_current_blog() {
}
/** This filter is documented in wp-includes/ms-blogs.php */
do_action( 'switch_blog', $new_blog_id, $prev_blog_id );
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'] );

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.4-alpha-47104';
$wp_version = '5.4-alpha-47105';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.