Login as User Shortcode [PRO Only]
The [login_as_user]
shortcode allows you to add a "Login as User" button to any post, page, or widget on your WordPress site. This facilitates easy and direct login as a specific user, which is particularly useful for administrators who need to quickly view or manage the site from another user's perspective.
Usage
[login_as_user user_id="USER_ID" redirect_to="URL_PATH" button_name="YOUR BUTTON NAME"]
Parameters
- user_id: Specify the ID of the user you want to impersonate. This parameter is required.
- redirect_to: Provide a URL or path to which the user should be redirected after logging in as the specified user. This parameter is optional.
- button_name: Customize the text of the button. You can use the $USER placeholder to dynamically insert the user's display name. This parameter is optional.
Example
[login_as_user user_id="357" redirect_to="/my-account" button_name="Login as $USER"]
In this example, the shortcode will render a button that allows a logged-in user to log in as the user with ID 357
. After logging in, the user will be redirected to /welcome-page
. The button text will display as Login as [User's Display Name]
.
Usage in PHP Code
You can also use the shortcode within your PHP code using the do_shortcode
function:
<?php echo do_shortcode('[login_as_user user_id="357" redirect_to="/my-account" button_name="Login as $USER"]'); ?>
Important Notes
- Replace
"357"
with the actual user ID of the account you wish to log in as. - Replace
"/my-account"
with the actual path or URL where you want the user to be redirected after logging in. - Replace
"Login as $USER"
with your preferred button name, using$USER
to dynamically include the user's display name if desired. - Ensure that you use valid URLs or WordPress path standards for the
redirect_to
parameter to avoid navigation errors. - Use this feature responsibly, especially on live sites, as it allows significant control over user accounts.
This shortcode is a powerful tool for site administrators and should be used with caution to ensure security and privacy.
* This feature is available only in the premium version of the plugin.