Too few arguments error when adding action

Adding the following code to functions.php:

add_action('hivepress/v2/models/user/update', function($user_id, $user ) {

});

And then updating any field in User Settings screen raises the following error:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /home/public_html/dev/wp-includes/class-wp-hook.php on line 309 and exactly 2 expected in /home/public_html/dev/wp-content/themes/listinghive/functions.php:53
Stack trace:
#0 /home/public_html/dev/wp-includes/class-wp-hook.php(309): {closure}(27)
#1 /home/public_html/dev/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(’’, Array)
#2 /home/public_html/dev/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#3 /home/public_html/dev/wp-content/plugins/hivepress/includes/components/class-hook.php(131): do_action(‘hivepress/v2/mo…’, 27, Object(HivePress\Models\User))
#4 /home/public_html/dev/wp-includes/class-wp-hook.php(309): HivePress\Components\Hook->update_us in /home/public_html/dev/wp-content/themes/listinghive/functions.php on line 53

The same error occurs with:
add_action(‘hivepress/v1/models/user/update_first_name’, function($object_id, $value ) {

});

Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /home/public_html/dev/wp-includes/class-wp-hook.php on line 309 and exactly 2 expected in /home/public_html/dev/wp-content/themes/listinghive/functions.php:60
Stack trace:
#0 /home/public_html/dev/wp-includes/class-wp-hook.php(309): {closure}(27)
#1 /home/public_html/dev/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(’’, Array)
#2 /home/public_html/dev/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#3 /home/public_html/dev/wp-content/plugins/hivepress/includes/components/class-hook.php(175): do_action(‘hivepress/v1/mo…’, 27, ‘vvvvvvvsssssss’)
#4 /home/public_html/dev/wp-includes/class-wp-hook.php(307): HivePress\Components\Hook->update_user_meta(‘816’ in /home/public_html/dev/wp-content/themes/listinghive/functions.php on line 60

If a custom callback you assign to a hook contains more than 1 parameter please specify the number of parameters this way:

add_action(‘hivepress/v2/models/user/update’, function($user_id, $user ) {

}, 10, 2);
1 Like

Thanks ihor!

1 Like