wordpress log in page either using either username or email

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.

Read More

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);
  }

Related posts

2 comments

  1. Put this code function.php

    Username and Email (both are Login)

    remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
         add_filter( 'authenticate', 'tcb_authenticate_username_password', 20, 3 );
    
    
           function tcb_authenticate_username_password( $user, $username, $password ) {
              if ( ! empty( $username ) && is_email( $username ) ) :
                if ( $user = get_user_by_email( $username ) )
                  $username = $user->user_login;
              endif;
    
              return wp_authenticate_username_password( null, $username, $password );
            }
    

    Username (only username through login)

    function login_with_email_address($username) {
    
        $user = get_user_by('email',$username);
        if(!empty($user->user_login))
            $username = $user->user_login;  
        return $username;
    }
    add_action('wp_authenticate','login_with_email_address',10,1);
    
  2. Answer in short, you can configure WordPress to login with email.

    Three Steps:

    • Remove default authentication function
    • Add custom authentication function
    • Change text “Username” in wp-login.php to “E-Mail”

    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.

Comments are closed.