Log In As Any User
23 Oct 2013, Posted by inIf you’re building a complex website with many roles, being able to switch between them quickly and easily would be useful. The wp_set_auth_cookie() lets you log the current user in based on ID.
$user_id = 4;
wp_set_auth_cookie( $user_id );
Take great care when using this function; left unchecked, it could log every user in as user number 4. Even while testing, I target it specifically to my IP, and maybe even to a special URL string just to be sure. That said, with proper safety, it can be used as part of a custom log-in script.