Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#49445 closed defect (bug) (invalid)

Only one argument passed to wp_login callback.

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


Hook into the wp_login action from a barebones plugin.

 * 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 (, the closure only receives $user_login.

Tried with PHP 7.2.22.

Change History (4)

#1 @pbiron
4 years 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:

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

you will find the error no longer happens.

Last edited 4 years ago by pbiron (previous) (diff)

#2 @tmfhokies
4 years ago

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

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

#3 @pbiron
4 years ago

glad I could help.

#4 @SergeyBiryukov
4 years ago

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