代码添加 Email 登录功能,添加以下代码至 Functions.php:
- //remove WordPress authentication
- 20);
- //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
- }
- 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
- //bad email
- if(!$user){
- 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
- 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);