Is there a way to give users that belong to a certain user role a unique error after failing to login?
Basically, I imported users from a site with a different CMS and it was near impossible to import their passwords. I would like to have the users of the older site belong to a specific user role to get an error saying due to the redevelopment of the website, they need to reset their passwords for security purposes.
Is there a way to give users that belong to a certain user role a unique error after failing to login?
Basically, I imported users from a site with a different CMS and it was near impossible to import their passwords. I would like to have the users of the older site belong to a specific user role to get an error saying due to the redevelopment of the website, they need to reset their passwords for security purposes.
Share Improve this question asked Apr 26, 2020 at 19:39 Michael R. BurkeMichael R. Burke 33 bronze badges1 Answer
Reset to default 0You can hook to the wp_login_errors
filter.
add_filter('wp_login_errors', function($errors, $redirect_to){
if(isset($errors->errors['incorrect_password']) &&
in_array('custom_role', (array) get_user_by('login', $_POST['log'])->roles)){
$errors->errors['incorrect_password'][0] = 'Custom message';
}
return $errors;
}, 10, 2);
EDIT:
This should work with WooCommerce login form or any other form that implements wp_signon
:
add_filter('authenticate', function($user, $username, $password){
if(is_wp_error($user) &&
isset($user->errors['incorrect_password']) &&
in_array('custom_role', (array) get_user_by('login', $username)->roles)){
$user->errors['incorrect_password'][0] = 'Custom message';
}
return $user;
}, 21, 3);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744524604a4578782.html
评论列表(0条)