#49445 closed defect (bug) (invalid)
Only one argument passed to wp_login callback.
| Reported by: | tmfhokies | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Login and Registration | Version: | 5.3.2 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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:
you will find the error no longer happens.