我在wordpress中创建了一个寄存器表单并在ajax中进行了注册。 表格就像这样
<form id="user-register-form" method="" action="" novalidate="novalidate">
<div class="full-column-width">
<div class="half-column-width">
<input type="text" name="firstname" placeholder="First Name" id="firstname" required="" aria-required="true">
</div>
<div class="half-column-width">
<input type="text" name="lastname" placeholder="Last Name" id="lastname" required="" aria-required="true">
</div>
</div>
<div class="full-column-width">
<input type="email" name="email" placeholder="E-mail" id="email" required="" aria-required="true">
</div>
<div class="full-column-width">
<input type="number" name="phone" placeholder="Phone" id="phone" required="" aria-required="true">
</div>
<div class="full-column-width">
<input type="password" name="password" placeholder="Password" id="password" required="" aria-required="true">
</div>
<div class="full-column-width">
<input class="submit" type="submit" name="submit" id="user_get_register" value="Register">
</div>
</form>
在函数文件中我已经使我的函数像这样
function user_register() {
$data = $_POST['data'];
parse_str($data, $arr);
$userdata = array (
'user_login' => $arr['email'],
'firstname' => $arr['firstname'],
'lastname' => $arr['lastname'],
'email' => $arr['email'],
'phone' => $arr['phone'],
'password' => $arr['password'],
);
//check username exists
if( username_exists( $arr['email'] ) ) {
echo 'username exists';
}
else {
$id = wp_insert_user($userdata);
if( !is_wp_error( $id )) {
wp_set_current_user($id);
wp_set_auth_cookie($id);
echo 'user created';
}
}
exit;
}
add_action('wp_ajax_nopriv_user_register', 'user_register');
它正在向用户注册其详细信息,但是当我从wordpress管理员登录时执行相同的登录详细信息时,它无法正常工作。我检查了数据库。价值观在那里。每当我登录仪表板时,它都会显示
ERROR: The password you entered for the username test@name.com is incorrect.
有人可以告诉我为什么会出现这个错误吗?以及如何解决这个问题?
答案 0 :(得分:0)
您在用户数据中出错,将密码更改为user_pass
$userdata = array (
'user_login' => $arr['email'],
'firstname' => $arr['firstname'],
'lastname' => $arr['lastname'],
//'email' => $arr['email'], ---- cant store this with this function
//'phone' => $arr['phone'], --- cant store this with this function
'user_pass' => $arr['password'],
);
你也传递了wp_insert_user()不存在的键,你需要将它们保存为usermeta =
update_user_meta( $id, '_telephone', '555-555' );