unhook_user_action( $connectors, 'clear_auth_cookie' ); $this->unhook_user_action( $connectors, 'set_logged_in_cookie' ); break; case 'switch_to_olduser': $this->unhook_user_action( $connectors, 'clear_auth_cookie' ); $this->unhook_user_action( $connectors, 'set_logged_in_cookie' ); break; case 'switch_off': $this->unhook_user_action( $connectors, 'clear_auth_cookie' ); break; } } /** * Fired when a user switches user with the User Switching plugin. * * @param int $user_id The ID of the user being switched to. * @param int $old_user_id The ID of the user being switched from. */ public function callback_switch_to_user( $user_id, $old_user_id ) { $user = get_userdata( $user_id ); $old_user = get_userdata( $old_user_id ); /* translators: %1$s: a user display name, %2$s: a username (e.g. "Jane Doe", "administrator") */ $message = _x( 'Switched user to %1$s (%2$s)', '1: User display name, 2: User login', 'stream' ); $this->log( $message, array( 'display_name' => $user->display_name, 'user_login' => $user->user_login, ), $old_user->ID, 'sessions', 'switched-to', $old_user->ID ); } /** * Fired when a user switches back to their previous user account with the User Switching plugin. * * @param int $user_id The ID of the user being switched back to. * @param int|false $old_user_id The ID of the user being switched from, or false if the user is switching back * after having been switched off. */ public function callback_switch_back_user( $user_id, $old_user_id ) { $user = get_userdata( $user_id ); /* translators: Placeholders refer to a user display name, and a username (e.g. "Jane Doe", "administrator") */ $message = _x( 'Switched back to %1$s (%2$s)', '1: User display name, 2: User login', 'stream' ); if ( $old_user_id ) { $old_user = get_userdata( $old_user_id ); } else { $old_user = $user; } $this->log( $message, array( 'display_name' => $user->display_name, 'user_login' => $user->user_login, ), $old_user->ID, 'sessions', 'switched-back', $old_user->ID ); } /** * Fired when a user switches off with the User Switching plugin. * * @param int $old_user_id The ID of the user switching off. */ public function callback_switch_off_user( $old_user_id ) { $old_user = get_userdata( $old_user_id ); $message = __( 'Switched off', 'stream' ); $this->log( $message, array(), $old_user->ID, 'sessions', 'switched-off', $old_user->ID ); } /** * Unhook the requested action from the Users connector. * * @param Connectors $connectors The Connectors instance. * @param string $action The name of the action to unhook. */ protected function unhook_user_action( Connectors $connectors, $action ) { foreach ( $connectors->connectors as $connector ) { if ( 'users' === $connector->name ) { remove_action( $action, array( $connector, 'callback' ) ); } } } }