Support » Developing with WordPress » Suppressing login error reporting

  • Resolved Ate Up With Motor



    For a while now, I’ve had a function in my functions.php file (originally found in this article) to disable login error reporting. I found this morning that create_function is deprecated in recent versions of PHP, so I need to update the function to an anonymous one, but I don’t understand enough about PHP to do that, even though it’s a very simple one.

    The present function is this:
    add_filter('login_errors',create_function('$a', "return null;"));

    Could anyone help me figure out what an anonymous function version of this would be?


Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    Please replace that code with the following:

    function ps_disable_login_errors(){
      return ''; // or you can try return null
    add_filter( 'login_errors', 'ps_disable_login_errors' );

    I hope this will solve your issue.

    Kind Regards

    Thread Starter Ate Up With Motor



    Great, thank you so much! I really appreciate it.

    Glad to help you 🙂

    Moderator bcworkz


    FWIW you could instead do

    add_filter('login_errors', function() {
      return '';

    as long as PHP v5.3+ is used. The ability to create anonymous functions like this is in part the reason create_function() was deprecated. Except for very simple things like this, I personally think using named functions like Prashant suggests is better for anything more complicated because it makes your code clearer and more readable.

    Because the returned value is used in an echo statement, returning an empty string is more appropriate than null.

    Thread Starter Ate Up With Motor


    @bcworkz: I did decide to create a named function as @prashantvatsh suggested, and decided to return an error string that’s not empty, but is less specific than the default values. (I tried the empty string approach, but concluded that it would be better even for me — the only one who normally needs to log in — to return some kind of visible error so that it doesn’t seem like the login window is malfunctioning if I enter something incorrectly.)

    Thanks again for your input!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Suppressing login error reporting’ is closed to new replies.