Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How can I allow access to two user accounts using one login?

I would reverse engineer the User Switching plugin and then create a solution that works for you. Fortunately there is not a whole lot of work to do. Most of the crucial functionality is in this function:

function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
    if ( ! $user = get_userdata( $user_id ) ) {
        return false;
    }

    $old_user_id = get_current_user_id();

    if ( $set_old_user && $old_user_id ) {
        user_switching_set_olduser_cookie( $old_user_id );
    } else {
        user_switching_clear_olduser_cookie( false );
    }

    wp_clear_auth_cookie();
    wp_set_auth_cookie( $user_id, $remember );
    wp_set_current_user( $user_id );

    if ( $set_old_user ) {
        do_action( 'switch_to_user', $user_id, $old_user_id );
    } else {
        do_action( 'switch_back_user', $user_id, $old_user_id );
    }

    return $user;
}

You could just maintain a list of “linked accounts” for each user to determine if a user is allowed to switch to another account.

Pseudo code:

$switch_to = 0; // some user id
$linked_accounts = get_linked_accounts( get_current_user_id() );
if(in_array($switch_to, $linked_accounts)) {
    switch_to_user($switch_to)
}

You would need to define get_linked_accounts and setup a way to actually do the linking. You should also do a lot of testing to make sure users will not be able to switch to any arbitrary account.

Related Posts:

  1. Woocommerce registration page [closed]
  2. Website Visible only to Registered users
  3. moving server can not login
  4. how to update current logged user username
  5. Redirecting or displaying a message on first login
  6. Password protect media attachment – share across guests
  7. WordPress login problem
  8. WordPress Login redirection according to user role
  9. How to restrict access to a single for users I’ve authorized? [closed]
  10. Sign in with social media accounts without creating a WP account [closed]
  11. Anonymous users can not access website
  12. Custom user roles are unable to login
  13. How to password protect pages in WordPress
  14. How to lock WordPress front-end with login and password?
  15. Updating usermeta from login redirect to billing address
  16. How do i Redirect specific user(WooCommerce Sign-in not wordpress admin page sign-in) to specific page
  17. redirect not logged in users to specific page and redirect them back where they come from
  18. Creating Custom Login Form Where Password Field is Dropdown Menu
  19. In Django, how do I know the currently logged-in user?
  20. Can I programmatically login a user without a password?
  21. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  22. Is there any way to rename or hide wp-login.php?
  23. How to login with email only no username?
  24. How can I redirect user after entering wrong password?
  25. Increase of failed login attempts, brute force attacks? [closed]
  26. Login page ERROR: Cookies are blocked due to unexpected output
  27. Separate registration and login for different roles
  28. SSO / authentication integration with external ‘directory service’
  29. Preventing session timeout
  30. How reduce wordpress login session timeout time?
  31. How to prefill WordPress registration with social details
  32. Check for correct username on custom login form
  33. Disallow user from editing their own profile information
  34. I can’t access my site via wp-admin
  35. ‘Password field is empty’ error when using autofill in Chrome
  36. Removing username from the ‘wordpress_logged_in’ cookie
  37. How to show ‘login error’ and ‘lost password’ on my template page?
  38. What is $interim_login?
  39. Custom login form
  40. How to prefill the username/password fields on the login page
  41. wp_signon returns user, but the user is not logged in
  42. Adding extra authentication field in login page
  43. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  44. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  45. wp_signon() does not authenticate user guidance needed
  46. What exactly is ReAuth?
  47. What are the differences between wp_users and wp_usermeta tables?
  48. Login members using web services
  49. Make my wordpress blog remember my login “forever”
  50. How to check in timber if user is loggedin?
  51. How do I change the language of only the login page?
  52. Disable WordPress 3.6 idle logout / login modal window / session expiration
  53. Stop WordPress from logging me out (need to keep me logged in)
  54. How to disable autocomplete on the wp-login.php page
  55. Share login data/cookies between multiple installations
  56. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  57. How to pass users back and forth using session data?
  58. How do I change the logo on the login page?
  59. Why does WordPress hide the reset password key from the URL?
  60. Is it possible to sign in with user_email in WordPress?
  61. How to use current_user_can()?
  62. Avoid to load default WP styles in login screen
  63. WordPress registration message
  64. How to fake a WordPress login?
  65. how to display the wordpress login and register forms on a page?
  66. Does wp_logout_url() destroy a session? (Logging out question)
  67. How can I send a welcome email to a user AFTER they login for the first time?
  68. Can not login with correct username and password
  69. How can i increase the login expiration length?
  70. How do I use add_action from a class method?
  71. How to remove the WordPress logo from login and register page?
  72. How can I add a custom script to footer of login page?
  73. Brute force attack?
  74. Customize wp_new_user_notification_email()
  75. Need to execute a cron job
  76. Login email after registration never sent or received
  77. How can I create a separate blog that is private?
  78. How to keep always logged in development environment
  79. Add Confirm Password field in wp-login.php Password Reset page
  80. Integrate recaptcha and wp_signon – what is needed?
  81. Stop users from logging in from multiple locations
  82. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  83. custom login page redirect to logged in user profile page
  84. Email address or username used to login in wordpress
  85. How do I check if a post is private?
  86. Front-end login: Redirect user to the post they had created
  87. Receiving “This content cannot be displayed in a frame” error on login page
  88. My login form does not work
  89. Programmatically log in a wordpress user
  90. Action wp_login_failed not working if only one field is filled out
  91. Remember page before login page, redirect to that page after login
  92. Getting “Cookies are blocked or not supported by your browser” on login page
  93. What is the purpose of logging out after WordPress upgrade?
  94. Is it alright for two people to simultaneously be logged into a WP site as administrator?
  95. wp-login.php redirecting to HTTPS
  96. Display last login time
  97. How to customise wp-login.php only for users who are setting a password for the first time?
  98. Intentionally Force Failed Login WordPress
  99. How do I turn off the ability to login?
  100. Gaining Login Access via the Database
Categories login Tags login, switch, user-access, woocommerce-offtopic
how to conditionally add attributes to start_lvl() function?
how to redirect to another post without getting headers already sent error?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress