WindCodex SwitchUser Developer Reference
Constants
| Constant | Value | Description |
|---|---|---|
SWITCHUSER_VERSION | e.g. '1.0.2' | Current plugin version |
SWITCHUSER_PLUGIN_FILE | __FILE__ | Plugin file path |
SWITCHUSER_PLUGIN_DIR | plugin_dir_path() | Plugin directory |
SWITCHUSER_PLUGIN_URL | plugin_dir_url() | Plugin URL |
SWITCHUSER_PLUGIN_BASE | plugin_basename() | windcodex-switchuser/windcodex-switchuser.php |
Actions
| Action | Arguments | Description |
|---|---|---|
switchuser_switched | $data (array) | Fires after switching into a user. $data contains actor_id, origin_id, target_id, ip and time (UTC) |
switchuser_switched_back | $data (array) | Fires after switching back. $data contains actor_id, origin_id, from_id, ip and time (UTC) |
switchuser_before_settings | - | Fires at the top of the SwitchUser settings page |
SwitchUser also fires WordPress's standard wp_login action when it logs you into the target account and back.
Example - custom logging:
add_action( 'switchuser_switched', function ( array $data ) {
error_log( sprintf( 'User %d switched into user %d from %s', $data['actor_id'], $data['target_id'], $data['ip'] ) );
} );There are no filters.
Options
All settings are stored in the switchuser_settings option:
| Key | Type | Default | Description |
|---|---|---|---|
enable_user_switching | yes/no | yes | Master switch |
block_admin_targets | yes/no | no | Block switching into administrators |
allowed_switcher_roles | string | '' | Comma-separated role slugs allowed to switch (empty = edit_users) |
session_ttl_hours | int | 48 | Session Duration, 1–168 |
order_screen_enabled | yes/no | yes | WooCommerce order screen box |
profile_screen_enabled | yes/no | yes | Profile screen button |
PHP Methods
$core = SwitchUser_Core::instance();
// Can the current user start switching at all?
$core->current_user_can_switch(); // bool
// Can the current user switch into this account?
$core->can_switch_to_user( get_user_by( 'id', 42 ) ); // bool (takes a WP_User)