[wp-hackers] filters with multiple parameters?

Otto otto at ottodestruct.com
Mon Nov 19 15:26:45 GMT 2007


Try this instead:

add_filter( 'bloginfo', 'my_bloginfo_filter', 10, 2 );

The definition for add_filter actually looks like this:

function add_filter($tag, $function_to_add, $priority = 10,
$accepted_args = 1) {

So when you use more than 1 argument, you need to specify how many. :)


On 11/19/07, Stephen Rider <wp-hackers at striderweb.com> wrote:
> I've been beating my head against this, and would appreciate an assist:
>
> I'm trying to use add_filter, but the hook in question has multiple
> parameters passed and I can't figure out how to access the second
> parameter.  Example code:
>
> add_filter( 'bloginfo', 'my_bloginfo_filter' );
>
> function my_bloginfo_filter ( $output = '', $show = '' ) {
>         switch( $show ) {
>                 case 'version' :
>                         if ( function_exists( 'mb_get_bloginfo' ) ) {
>                                 $output .= 'Hello World';
>                         }
>                         break;
>         }
>         return $output;
> }
>
> This doesn't work because in my function, $show is always empty,
> though $output comes through just fine.  I've tried it as an array --
> no luck: it just splits the $output string into a letter-by-letter
> array.
>
> The hook itself (in core) looks like this:
>
> $output = apply_filters('bloginfo', $output, $show);
>
> How do I get $show in my filter function?
>
> TIA
> Stephen
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list