Choose which cookies we can use. You can change this at any time from “Cookie settings” in the footer. See our cookie policy for details.

Essential

Needed for the site to work, such as remembering your cookie choices. These can’t be switched off.

Always on
Skip to content
Developer reference

User Switching hooks

13 filters and actions, read from the plugin source. Add these in a theme’s functions.php or a Code Snippet.

  • 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/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 );