I am making a login form using customized wordpress code, I am stuck to enable users to log in with help of either of email or username.
Still they can use only username and verifying process I am doing with the help of wordpress function
$user_verify = wp_signon( $login_data, false );
Please let me know how can I make users login with any of username of email.
thank you.
I am using this code for login using username only. How can I change it for both of email and username to be logged in.
$username = $wpdb->escape($_REQUEST['username']);
$password = $wpdb->escape($_REQUEST['password']);
if ($username && $password) {
$login_data = array();
$login_data['user_login'] = $username;
$login_data['user_password'] = $password;
$user_verify = wp_signon( $login_data, false );
$user_check = $user_verify->user_id;
if(!empty($user_verify->id))
{
do_action('wp_login', $user_verify->user_login, $user_verify);
wp_set_current_user( $user_verify->ID );
wp_set_auth_cookie( $user_verify->ID );
$r2 = get_current_user_id();
$registerd = get_user_meta($r2, 'package', true);
global $current_user;
$user_id=$current_user->data->ID;
$paid_tag_list=get_user_meta($user_id,'tags','');
$used_tag_list=get_user_meta($user_id,'tags','');
$company_name=get_user_meta($user_id,'company_name','');
$used_tag=explode(',',$used_tag_list[0]);
$used_tags=explode(',',$used_tag_list[0]);
if($paid_tag_list[0])
$paid_tag=explode(',',$paid_tag_list[0]);
else
$paid_tag=array();;
$paid_list=array_unique(array_filter(array_merge($paid_tag,$used_tags)));
foreach ($paid_list as $c){
$paid_l[]=str_replace(' ','',$c);
}
$directs=$wide->Getdirect();
foreach($directs as $key=>$value)
{
if($value==$info_post['desired_direction'][0])
{
$direct[]=$value ;
}
else
{
$direct[]=$value;
}
}
$states=array('USA'=>array(
'ALABAMA',
'Aguascalientes',
'Morelos',
'Tlaxcala',
)
);
$array = array("status" => "success", "message" => "user login","cars"=>$paid_l,"company"=>$company_name,"states"=>$states,"direction"=>$direct);
echo json_encode($array);
} else {
$array = array("status" => "fail", "message" => "Enter Correct Log-in info");
echo json_encode($array);
}
}else {
$array = array("status" => "fail", "message" => "something missing");
echo json_encode($array);
}
Username and Email (both are Login)
Username (only username through login)
Answer in short, you can configure WordPress to login with email.
Three Steps:
Use remove_filter to remove the default authentication function and replace it with your own using add_filter and then update wp-login.php accordingly.