0

I am modifying my wp-login.php but from within functions.php (in order not to hack the core).

I need to disable one WP_error with code: authentication_failed.

if i hack the core and modify wp-login.php at the code:

foreach ( $wp_error->get_error_codes() as $code ) {
    $severity = $wp_error->get_error_data( $code );
    foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
            if ( 'message' == $severity )
                $messages .= '  ' . $error_message . "<br />\n";
            else
                $errors .= '    ' . $error_message . "<br />\n";
        }
}

to:

foreach ( $wp_error->get_error_codes() as $code ) {
        $severity = $wp_error->get_error_data( $code );
        if($code !=='authentication_failed'){ <======= ADDED
            foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
                  if ( 'message' == $severity )
                        $messages .= '  ' . $error_message . "<br />\n";
                  else
                        $errors .= '    ' . $error_message . "<br />\n";
            }
         }
}

It works. But I don't want to hack the core, is there a way to disable it from functions.php?

0

You can use the pluggable function wp_authenticate to override the core.

https://developer.wordpress.org/reference/functions/wp_authenticate/

Important caution: Test this code on a sandbox before deploying live!

function wp_authenticate($username, $password) {
    $username = sanitize_user($username);
    $password = trim($password);

    $user = apply_filters( 'authenticate', null, $username, $password );

    if ( $user == null ) {
        $user = new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username or incorrect password.' ) );
    }

    $ignore_codes = array( 'authentication_failed' );

    if ( is_wp_error( $user ) && !in_array( $user->get_error_code(), $ignore_codes ) ) {
        do_action( 'wp_login_failed', $username );
    }

    return $user;
}
add_action( 'init', 'wp_authenticate' );
|improve this answer|||||
  • it is breaking something on my end, i'll debug it and get back to you – shadesco Mar 17 '15 at 13:33
  • @shadesco Yeah, I feared that. An option would be to look at the code in Limit Login Attempts wordpress.org/plugins/limit-login-attempts (an old plugin, but still works fine) and see if maybe that gets you closer. – user12479 Mar 17 '15 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.