WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#49445 closed defect (bug) (invalid)

Only one argument passed to wp_login callback.

Reported by: tmfhokies Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.3.2
Component: Login and Registration Keywords:
Focuses: Cc:

Description

Hook into the wp_login action from a barebones plugin.

<?php
/**
 * Plugin Name: wp_login hook issue
 */
add_action('wp_login', function ($user_login, $user) {
});

Activate the "wp_login hook issue" plugin, log out, try to log in. That results in an "PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function".

Even though the do_action call passes both (https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/user.php#L110), the closure only receives $user_login.

Tried with PHP 7.2.22.

Change History (4)

#1 @pbiron
3 months ago

Hi @tmfhokies, welcome to Trac!

The problem you're experiencing is because of the way you're calling add_action(). add_action() has an optional 2nd & 3rd parameter: the 3rd is "The number of arguments the function accepts". For more details, see add_action().

If you change the call to:

<?php
add_action('wp_login', function ($user_login, $user) {
}, 10, 2 );

you will find the error no longer happens.

Last edited 3 months ago by pbiron (previous) (diff)

#2 @tmfhokies
3 months ago

  • Resolution set to invalid
  • Status changed from new to closed

@pbiron Thanks, I definitely overlooked the default value for $accepted_args.

#3 @pbiron
3 months ago

glad I could help.

#4 @SergeyBiryukov
3 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.