How to Change WordPress Login Validation Messages?

1,757 views
Skip to first unread message

Toby Cryns

unread,
Jun 7, 2012, 2:58:43 PM6/7/12
to mpls-stpau...@googlegroups.com
How do I change all of my login validation messages to the same message?  

For example
  • "Error: The username field is empty." becomes "Sorry, but your login information is incorrect." 
  • "Error: The password field is empty." becomes "Sorry, but your login information is incorrect."
These messages are defined on line #80+ of wp-includes/user.php.

Thanks!
Toby

Nick Ciske

unread,
Jun 8, 2012, 9:46:02 AM6/8/12
to mpls-stpau...@googlegroups.com
$userdata = apply_filters('wp_authenticate_user', $userdata, $password);

You can add a filter for wp_authenticate_user and if it's an error (e.g. is_wp_error($userdata) ), adjust the verbiage in the WP_ERROR object, then pass it back to WP to display.

_________________________
Nick Ciske
@nciske

Toby C

unread,
Jun 8, 2012, 12:07:12 PM6/8/12
to mpls-stpau...@googlegroups.com
Nick,
I added the following to functions.php, and it is not working.  What am I missing?

add_filter('wp_authenticate_user', 'toby_custom_filter');
function toby_custom_filter ($userdata,$password) {
if ( is_wp_error($userdata) ) {
$userdata = 'Username Error Message Here';
return $userdata;
}
}

I checked out the codex pages for WP_Error and wp_authenticate_user() but was unable to figure this out.  Perhaps you can point me in the right direction.  

One big gap in my knowledge at present is that I do not understand the second part of your solution - both manipulating the WP_Error object and passing it back to WordPress.  I did a bunch of googling but was unable to come to a better understanding of the matter.

Any help you can provide will be greatly appreciated!

Thanks!
Toby


----


--
You received this message because you are subscribed to the Google Groups "Minneapolis St. Paul WordPress User Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mpls-stpaul-wordpress/-/A-2UU45AEeoJ.
To post to this group, send email to mpls-stpau...@googlegroups.com.
To unsubscribe from this group, send email to mpls-stpaul-word...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mpls-stpaul-wordpress?hl=en.

Nick Ciske

unread,
Jun 9, 2012, 9:18:38 AM6/9/12
to mpls-stpau...@googlegroups.com
Sorry, gave you bad info... you can't just filter part of the function, you have to override the entire thing.

Here's a Gist of the code as a plugin:

Just drop it into a subfolder called custom-login-message (or whatever), make your edits, and activate.

_________________________
Nick Ciske
@nciske

Toby C

unread,
Jun 11, 2012, 6:06:13 PM6/11/12
to mpls-stpau...@googlegroups.com
Nick,
Thanks so much!  This works perfectly.

Toby
--
You received this message because you are subscribed to the Google Groups "Minneapolis St. Paul WordPress User Group" group.

Nick Ciske

unread,
Jul 18, 2012, 12:41:22 PM7/18/12
to mpls-stpau...@googlegroups.com
From the WP-Hackers list... a plugin for this (of course):

You can also use the plugin "Unified Login Error Messages" 
which changes the error message to "ERROR: Invalid user/password 
combination." or anything you like. 
(http://wordpress.org/extend/plugins/unified-login-error-messages/)


Toby Cryns

unread,
Jul 18, 2012, 1:05:17 PM7/18/12
to mpls-stpau...@googlegroups.com
Brilliant!  Great find!

Toby

Syed Musaib Jeelani

unread,
Nov 27, 2018, 1:18:22 PM11/27/18
to Minneapolis St. Paul WordPress User Group
Nick Thank you so much.

Ule Stevenson

unread,
Jul 31, 2019, 6:02:42 PM7/31/19
to Minneapolis St. Paul WordPress User Group
It's been many years since the discussion has concluded, but I hope someone sees this and can offer advice.

First of all, thank you Nick. This works brilliantly. My question: How to I add to it for function 'retrieve_password'? I adapted the code and changed the authentication messages, but I don't know how to alter the message for lostpassword -- I assume the function is 'retrieve_password'?
Reply all
Reply to author
Forward
0 new messages