[theme-reviewers] Use of Action/Filter Hooks in WordPress Theme
Josh Stauffer
joshstauffer at gmail.com
Tue Jul 26 14:39:28 UTC 2011
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<https://github.com/chipbennett/oenology/blob/master/functions/hooks.php>
>> .
>>
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110726/0a8ea271/attachment-0001.htm>
More information about the theme-reviewers
mailing list