• Hi,

    Love the plugin! One issue we have is that we login to many different users in a row. By default, the plugin requires us to logout of the old user (going back to the admin user) before logging into the next user. We tried to modify this behavior with this code:

    add_filter ('wp_redirect', 'dscsa_wp_redirect');
    function dscsa_wp_redirect($location) {
    
      //If Admin is impersonating user and tries to impersonate a different user before logging out of old user, they will be redirected to old users page
      //So we logout of that user first then redirect to that page again
      if (is_impersonating() AND trying_to_impersonate_next_user()) {
    
        //Destroy current impersonated session so that we go back to admin
        wp_destroy_current_session();
        wp_logout();
    
        //Now that we are in admin we should be able to impersonate next user
        return home_url('/wp-admin?impersonate='.$_GET[impersonate']);  
      }
    }

    But your plugin doesn’t seem to respect the programatic logout above, and we are just sent to the admin page. How best can we achieve this behavior?

    • This topic was modified 5 years, 2 months ago by akircher.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter akircher

    (@akircher)

    Never mind, looked through the plugin code and figured out a workaround:

    add_filter (‘wp_redirect’, ‘dscsa_wp_redirect’);
    function dscsa_wp_redirect($location) {
    
       if (is_impersonating() AND trying_to_impersonate_next_user()) {
    
          $_SERVER['HTTP_REFERER'] = home_url(home_url($_SERVER['REQUEST_URI']));
          wp_logout(); //Fast User Switching Hooks into this and redirects to $_SERVER['HTTP_REFERER'])
          exit;
       }
    }

    Hello, glad that you figure it out. Also thanks for the code snippet that worked.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Impersonate next user without logging out of previous user’ is closed to new replies.