Store Locator Plus®

MySLP_Admin_UserSwitching
in package

Manage user switching.

Table of Contents

Properties

$application  : string
The name used to identify the application during a WordPress redirect.

Methods

action_admin_bar_menu()  : mixed
Adds a 'Switch back to {user}' link to the account menu, and a `Switch To` link to the user edit menu.
action_admin_notices()  : mixed
Displays the 'Switched to {user}' and 'Switch back to {user}' messages in the admin area.
action_bbpress_button()  : mixed
Adds a 'Switch To' link to each member's profile page in bbPress.
action_bp_button()  : mixed
Adds a 'Switch To' link to each member's profile page and profile listings in BuddyPress.
action_init()  : mixed
Loads localisation files and routes actions depending on the 'action' query var.
action_personal_options()  : mixed
Outputs the 'Switch To' link on the user editing screen if the current user has permission to switch to them.
action_wp_footer()  : mixed
Adds a 'Switch back to {user}' link to the WordPress footer if the admin toolbar isn't showing.
action_wp_meta()  : mixed
Adds a 'Switch back to {user}' link to the Meta sidebar widget.
authenticate_old_user()  : bool
Authenticates an old user by verifying the latest entry in the auth cookie.
current_url()  : string
Returns the current URL.
filter_login_message()  : string
Adds a 'Switch back to {user}' link to the WordPress login screen.
filter_map_meta_cap()  : array<string|int, string>
Filters the required primitive capabilities for the given primitive or meta capability.
filter_removable_query_args()  : array<string|int, string>
Filters the list of query arguments which get removed from admin area URLs in WordPress.
filter_user_has_cap()  : array<string|int, bool>
Filters a user's capabilities so they can be altered at runtime.
filter_user_row_actions()  : array<string|int, string>
Adds a 'Switch To' link to each list of user actions on the Users screen.
forget_woocommerce_session()  : mixed
Instructs WooCommerce to forget the session for the current user, without deleting it.
get_instance()  : user_switching
Singleton instantiator.
get_old_user()  : false|WP_User
Validates the old user cookie and returns its user data.
init_hooks()  : mixed
Sets up all the filters and actions.
maybe_switch_url()  : string|false
Returns the switch to or switch back URL for a given user.
remember()  : bool
Returns whether or not the current logged in user is being remembered in the form of a persistent browser cookie (ie. they checked the 'Remember Me' check box when they logged in). This is used to persist the 'remember me' value when the user switches to another user.
remove_query_args()  : string
Removes a list of common confirmation-style query args from a URL.
secure_auth_cookie()  : bool
Returns whether or not User Switching's equivalent of the 'auth' cookie should be secure.
secure_olduser_cookie()  : bool
Returns whether or not User Switching's equivalent of the 'logged_in' cookie should be secure.
switch_back_url()  : string
Returns the nonce-secured URL needed to switch back to the originating user.
switch_off_url()  : string
Returns the nonce-secured URL needed to switch off the current user.
switch_to_url()  : string
Returns the nonce-secured URL needed to switch to a given user ID.
get_redirect()  : string
Fetches the URL to redirect to for a given user (used after switching).
__construct()  : mixed
Private class constructor. Use `get_instance()` to get the instance.

Properties

$application

The name used to identify the application during a WordPress redirect.

public static string $application = 'WordPress/User Switching'

Methods

action_admin_bar_menu()

Adds a 'Switch back to {user}' link to the account menu, and a `Switch To` link to the user edit menu.

public action_admin_bar_menu(WP_Admin_Bar $wp_admin_bar) : mixed
Parameters
$wp_admin_bar : WP_Admin_Bar

The admin bar object.

action_admin_notices()

Displays the 'Switched to {user}' and 'Switch back to {user}' messages in the admin area.

public action_admin_notices() : mixed

action_bbpress_button()

Adds a 'Switch To' link to each member's profile page in bbPress.

public action_bbpress_button() : mixed

action_bp_button()

Adds a 'Switch To' link to each member's profile page and profile listings in BuddyPress.

public action_bp_button() : mixed

action_init()

Loads localisation files and routes actions depending on the 'action' query var.

public action_init() : mixed

action_personal_options()

Outputs the 'Switch To' link on the user editing screen if the current user has permission to switch to them.

public action_personal_options(WP_User $user) : mixed
Parameters
$user : WP_User

User object for this screen.

Adds a 'Switch back to {user}' link to the WordPress footer if the admin toolbar isn't showing.

public action_wp_footer() : mixed

action_wp_meta()

Adds a 'Switch back to {user}' link to the Meta sidebar widget.

public action_wp_meta() : mixed

authenticate_old_user()

Authenticates an old user by verifying the latest entry in the auth cookie.

public static authenticate_old_user(WP_User $user) : bool
Parameters
$user : WP_User

A WP_User object (usually from the logged_in cookie).

Return values
bool

Whether verification with the auth cookie passed.

current_url()

Returns the current URL.

public static current_url() : string
Return values
string

The current URL.

filter_login_message()

Adds a 'Switch back to {user}' link to the WordPress login screen.

public filter_login_message(string $message) : string
Parameters
$message : string

The login screen message.

Return values
string

The login screen message.

filter_map_meta_cap()

Filters the required primitive capabilities for the given primitive or meta capability.

public filter_map_meta_cap(array<string|int, string> $required_caps, string $cap, int $user_id, array<string|int, mixed> $args) : array<string|int, string>

This is used to:

  • Add the 'do_not_allow' capability to the list of required capabilities when a Super Admin is trying to switch to themselves.

It affects nothing else as Super Admins can do everything by default.

Parameters
$required_caps : array<string|int, string>

Array of required primitive capabilities for the requested capability.

$cap : string

Capability or meta capability being checked.

$user_id : int

Concerned user ID.

$args : array<string|int, mixed>

{ Arguments that accompany the requested capability check.

Tags
type

mixed ...$0 Optional second and further parameters. }

Return values
array<string|int, string>

Array of required capabilities for the requested action.

filter_removable_query_args()

Filters the list of query arguments which get removed from admin area URLs in WordPress.

public filter_removable_query_args(array<string|int, string> $args) : array<string|int, string>
Parameters
$args : array<string|int, string>

Array of removable query arguments.

Tags
link
https://core.trac.wordpress.org/ticket/23367
Return values
array<string|int, string>

Updated array of removable query arguments.

filter_user_has_cap()

Filters a user's capabilities so they can be altered at runtime.

public filter_user_has_cap(array<string|int, bool> $user_caps, array<string|int, string> $required_caps, array<string|int, mixed> $args, WP_User $user) : array<string|int, bool>

This is used to:

  • Grant the 'switch_to_user' capability to the user if they have the ability to edit the user they're trying to switch to (and that user is not themselves).
  • Grant the 'switch_off' capability to the user if they can edit other users.

Important: This does not get called for Super Admins. See filter_map_meta_cap() below.

Parameters
$user_caps : array<string|int, bool>

Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability.

$required_caps : array<string|int, string>

Array of required primitive capabilities for the requested capability.

$args : array<string|int, mixed>

{ Arguments that accompany the requested capability check.

$user : WP_User

Concerned user object.

Tags
type

string $0 Requested capability.

type

int $1 Concerned user ID.

type

mixed ...$2 Optional second and further parameters. }

Return values
array<string|int, bool>

Array of concerned user's capabilities.

filter_user_row_actions()

Adds a 'Switch To' link to each list of user actions on the Users screen.

public filter_user_row_actions(array<string|int, string> $actions, WP_User $user) : array<string|int, string>
Parameters
$actions : array<string|int, string>

Array of actions to display for this user row.

$user : WP_User

The user object displayed in this row.

Return values
array<string|int, string>

Array of actions to display for this user row.

forget_woocommerce_session()

Instructs WooCommerce to forget the session for the current user, without deleting it.

public forget_woocommerce_session() : mixed

get_instance()

Singleton instantiator.

public static get_instance() : user_switching
Return values
user_switching

User Switching instance.

get_old_user()

Validates the old user cookie and returns its user data.

public static get_old_user() : false|WP_User
Return values
false|WP_User

False if there's no old user cookie or it's invalid, WP_User object if it's present and valid.

maybe_switch_url()

Returns the switch to or switch back URL for a given user.

public static maybe_switch_url(WP_User $user) : string|false
Parameters
$user : WP_User

The user to be switched to.

Return values
string|false

The required URL, or false if there's no old user or the user doesn't have the required capability.

remember()

Returns whether or not the current logged in user is being remembered in the form of a persistent browser cookie (ie. they checked the 'Remember Me' check box when they logged in). This is used to persist the 'remember me' value when the user switches to another user.

public static remember() : bool
Return values
bool

Whether the current user is being 'remembered' or not.

remove_query_args()

Removes a list of common confirmation-style query args from a URL.

public static remove_query_args(string $url) : string
Parameters
$url : string

A URL.

Return values
string

The URL with query args removed.

Returns whether or not User Switching's equivalent of the 'auth' cookie should be secure.

public static secure_auth_cookie() : bool

This is used to determine whether to set a secure auth cookie or not.

Return values
bool

Should the auth cookie be secure?

Returns whether or not User Switching's equivalent of the 'logged_in' cookie should be secure.

public static secure_olduser_cookie() : bool

This is used to set the 'secure' flag on the old user cookie, for enhanced security.

Tags
link
https://core.trac.wordpress.org/ticket/15330
Return values
bool

Should the old user cookie be secure?

switch_back_url()

Returns the nonce-secured URL needed to switch back to the originating user.

public static switch_back_url(WP_User $user) : string
Parameters
$user : WP_User

The old user.

Return values
string

The required URL.

switch_off_url()

Returns the nonce-secured URL needed to switch off the current user.

public static switch_off_url(WP_User $user) : string
Parameters
$user : WP_User

The user to be switched off.

Return values
string

The required URL.

switch_to_url()

Returns the nonce-secured URL needed to switch to a given user ID.

public static switch_to_url(WP_User $user) : string
Parameters
$user : WP_User

The user to be switched to.

Return values
string

The required URL.

get_redirect()

Fetches the URL to redirect to for a given user (used after switching).

protected static get_redirect([WP_User $new_user = null ][, WP_User $old_user = null ]) : string
Parameters
$new_user : WP_User = null

Optional. The new user's WP_User object.

$old_user : WP_User = null

Optional. The old user's WP_User object.

Return values
string

The URL to redirect to.

__construct()

Private class constructor. Use `get_instance()` to get the instance.

private final __construct() : mixed

        
On this page

Search results