[theme-reviewers] Use of Action/Filter Hooks in WordPress Theme
Amy Hendrix
sabreuse at gmail.com
Tue Jul 26 18:41:13 UTC 2011
On Tue, Jul 26, 2011 at 2:34 PM, Chip Bennett <chip at chipbennett.net> wrote:
> That's why I've taken *both* approaches: developers (or savvy users) can
> take advantage of the action/filter hooks, and completely modify the Theme
> using nothing other than style.css and functions.php; while at the same
> time, less-savvy users can modify the Theme using the more-basic (and
> easier-to-understand) template-part files.
> But I wouldn't necessarily recommend this approach to anyone. I agree with
> Josh: pick an audience, and code accordingly. I've chosen to employ both
> methods, only because I wanted to try to provide best-practice
> implementation examples for both methods.
> Chip
>
> On Tue, Jul 26, 2011 at 1:22 PM, Edward Caissie <edward.caissie at gmail.com>
> wrote:
>>
>> Personally I see themes being submitted to the repository as more end-user
>> first more than anything else. That does not mean to say you should not use
>> the "Action" approach over the "Simple" approach as both accomplish the same
>> goals but there is a lot to say about keeping things simple, aka K.I.S.S.
>>
>>
>> Cais.
>>
>>
>> On Tue, Jul 26, 2011 at 10:39 AM, Josh Stauffer <joshstauffer at gmail.com>
>> wrote:
>>>
>>> In my opinion, I believe the Action approach is easier for developers
>>> while the Simple approach is easier for your average end-user. The question
>>> you should ask is "who are you building this theme for?" Answer that and
>>> code it accordingly.
>>> Josh
>>>
>>>
>>> On Tue, Jul 26, 2011 at 9:30 AM, Qamar Ashraf <life.object at gmail.com>
>>> wrote:
>>>>
>>>> Thanks Chip,
>>>> I also love hooks and Oenology 2.0 is an excellent example of hooks. But
>>>> i am also thinking about end-user flexibility who have not much more idea
>>>> about using them. So, i was thinking about the complexity of code before
>>>> submitting to the WordPress directory. Okay, what you prefer in the
>>>> following two code snippets in terms of,
>>>>
>>>> Simplicity for End Users who have little idea about Child Themes.
>>>> Code efficiency.
>>>>
>>>> 1. Action Approach:
>>>>>
>>>>> <?php do_action( 'chip_header_pre' ); ?>
>>>>> <div id="header">
>>>>> <div id="header-data">
>>>>> <?php do_action( 'chip_header' ); ?>
>>>>> </div> <!-- end #header-data -->
>>>>> </div> <!-- end #header -->
>>>>> <?php do_action( 'chip_header_post' ); ?>
>>>>
>>>> 2. Simple Approach:
>>>>>
>>>>> <?php get_template_part( 'nav', 'primary' ); ?>
>>>>> <div id="header">
>>>>> <div id="header-data">
>>>>> <?php get_template_part( 'header', get_chip_header_format() ); ?>
>>>>> <div class="clear"></div>
>>>>> </div> <!-- end #header-data -->
>>>>> </div> <!-- end #header -->
>>>>> <?php get_template_part( 'nav', 'secondary' ); ?>
>>>>
>>>> You can guess better the complexity of hooks in the loop :)
>>>> Regards
>>>>
>>>> On Tue, Jul 26, 2011 at 7:14 PM, Chip Bennett <chip at chipbennett.net>
>>>> wrote:
>>>>>
>>>>> Personally, I think action/filter hooks are Teh Awesome. I also use
>>>>> them, quite extensively.
>>>>> But I'm not really sure what you're asking?
>>>>> Are they acceptable? Of course; provided they are implemented properly,
>>>>> per the appropriate API conventions.
>>>>> Are they best practice? In my personal opinion, they are; I prefer them
>>>>> to, e.g. pluggable functions. But at least currently, the Guidelines are
>>>>> silent on custom hooks.
>>>>> (p.s. you should prefix your hooks with theme_slug, or at the very
>>>>> least, make sure your hook-name prefixes are consistent with the rest of the
>>>>> Theme - which, IIRC, is Chip Life, or "chip_life" as a prefix?)
>>>>> Chip
>>>>>
>>>>> On Tue, Jul 26, 2011 at 8:08 AM, Qamar Ashraf <life.object at gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Hello,
>>>>>> I am going to share my WordPress Theme development logic for an expert
>>>>>> opinion. So it will help me and others in the WP theme development, Here is
>>>>>> a sample code of header template,
>>>>>>>
>>>>>>> <?php do_action( 'chip_header_pre' ); ?>
>>>>>>> <div id="header">
>>>>>>> <div id="header-data">
>>>>>>> <?php do_action( 'chip_header' ); ?>
>>>>>>> </div> <!-- end #header-data -->
>>>>>>> </div> <!-- end #header -->
>>>>>>> <?php do_action( 'chip_header_post' ); ?>
>>>>>>
>>>>>> - I have written different modules like, Primary Menu, Secondary Menu
>>>>>> etc.
>>>>>> - So i can easily attach these modules to any hook with add_action(),
>>>>>> depending on the requirement/presentation of a them/child theme.
>>>>>> Child Theme A Example
>>>>>> add_action('chip_header_pre', 'chip_primary_menu_init');
>>>>>> add_action('chip_header_post', 'chip_secondary_menu_init');
>>>>>> Child Theme B Example
>>>>>> add_action('chip_header_pre', 'chip_secondary_menu_init');
>>>>>> add_action('chip_header_post', 'chip_primary_menu_init');
>>>>>> Both of above child themes will have different presentation of menus,
>>>>>> with just a single line of code, and there may any other combination as
>>>>>> well.
>>>>>> So what is the recommendation of experts to have this logic ?
>>>>>> --
>>>>>> Regards
>>>>>> Qamar Ashraf
>>>>>> www.tutorialchip.com
>>>>>> @lifeobject1
>>>>>>
>>>>>> _______________________________________________
>>>>>> theme-reviewers mailing list
>>>>>> theme-reviewers at lists.wordpress.org
>>>>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> theme-reviewers mailing list
>>>>> theme-reviewers at lists.wordpress.org
>>>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Regards
>>>> Qamar Ashraf
>>>> www.tutorialchip.com
>>>> @lifeobject1
>>>>
>>>> _______________________________________________
>>>> theme-reviewers mailing list
>>>> theme-reviewers at lists.wordpress.org
>>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>>
>>>
>>>
>>> _______________________________________________
>>> theme-reviewers mailing list
>>> theme-reviewers at lists.wordpress.org
>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>
>>
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
More information about the theme-reviewers
mailing list