Fatal Error: Uncaught ArgumentCountError : Too few arguments to function

I am getting a fatal error when trying to login to the WP dashboard - and on logout after logging in via the host:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Wpsec\captcha\handlers\WPLoginEventHandler::handle_login_hook(), 1 passed in /var/www/wp-includes/class-wp-hook.php on line 308 and exactly 2 expected in /var/www/wp-content/mu-plugins/vendor/wpsec/wp-captcha-plugin/src/handlers/WPLoginEventHandler.php:24 Stack trace: #0 /var/www/wp-includes/class-wp-hook.php(308): Wpsec\captcha\handlers\WPLoginEventHandler->handle_login_hook(NULL) #1 /var/www/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(’’, Array) #2 /var/www/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /var/www/wp-content/themes/arya-multipurpose-child/functions.php(34): do_action(‘wp_login_failed’, NULL) #4 /var/www/wp-includes/class-wp-hook.php(308): {closure}(NULL, ‘’, ‘’) #5 /var/www/wp-includes/plugin.php(205): WP_Hook->apply_filters(NULL, Array) #6 /var/www/wp-includes/pluggable.php(614): apply_filters(‘authenticate’, NULL, ‘’, ‘’) #7 /var/www/wp-includes/user.php(95): wp_authenticate(’’, ‘’) #8 /var/www/wp-login.php in /var/www/wp-content/mu-plugins/vendor/wpsec/wp-captcha-plugin/src/handlers/WPLoginEventHandler.php on line 24

I have only added code to arya-multipurpose-child/functions.php:

//add hook to redirect the user back to the elementor login page if the login failed
add_action( 'wp_login_failed', 'elementor_form_login_fail' );
function elementor_form_login_fail( $username ) {
    $referrer = wp_get_referer();  // where did the post submission come from?
//    $referrer = array();
    // if there's a valid referrer, and it's not the default log-in screen
    if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
        //redirect back to the referrer page, appending the login=failed parameter and removing any previous query strings
        //maybe could be smarter here and parse/rebuild the query strings from the referrer if they are important
        wp_redirect(preg_replace('/\?.*/', '', $referrer) . '/?login=failed' );
        exit;
    }
}

add_filter( 'authenticate', function( $user, $username, $password ) {
    // forcefully capture login failed to forcefully open wp_login_failed action, 
    // so that this event can be captured
    if ( empty( $username ) || empty( $password ) ) {
        do_action( 'wp_login_failed', $user );
    }
    return $user;
}, 10, 3 );

// to handle even you can handle the error like
add_action( 'wp_login_failed', function( $username ) {
    if ( is_wp_error( $username ) ) {
        // perform operation on error object for empty error
    }
} );

Line 34 is the line:

    `do_action( 'wp_login_failed', $user );`

I have tried modifying this to
do_action( 'wp_login_failed', $username, $error );

and I am still getting
“Notice: Undefined variable: error in /var/www/wp-content/themes/arya-multipurpose-child/functions.php on line 34”

The additions are working as desired on the login form on the home page when there is ANY kind of failed login i.e. redirecting back to the login page while also returning ?login=failed so as to trigger the “Login failed!” message on the page.

However I am struggling to find where I am going wrong with the arguments. As you can probably tell I am highly noob and will be grateful for any help.

Oh and if it helps, this is happening at my production and staging site, staging is at: https://5br.aa8.myftpupload.com/

Sponsor our Newsletter | Privacy Policy | Terms of Service