我已经创建了一个WordPress网站。在user部分中,我创建了一个名为“Token”元字段的附加属性。每次创建新用户或用户登录并验证时,我都想用随机字符串更新此令牌属性。如果你能帮我做这件事,我将不胜感激。非常感谢。这是我在用户登录期间的代码,其中randomString是存储随机字符串的变量。
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";
}