User Switching hooks
13 filters and actions, read from the plugin source. Add these in a theme’s functions.php or a Code Snippet.
- action
wpextended/user-switching/clear_olduser_cookie
Fires just before the user switching cookies are cleared.
add_action( 'wpextended/user-switching/clear_olduser_cookie', function () { // Your code here } ); - filter
wpextended/user-switching/current_old_user
Filters the old user object retrieved from the cookie.
- $old_user
- (WP_User|false) The old user object
Returns: WP_User|false The filtered old user object
add_filter( 'wpextended/user-switching/current_old_user', function ( $old_user ) { return $old_user; } ); - filter
wpextended/user-switching/do_switch_off
Filters the result of the switch off operation.
- $success
- (bool) Whether the switch off operation was successful
Returns: bool Whether the operation should proceed
add_filter( 'wpextended/user-switching/do_switch_off', function ( $success ) { return $success; } ); - filter
wpextended/user-switching/get_redirect
Filters the final redirect URL for user switching operations.
- $redirectTo
- (string) The URL to redirect to
- $newUser
- (WP_User|null) The user being switched to (null when switching off)
- $oldUser
- (WP_User|null) The user being switched from
Returns: string The filtered redirect URL
add_filter( 'wpextended/user-switching/get_redirect', function ( $redirectTo, $newUser, $oldUser ) { return $redirectTo; }, 10, 3 ); - filter
wpextended/user-switching/login_message
Filters the login screen message when a user is switching or has switched.
- $message
- (string) The login message
Returns: string The filtered login message
add_filter( 'wpextended/user-switching/login_message', function ( $message ) { return $message; } ); - filter
wpextended/user-switching/redirect_to
Filters the redirect location after a user switches to another account or switches off
add_filter( 'wpextended/user-switching/redirect_to', function ( $value ) { return $value; } ); - filter
wpextended/user-switching/send_auth_cookies
add_filter( 'wpextended/user-switching/send_auth_cookies', function ( $value ) { return $value; } ); - action
wpextended/user-switching/set_auth_cookie
Fires immediately before the User Switching authentication cookie is set.
- $auth_cookie
- (string) The auth cookie value
- $expiration
- (int) The cookie expiration timestamp
- $old_user_id
- (int) The ID of the old user
- $scheme
- (string) The auth scheme
- $token
- (string) The auth token
add_action( 'wpextended/user-switching/set_auth_cookie', function ( $auth_cookie, $expiration, $old_user_id, $scheme, $token ) { // Your code here }, 10, 5 ); - action
wpextended/user-switching/set_olduser_cookie
Fires immediately before the User Switching old user cookie is set.
- $olduser_cookie
- (string) The old user cookie value
- $expiration
- (int) The cookie expiration timestamp
- $old_user_id
- (int) The ID of the old user
- $scheme
- (string) The auth scheme
- $token
- (string) The auth token
add_action( 'wpextended/user-switching/set_olduser_cookie', function ( $olduser_cookie, $expiration, $old_user_id, $scheme, $token ) { // Your code here }, 10, 5 ); - action
wpextended/user-switching/switch_back_user
Fires when a user switches back to their originating account.
- $user_id
- (int) The ID of the user being switched to
- $old_user_id
- (int) The ID of the user being switched from
- $new_token
- (string) The token of the new user session
- $old_token
- (string) The token of the old user session
add_action( 'wpextended/user-switching/switch_back_user', function ( $user_id, $old_user_id, $new_token, $old_token ) { // Your code here }, 10, 4 ); - action
wpextended/user-switching/switch_off_user
Fires when a user switches off.
- $old_user_id
- (int) The ID of the user switching off.
- $old_token
- (string) The token of the session of the user switching off.
add_action( 'wpextended/user-switching/switch_off_user', function ( $old_user_id, $old_token ) { // Your code here }, 10, 2 ); - filter
wpextended/user-switching/switch_to_url
Filters the URL for switching to a user.
- $url
- (string) The URL for switching to the user
- $user
- (WP_User) The user being switched to
Returns: string The filtered URL
add_filter( 'wpextended/user-switching/switch_to_url', function ( $url, $user ) { return $url; }, 10, 2 ); - action
wpextended/user-switching/switch_to_user
Fires when a user switches to another user account.
- $user_id
- (int) The ID of the user being switched to
- $old_user_id
- (int) The ID of the user being switched from
- $new_token
- (string) The token of the new user session
- $old_token
- (string) The token of the old user session
add_action( 'wpextended/user-switching/switch_to_user', function ( $user_id, $old_user_id, $new_token, $old_token ) { // Your code here }, 10, 4 );
