[wp-hackers] Changing two variables listed in apply_filters hook

Otto otto at ottodestruct.com
Mon Jul 23 16:41:57 GMT 2007


Okay, so you've got something like this:
$categories = apply_filters('get_categories', $categories, $r);
And you want to not only return something for categories, but also
change the value of $r?


Short answer: You can't do that.


Long answer: You can't do that without changing the apply_filter()
call itself. You would need to pass an array containing the reference
to the variable. The array is passed by value, but the reference can
be used to alter what you want to alter.

Also, as FUJINAKA Tohru points out, if you also pass the same thing by
value, then that value won't be recognized as changed until you return
from all the filters, because the value has already been passed,
you're not changing the passed value, you're changing the original
value (via the reference).



On 7/22/07, Ted Balaban <tsbalaban at yahoo.com> wrote:
> When the apply_filters hook has 2 variables how
> do you change the second variable in a plugin?
>
> For example:
> apply_filter ('get_categories', $categories, $r);
>
> I know what to do for one variable.  Create a function
> with the specified variable as an argument and in the
> return statement.  Call add_filter.
>
> For example:
> function test_function ($test)  {
>   $test =  .......
>   return $test;
> }
> add_filter ('hook', 'test_function');
>
> Any help is appreciated.
>
> tsbalaban
> _______________________________________________
> 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