Jump to content

Fatal Error: Uncaught ArgumentCountError: Too few arguments to function.

Recommended Posts

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' );

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
} );

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. Super 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/

Link to comment
Share on other sites

Are you able to link any of the reported line numbers to your code?  It looks like one of your function calls doesn't have the expected number of arguments in it.  Find the line that is being mentioned.

Link to comment
Share on other sites

@ginerjm you make an excellent point my apologies. The line being referenced in the php in 34 which is:

do_action( 'wp_login_failed', $user );

I have since realised that this is missing parameters and have modified it to:

do_action( 'wp_login_failed', $username, $error );

But this doesn't seem to correct the issue. I am still getting a reports stating:

Notice: Undefined variable: error in /var/www/wp-content/themes/arya-multipurpose-child/functions.php on line 34

Link to comment
Share on other sites

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

The beginning says you are passing one arg in line 308.  Find that.

You do understand how functions work I hope.  When you define/create a function the header of it will have a number of parameters in the parentheses following the function name.  However many of them are hard, required parms will need to be included in any line of code that later calls this function.  If that line of code does not use enough values in the call to the function you get your error message.  So take those first couple of lines of the error message and track down the items mentioned there in your code and see what you are passing.

Edited by ginerjm
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.