Store Locator Plus®

MySLP_Admin_UserSwitching.php

Table of Contents

Classes

MySLP_Admin_UserSwitching
Manage user switching.

Functions

user_switching_set_olduser_cookie()  : mixed
Sets authorisation cookies containing the originating user information.
user_switching_clear_olduser_cookie()  : mixed
Clears the cookies containing the originating user, or pops the latest item off the end if there's more than one.
user_switching_get_olduser_cookie()  : string|false
Gets the value of the cookie containing the originating user.
user_switching_get_auth_cookie()  : array<string|int, string>
Gets the value of the auth cookie containing the list of originating users.
switch_to_user()  : false|WP_User
Switches the current logged in user to the specified user.
switch_off_user()  : bool
Switches off the current logged in user. This logs the current user out while retaining a cookie allowing them to log straight back in using the 'Switch back to {user}' system.
current_user_switched()  : false|WP_User
Returns whether or not the current user switched into their account.

Functions

Sets authorisation cookies containing the originating user information.

user_switching_set_olduser_cookie(int $old_user_id[, bool $pop = false ][, string $token = '' ]) : mixed
Parameters
$old_user_id : int

The ID of the originating user, usually the current logged in user.

$pop : bool = false

Optional. Pop the latest user off the auth cookie, instead of appending the new one. Default false.

$token : string = ''

Optional. The old user's session token to store for later reuse. Default empty string.

Tags
since
1.4.0

The $token parameter was added.

Clears the cookies containing the originating user, or pops the latest item off the end if there's more than one.

user_switching_clear_olduser_cookie([bool $clear_all = true ]) : mixed
Parameters
$clear_all : bool = true

Optional. Whether to clear the cookies (as opposed to just popping the last user off the end). Default true.

Gets the value of the cookie containing the originating user.

user_switching_get_olduser_cookie() : string|false
Return values
string|false

The old user cookie, or boolean false if there isn't one.

Gets the value of the auth cookie containing the list of originating users.

user_switching_get_auth_cookie() : array<string|int, string>
Return values
array<string|int, string>

Array of originating user authentication cookie values. Empty array if there are none.

switch_to_user()

Switches the current logged in user to the specified user.

switch_to_user(int $user_id[, bool $remember = false ][, bool $set_old_user = true ]) : false|WP_User
Parameters
$user_id : int

The ID of the user to switch to.

$remember : bool = false

Optional. Whether to 'remember' the user in the form of a persistent browser cookie. Default false.

$set_old_user : bool = true

Optional. Whether to set the old user cookie. Default true.

Return values
false|WP_User

WP_User object on success, false on failure.

switch_off_user()

Switches off the current logged in user. This logs the current user out while retaining a cookie allowing them to log straight back in using the 'Switch back to {user}' system.

switch_off_user() : bool
Return values
bool

True on success, false on failure.

current_user_switched()

Returns whether or not the current user switched into their account.

current_user_switched() : false|WP_User
Return values
false|WP_User

False if the user isn't logged in or they didn't switch in; old user object (which evaluates to true) if the user switched into the current user account.


        
On this page

Search results