Auto login to WordPress using user email id or id

Posted on March 10, 2015 by Suresh Kamrushi in PHP

Using inbuilt functions of WordPress user can do auto login for the application. As a client requirement my wordpress need auto login using user email id, so after doing some google i came to know about function wp_set_current_user() which sets the current user (but does not do auto login) and wp_set_auth_cookie sets the authentication cookies using User ID.
Below is the complete code i got it from the function page:

My current WordPress version: 3.9

$email = $_GET['email'];
$user = get_user_by( 'email', $email );
if( $user ) {    
    wp_set_current_user( $user->ID, $user->user_login );
    wp_set_auth_cookie( $user->ID );
    do_action( 'wp_login', $user->user_login );
wp_redirect( home_url() ); 
  Comments or questions are welcome  
Tagged as ,