I'm having a hard time understanding how to set up a function with a default parameter and then call it with the do_action
in WordPress. I'm not sure if this is a WordPress issue or just me not understanding the do_action
method. What happens is I define a function like this:
function contact_info( $show_logo=true ) {
var_dump( $show_logo );
}
Then I add the hook like this:
add_action( 'show_contact_info', 'contact_info' );
Finally when I call the do_action like this:
do_action('show_contact_info');
I would expect a the var_dump
to be bool(true)
, but what I am getting is: string(0) ""
So my question is WHY?
It doesn't seem to be accepting the default as set in my function, or more specifically, the do_action
call ALWAYS seems to pass blank as the first parameter if one is not defined in the call. Is this standard for Wordpress? Why would it not pass NULL?
add_action( 'show_contact_info', 'contact_info', 10, 0 );
to prevent this.