I have an add_filter
function for the auth_cookie_expiration
hook. This hook accepts three parameters. However, I am interested in passing it more parameters. For example:
add_filter( 'auth_cookie_expiration', 'get_expiration', 10, 5 );
This would be possible with apply_filter
, but the add_filter
function is called once, which makes it throw an error:
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function get_expiration(), 3 passed in ... and exactly 5 expected
I got around this using closures, but it seems like a completely ridiculous way to do this:
add_filter( 'auth_cookie_expiration', function() use ($param1, $param2) { return get_expiration(null, null, null, $param1, $param2); } , 10, 3 );
Is there a proper/more elegant way to make it accept additional parameters (even better, the params I want in place of the default ones)? Am I misunderstanding how add_filter
is supposed to work?
For the sake of example, suppose get_expiration
looks like this:
function get_expiration( $length, $user_id, $remember, $param1, $param2 )
{
return $param1 + $param2;
}
use
looks like the better solution.