From 05a2cd6f716e326fbf861a4cd15470de2d6fbcf4 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Wed, 22 Jan 2020 20:51:26 +0000 Subject: [PATCH] Multisite: Add `$context` parameter to `switch_blog` action. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. git-svn-id: https://develop.svn.wordpress.org/trunk@47105 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-blogs.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index 4cdb052b93..25dbe4b29f 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -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'] );