WordPress.org

Ready to get started?Download WordPress

Forums

Login With Ajax
How To Change Error Notices (7 posts)

  1. Wasca
    Member
    Posted 2 years ago #

    Hi Guys

    Where do I go to change the error notices you see when there is an unsuccessful login.

    Example:

    I want to change "ERROR: The username field is empty" to a custom message.

    Thanks

    Wasca

    http://wordpress.org/extend/plugins/login-with-ajax/

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    This is standard WP errors, not sure if there's a plugin that'd change those errors

  3. customedia
    Member
    Posted 2 years ago #

    This one as well is from wp?

    ERROR: The password you entered for the username demo is incorrect. Lost your password?

    I installed a plugin that takes care of the other messages but this one is the only one remaining. Could it be that Login with ajax is handling this one?

  4. Wasca
    Member
    Posted 2 years ago #

    What is the name of the plugin you used to change the standard messages?

  5. customedia
    Member
    Posted 2 years ago #

    Unified login error messages

  6. Wasca
    Member
    Posted 2 years ago #

    I found these error messages, they live in /wp-includes/user.php

    Now I just need to find a way of changing them without touching the source WP code.

    Any clues anyone?

  7. scsmash3r
    Member
    Posted 2 years ago #

    Hello, Wasca!

    Im having same problem, and I guess I've found a way to change any of those messages. I think it's not the right way I do it, but it works for me well =)

    You won't need to modify WP core files, but you will need to edit one of the plugin's PHP files - it's called login-with-ajax.php.

    This file is located right inside login-with-ajax plugin folder.

    So basically, the idea is to catch up error messages and replace them with your custom ones. All messages are handled through the WP native class WP Error.

    Read up some usefull info, using this link above. When you're done, you will then understand, that login-with-ajax plugin sends our post data (all that user fills into input fields during registration or login) and then receives answer, containing an error, if there is one.

    So now, look up into our login-with-ajax.php file and find line 195 and 226. It's those one lines, where an error result returns:

    $return['error'] = $loginResult->get_error_message(); // For Login fields
    $return['error'] = $errors->get_error_message(); // For registration fields

    Since plugin uses get_error_message() function, and we're already having some translation files, this error message will return already translated. So, we need to receive some other data to work with. Reading up class reference about WP error once again, you can find some other function called get_error_code(). So, let's replace get_error_message() with get_error_code() and see what happens on the site:

    $return['error'] = $loginResult->get_error_code();
    $return['error'] = $errors->get_error_code();

    You will now be able to see error codes instead of real human-readable error messages. Now, you can str_replace this error codes with some custom stuff. To do so, add these line after your modified 195 and 226 lines:

    $return['error'] = str_replace('empty_username', 'Oh my, you have no name, sir?', $return['error']);

    This example will replace an error message if the registration form's username is empty. You can check up all the other error codes by your own and str_replace them your own way :)

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic