[wp-hackers] apply_filters() in an if statement?

Nathan Rice ncrice at gmail.com
Wed Feb 29 20:46:47 UTC 2012


Sorry, meant to say ...

"For instance, if I wanted [to give the option] to display a banner above
my header, I could do this:"

------------------
Nathan Rice
WordPress and Web Development
www.nathanrice.net | twitter.com/nathanrice


On Wed, Feb 29, 2012 at 3:45 PM, Nathan Rice <ncrice at gmail.com> wrote:

> It's an easy way for a plugin to change the outcome of an if() check.
>
> For instance, if I wanted to display a banner above my header, I could do
> this:
>
> if ( apply_filters( 'show_banner_above_header', '' ) )
>   show_banner_above_header();
>
> or, I would more likely do this:
>
> if ( apply_filters( 'show_banner_above_header', false ) )
>   show_banner_above_header();
>
> ... then a plugin could come along and do this:
>
> add_filter( 'show_banner_above_header', '__return_true' );
>
> ... and the banner would then show.
>
> Of course, you could reverse the whole things and use __return_false as
> the callback for add_filter() and get the opposite result.
>
> ------------------
> Nathan Rice
> WordPress and Web Development
> www.nathanrice.net | twitter.com/nathanrice
>
>
>
> On Wed, Feb 29, 2012 at 3:38 PM, Micky Hulse <mickyhulse.lists at gmail.com>wrote:
>
>> Hello,
>>
>> Sorry in advance if this type of question belongs on the forums...
>>
>> I am hacking a theme, and they have something like this (abbreviated):
>>
>> [code]
>>
>> if (option('foo') || apply_filters('baz_baz', '') ||
>> apply_filters('bar_bar', '')) {
>>
>>   $bar_bar = apply_filters('bar_bar', blah, blah);
>>   $return = apply_filters('baz_baz', blah, blah);
>>
>> }
>>
>> [/code]
>>
>> What does apply_filters('string', '') accomplish? I guess I am
>> confused because the second argument is an empty string.
>>
>> This helps to explain (at least in my brain) what apply_filters() does:
>>
>> "In the most basic terms, apply_filters is used to initialise a filter
>> hook... add_filter assigns a new function to hooks that have already
>> been created."
>> --<
>> http://stackoverflow.com/questions/2270989/what-does-apply-filters-actually-do-in-wordpress
>> >
>>
>> But why would you put it in an if statement with an empty string for
>> the second argument?
>>
>> Am I talking crazy here?
>>
>> Let me know if this type of question is too noob for this list. I
>> don't want to bug folks with simple ones. :D
>>
>> Thanks a billion!
>>
>> Cheers,
>> Micky
>> _______________________________________________
>> 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