admin管理员组文章数量:1130349
I have created a WordPress website. In the user section I have created an additional attribute called "Token" meta field. Every time a new user is created or a user logs in and is validated, I would like to update this Token attribute with a random string. I would really appreciate some help in going about doing this. Thank you. This is my code so far during a user log in where randomString is the variable storing the random string.
function login_user($request) {
$length = 10;
$characters =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$params = $request->get_params();
$email = $params['email'];
$pass = $params['password'];
$user = get_user_by('email', $email);
$user_id = $user->ID;
if ( $user && wp_check_password( $pass, $user->data->user_pass, $user->ID) ){
return $randomString;
return "true";
}
else {
return "false";
}
I have created a WordPress website. In the user section I have created an additional attribute called "Token" meta field. Every time a new user is created or a user logs in and is validated, I would like to update this Token attribute with a random string. I would really appreciate some help in going about doing this. Thank you. This is my code so far during a user log in where randomString is the variable storing the random string.
function login_user($request) {
$length = 10;
$characters =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$params = $request->get_params();
$email = $params['email'];
$pass = $params['password'];
$user = get_user_by('email', $email);
$user_id = $user->ID;
if ( $user && wp_check_password( $pass, $user->data->user_pass, $user->ID) ){
return $randomString;
return "true";
}
else {
return "false";
}
Share
Improve this question
asked Dec 3, 2018 at 9:04
Sanjana NanjappaSanjana Nanjappa
135 bronze badges
1 Answer
Reset to default 0You're almost there.
You can use this to update user meta: https://codex.wordpress/Function_Reference/update_user_meta.
Create your custom field using ACF (Advanced Custom Fields).
I have created a WordPress website. In the user section I have created an additional attribute called "Token" meta field. Every time a new user is created or a user logs in and is validated, I would like to update this Token attribute with a random string. I would really appreciate some help in going about doing this. Thank you. This is my code so far during a user log in where randomString is the variable storing the random string.
function login_user($request) {
$length = 10;
$characters =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$params = $request->get_params();
$email = $params['email'];
$pass = $params['password'];
$user = get_user_by('email', $email);
$user_id = $user->ID;
if ( $user && wp_check_password( $pass, $user->data->user_pass, $user->ID) ){
return $randomString;
return "true";
}
else {
return "false";
}
I have created a WordPress website. In the user section I have created an additional attribute called "Token" meta field. Every time a new user is created or a user logs in and is validated, I would like to update this Token attribute with a random string. I would really appreciate some help in going about doing this. Thank you. This is my code so far during a user log in where randomString is the variable storing the random string.
function login_user($request) {
$length = 10;
$characters =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$params = $request->get_params();
$email = $params['email'];
$pass = $params['password'];
$user = get_user_by('email', $email);
$user_id = $user->ID;
if ( $user && wp_check_password( $pass, $user->data->user_pass, $user->ID) ){
return $randomString;
return "true";
}
else {
return "false";
}
Share
Improve this question
asked Dec 3, 2018 at 9:04
Sanjana NanjappaSanjana Nanjappa
135 bronze badges
1 Answer
Reset to default 0You're almost there.
You can use this to update user meta: https://codex.wordpress/Function_Reference/update_user_meta.
Create your custom field using ACF (Advanced Custom Fields).
本文标签: phpUpdate an additional user meta field with a string
版权声明:本文标题:php - Update an additional user meta field with a string 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749132240a2320786.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论