Your account expired support, please renew to get your support.

Home Forums Themes Support Claue We want login should be using Phone or Email

Viewing 1 reply thread
  • Author
    Posts
    • #30177
      shopnslime
      Support Expired

      Hi,

      How to have login using Either Mobile or Email instead of Username.

    • #30179
      Harry
      Support Expired

      Hi,

      1. To login by use email, please add below code to claue-child > functions.php

      //remove wordpress authentication
      remove_filter('authenticate', 'wp_authenticate_username_password', 20);
      
      add_filter('authenticate', function($user, $email, $password){
       
          //Check for empty fields
              if(empty($email) || empty ($password)){        
                  //create new error object and add errors to it.
                  $error = new WP_Error();
       
                  if(empty($email)){ //No email
                      $error->add('empty_username', __('<strong>ERROR</strong>: Email field is empty.'));
                  }
                  else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //Invalid Email
                      $error->add('invalid_username', __('<strong>ERROR</strong>: Email is invalid.'));
                  }
       
                  if(empty($password)){ //No password
                      $error->add('empty_password', __('<strong>ERROR</strong>: Password field is empty.'));
                  }
       
                  return $error;
              }
       
              //Check if user exists in WordPress database
              $user = get_user_by('email', $email);
       
              //bad email
              if(!$user){
                  $error = new WP_Error();
                  $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.'));
                  return $error;
              }
              else{ //check password
                  if(!wp_check_password($password, $user->user_pass, $user->ID)){ //bad password
                      $error = new WP_Error();
                      $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.'));
                      return $error;
                  }else{
                      return $user; //passed
                  }
              }
      }, 20, 3);

      2. Or you can use this plugin to login by social account https://wordpress.org/plugins/miniorange-login-openid/, it doesn’t support login by phone number

      Kind regards

      Harry
      Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio

Viewing 1 reply thread

You must be logged in to reply to this topic.