You 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);
Related Posts:
- Separate registration and login for different roles
- Disallow user from editing their own profile information
- Restricting frontend acess based on user role otherwise redirect to login form
- Deny a user role to log in after register
- Private page protected with username and password
- How to integrate external user tables with WP?
- Allow Users Only Edit Their Profile?
- Set Default User Role
- Lock out all WordPress Administrators except two specific users
- Generate email on meta value update
- WordPress Login redirection according to user role
- Prevent Subscriber Role to login
- Can I protect a type of content site-wide with a single password?
- Login Based on ip
- URL Restrictions? Need only people who are logged in AND have a specific role (or roles) to access all pages for a site
- Custom user roles are unable to login
- Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
- SSO / authentication integration with external ‘directory service’
- Preventing session timeout
- Check for correct username on custom login form
- ‘Password field is empty’ error when using autofill in Chrome
- Prevent wp_login_form() from redirecting to wp-admin when there are errors
- How to disable autocomplete on the wp-login.php page
- how to display the wordpress login and register forms on a page?
- How can I add a custom script to footer of login page?
- Is it alright for two people to simultaneously be logged into a WP site as administrator?
- How do I turn off the ability to login?
- Give visitor access to password protected page/post via external script
- WordPress Login Footer URL
- Save last login date in global before change it?
- Redirect after login based on user role (custom login page)
- wordpress custom login successful redirect hook
- How to get login data (session) outside WordPress?
- password protect individual pages
- Change register form action url
- Is back-end access not required for an app to post to my blog?
- Store brute-force IP addresses
- How do I make my site publicly viewable? Everything redirects to wp-admin
- How to create a private login page for admin.?
- WordPress Security – How to block alternative WordPress access
- Protecting WordPress login page
- Different homepage for logged in users
- reset password link redirect to login page
- Deregister default wp-admin css on login screen only?
- SSO to WP, from a non-wp site on a different domain and server
- How can I login as admin after redirect to custom login page
- Login with serialized password
- is_user_logged_in() not working in Firefox
- Why would the login page reload indefinitely?
- Creating custom login errors
- Removing wordpress cookie from non-wordpress site
- Why is wp-login trying to send an email?
- Replacing default display name to login name
- Why does is_user_logged_in() return false after I change user password on the front end?
- How to generate “WP_Error” Object for user login?
- ?login=failed only attached to URL under certain circumstances
- WordPress not logged in locally with correct username and password
- my wp-login page doesn’t load [closed]
- current_user_can(‘administrator’) not working in custom login
- Requiring login for specific pages
- login trouble WordPress can change IDs created by hoster site
- login/logout for only one page
- WordPress registration page template
- Removing “public” user registration without completely turning it off?
- Custom login modal page action
- Require re-login when logged-in user attempts to access restricted page
- Disable registration on certain condition
- Temporally disable password to login with empty password?
- Login error when username as email different to primary email
- Unable to login my wordpress website
- How do you implement a login feature on a WordPress site?
- Help! ERROR: Cookies are blocked due to unexpected output on attempting to login to resolve an issue with my site
- Cant reset password my wordpress password not even with phpMyAdmin
- Get WordPress logged in username from root domain when WP is installed in a subfolder
- How to invalidate `password reset key` after being used
- wp-cron event doesn’t run when custom login API is enabled
- Does it make sense to check a nonce on user log in?
- Special link for no automatic login (no username and no password)
- Global login to password protected pages
- Disable / Remove Password for Login WordPress
- WordPress Auto Login From Email Link
- Building a custom login form – encountering issues
- Making sure two different wordpress website has auto login
- Site login failed due to strange warning
- Conditional redirect on login using referring URL
- Chosen user password in registration is not being accepted on Login
- Improvements to “limit login attempts” plugin
- loging to Admin page not working at all
- Can’t login through wp-login.php on fresh installation
- WordPress Cookies – wp_set_auth_cookie
- Authenticate return value
- Front-end login problem: requires re-authorization when accessing dashboard
- Using wp_login_form passowrd as undefined
- Redirect non-members to about/intro page
- When trying to login if already logged in, form just shakes – error message remains empty
- Handle POST request sent from an external site for login?
- Unable to login after adding ReCaptacha without API key
- How to create an alternative login page that does not use any plugins?
- Entire WordPress content disappears
- Remove login link from Reset Password-screen