Solution:1
Well, i could setup a script in the root of my site, that handles the automatic login of a user, when he clicks on the link in his email. The link has 2 parameters: his username and md5 string of his email.
For example, if the username is ‘sam‘ and his email is ‘samuel@example.com‘, the sample link in his email will be like:
http://www.example.com/user-login.php?username=sam&rand=ddb4b1cd8f56f9946b76399abb9d3106
Then finally the user-login.php script goes like this:
<?php
require_once ('wp-config.php');
if(isset($_GET['username']) && $_GET['username'] != '' &&
isset($_GET['rand']) && $_GET['rand'] != '')
{
$username = trim($_GET['username']);
$rand = trim($_GET['rand']);
global $wpdb;
$user_details = $wpdb->get_row("SELECT id, user_email FROM wp_users
WHERE user_login='".$username."'");
if(! $user_details->id)
{
die("Error: Not a valid user");
}
else
{
$rand_email = md5($user_details->user_email);
if($rand_email != $rand)
{
die("Error: Invalid URL");
}
else {
$user = get_user_by('login', $username );
if ( !is_wp_error( $user ) )
{
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID );
$redirect_to = get_option('siteurl');
wp_safe_redirect( $redirect_to );
exit();
}
}
}
}
else {
die("Error: Missing params");
}
?>
This way, when the user clicks on the link in his email, he will be automatically logged in and navigates to the home page.
Thanks to Sjoerd Linders for providing me an insight in his answer.