Something I have seen several times now and I don’t understand is the following: In a theme’s functions.php
a function is defined and then attached to a hook, like so (simplified example):
function do_stuff($a, $b) {
// Do stuff with $a and $b
}
add_filter( 'bloginfo_url', 'do_stuff', 10, 2 );
Basically I think I understand whats happening there, but how do I know what $a
and $b
is?
In a “traditional” PHP way, one would call the function maybe like that:
do_stuff("var a content", $var_b_content);
Then its clear what $a
and $b
contain, but how can I know that with WordPress?
Real life example, take the following function (credit to Frank Bültge):
if ( ! function_exists( 'fb_css_cache_buster' ) ) {
function fb_css_cache_buster( $info, $show ) {
if ( ! isset($pieces[1]) )
$pieces[1] = '';
if ( 'stylesheet_url' == $show ) {
// Is there already a querystring? If so, add to the end of that.
if ( strpos($pieces[1], '?' ) === FALSE ) {
return $info . "?" . filemtime( WP_CONTENT_DIR . $pieces[1] );
} else {
$morsels = explode( "?", $pieces[1] );
return $info . "&" . filemtime( WP_CONTENT_DIR . $morsles[1] );
}
} else {
return $info;
}
}
add_filter( 'bloginfo_url', 'fb_css_cache_buster', 9999, 2 );
}
The function can be used for CSS versioning by attaching the date of the last change (using filemtime
) as querystring to the CSS call.
You can see, the uses $info
and $show
as variables that are passed to that function. But how can I know what these variables contain? He even uses these variables in conditional logic ('stylesheet_url' == $show
) so somehow there something must be passed automatically?