这是我正在使用的代码
首先,我删除了Wordpress身份验证
remove_filter(\'authenticate\', \'wp_authenticate_username_password\', 20);
然后我添加了自己的身份验证
add_filter(\'authenticate\', function($user, $email, $password){
$phone = $wpdb->escape($_REQUEST[\'phone\']);
$password = $wpdb->escape($_REQUEST[\'password\']);
if(empty($phone) || empty ($password)){
//create new error object and add errors to it.
$error = new WP_Error();
if(empty($phone)){
$error->add(\'empty_phone\', __(\'<strong>ERROR</strong>: Phone field is empty.\'));
}
if(empty($password)){
$error->add(\'empty_password\', __(\'<strong>ERROR</strong>: Password field is empty.\'));
}
return $error;
}
$user = reset(
get_users(
array(
\'meta_key\' => \'phone\',
\'meta_value\' => $phone,
\'number\' => 1,
\'count_total\' => false
)
)
);
if(!$user){
$error = new WP_Error();
$error->add(\'invalid\', __(\'<strong>ERROR</strong>: Either the phone 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 phone or password you entered is invalid.\'));
return $error;
}else{
return $user; //passed
}
}
}, 20, 3);
最后是我的HTML表单
<form id="login" name="form" action="<?php echo wp_login_url(); ?>" method="post">
<input id="phone" type="text" placeholder="Phone Number" name="phone">
<input id="password" type="password" placeholder="Password" name="password">
<input id="submit" type="submit" name="submit" value="Submit">
</form>
它似乎不起作用。我输入了正确的电话号码和密码,但我只需要重新加载页面。有什么帮助或意见吗?