Skip Navigation

[Resolved] Toolset login form custom error message

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to change the following two text strings associated with Toolset's login forms:
1. ERROR: The password you entered for the username **USERNAME** is incorrect.
2. Unknown Error.

Solution: You can use the following function to override the two error messages you mentioned for the login form shortcode:

add_filter( 'gettext', 'tssupp_login_errors', 20, 3 );
function tssupp_login_errors( $translated_text, $text, $domain ) {
    // change the text here to customize the messages.
    $incorrect_msg = "The information you entered is incorrect.";
    $unknown_msg = "There was an unexpected error, please try again.";
    // do not edit below this line.
     
    if ( !is_admin() ) {
 
        switch ( $translated_text ) {
 
            case 'The password you entered for the username %s is incorrect.' :
 
                $translated_text = $incorrect_msg;
                break;
 
            case 'Unknown error.' :
 
                $translated_text = $unknown_msg;
                break;
        }
 
    }
 
    return $translated_text;
}

Relevant Documentation:
https://developer.wordpress.org/reference/hooks/gettext/
https://developer.wordpress.org/reference/functions/__/

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Ankit Katailiha 2 years, 2 months ago.

Assigned support staff: Christian Cox.

Author
Posts
#2103033

Hi,
I am using toolset login form in my website. I need to changes the login error messages as they are disclosing the username like "ERROR: The password you entered for the username someone@gmail.com is incorrect." and also I need to change the error message "Unknown Error".
Could you please help me?
P.S. - I have already tried 7-8 functions with different hooks and none of them worked for me!

#2103349

I am using toolset login form in my website. I need to changes the login error messages as they are disclosing the username like "ERROR: The password you entered for the username someone@gmail.com is incorrect." and also I need to change the error message "Unknown Error".
Hello, the solution here may depend on the theme and other plugins installed on your site, as those other components could be adding their own overrides, translations, and other customizations in a way that prevents custom code solutions from having the desired effect. If you're using WPML, you can edit these strings using String Translation. In most cases, you can use the following function to override the two error messages you mentioned for the login form shortcode:

add_filter( 'gettext', 'tssupp_login_errors', 20, 3 );
function tssupp_login_errors( $translated_text, $text, $domain ) {
    // change the text here to customize the messages.
    $incorrect_msg = "The information you entered is incorrect.";
    $unknown_msg = "There was an unexpected error, please try again.";
    // do not edit below this line.
    
    if ( !is_admin() ) {

        switch ( $translated_text ) {

            case 'The password you entered for the username %s is incorrect.' :

                $translated_text = $incorrect_msg;
                break;

            case 'Unknown error.' :

                $translated_text = $unknown_msg;
                break;
        }

    }

    return $translated_text;
}

If this does not solve the problem, I'll need to take a look at your site's debug information. We have instructions for sharing your debug information here:
https://toolset.com/faq/provide-debug-information-faster-support/

#2103671

Hi,
I am not using the WPML plugin. I am using Astra theme and Toolset plugins only. The registration and login form both created with Toolset plugin.

#2104123
Screen Shot 2021-07-01 at 1.45.14 PM.png
Screen Shot 2021-07-01 at 1.45.24 PM.png

I am not using the WPML plugin. I am using Astra theme and Toolset plugins only.
That's fine. The function I provided should be effective in this scenario. I am showing screenshots here so you can see how I added the custom function to a new custom code snippet in Toolset > Settings > Custom Code. I just tested with Astra, Types, Views, and Forms active in my test site, and I was able to see an updated error message in my local environment.

The "incorrect password" message now says "The information you entered is incorrect." instead of "The password you entered for the username someone@gmail.com is incorrect."

The "unknown error" message now says "There was an unexpected error, please try again." instead of "Unknown error."

You can customize these example messages in the code snippet if you'd like to display different messages.

#2106803

Code worked!!
My issue is resolved now.
Thank you