1

Hi I'm learning theming options based on the existing theme TwentyEleven.

I've come across the following code in inc/theme-options.php

return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options );

I can't seem to find the add_filter for 'twentyeleven_default_theme_options', or does it not even exist?

0

2 Answers 2

1

I don't believe there is an add_filter() call anywhere. If you want to override the option defaults, you can call your own add_filter() to do so, either in a Plugin or in a Child Theme.

EDIT

An apply_filters() call is nothing more than a filter hook definition: basically, it is defining the data to which a filter hook is applied.

It is similar to do_action(), which is an action hook definition: it defines the template location/runtime execution point at which the action hook is fired.

So, the presence of apply_filters() does not imply that there will necessarily be a corresponding add_filter() call; rather, it merely means that a filter is available to modify the specified data.

On the other hand, the presence of add_filter() does imply that somewhere, a corresponding apply_filters() call exists - just as the presence of an add_action() call implies that somewhere, a corresponding do_action() call exists.

3
  • Sorry, I'm a beginner at this. From what I read from the codex, it seems like you need to add the filter before you can apply it. But in this case the add_filter portion is missing, how does the apply_filter work?
    – hamahama
    Commented Oct 19, 2011 at 11:40
  • See updated answer. You've got it a bit backward. :) Commented Oct 19, 2011 at 11:44
  • Thanks alot. I'm currently reading your post on how to incorporate the settings api, and it really helps alot!
    – hamahama
    Commented Oct 19, 2011 at 16:24
0

apply_filters is required if you want to define your own filters, or wrap the existing ones with your custom filters. That's what is happening in the code you saw. You won't need to add any custom filters at a beginner stage, so won't need to use apply_filters, at least until you get comfortable with the existing ones! WordPress provides you with a huge list of filters, check here and here for a category wise list of filters and how to use them. Start digging into these.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.