我更改了默认的注册选项,允许用户使用其电子邮件地址注册。他们还可以选择添加自己的名字和姓氏,但这不是必需的。
// Allow email instead of nickname for login
add_filter(\'authenticate\', function($user, $email, $password){
//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
$error->add(\'empty_username\', __(\'<strong>Viga</strong>: Unustasid sisestada e-posti aadressi\'));
}
else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //Invalid Email
$error->add(\'invalid_username\', __(\'<strong>Viga</strong>: E-posti aadress on vale.\'));
}
if(empty($password)){ //No password
$error->add(\'empty_password\', __(\'<strong>Viga</strong>: Unustasid sisestada parooli\'));
}
return $error;
}
//Check if user exists in WordPress database
$user = get_user_by(\'email\', $email);
//bad email
if(!$user){
$error = new WP_Error();
$error->add(\'invalid\', __(\'<strong>Viga</strong>: E-posti aadress või parool ei ole õige.\'));
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>Viga</strong>: E-posti aadress või parool ei ole õige.\'));
return $error;
}else{
return $user; //passed
}
}
}, 20, 3);
但这带来了一个问题。在“作者”页面上,用户的电子邮件地址变为公共地址:http://example.com/author/email-address/
我知道如何更改URL的/作者/部分:add_action(\'init\', \'cng_author_base\');
function cng_author_base() {
global $wp_rewrite;
$author_slug = \'autor\'; // change slug name
$wp_rewrite->author_base = $author_slug;
}
但不是如何更改用户名以显示作者的ID。能做到吗?