From b0b36ae4b8e16cbf28081f222cd1f23bd086a242 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 20 Nov 2018 18:58:42 +0100 Subject: [PATCH] Add support for clearing a session and associated cart contents when switching between accounts using the User Switching plugin. See #21989. --- includes/class-wc-session-handler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/class-wc-session-handler.php b/includes/class-wc-session-handler.php index 5a4907b1a97..1b764502194 100644 --- a/includes/class-wc-session-handler.php +++ b/includes/class-wc-session-handler.php @@ -90,6 +90,11 @@ class WC_Session_Handler extends WC_Session { add_action( 'shutdown', array( $this, 'save_data' ), 20 ); add_action( 'wp_logout', array( $this, 'destroy_session' ) ); + // Support for the User Switching plugin. + add_action( 'switch_to_user', array( $this, 'forget_session' ) ); + add_action( 'switch_back_user', array( $this, 'forget_session' ) ); + add_action( 'switch_off_user', array( $this, 'forget_session' ) ); + if ( ! is_user_logged_in() ) { add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); }