Hotaru Docs

 [həʊdɒks]

Designing around Plugin Hooks

One of the difficulties with designing a theme is knowing what to do with all the plugin hooks in a template. For example, imagine a typical post from the Submit plugin:

What you've got

AVATAR - TITLE
AUTHOR - DATE - CATEGORY
DESCRIPTION
TAGS - COMMENTS - FLAG IT!

If you delved into the template itself, you'll see you've got something like:

HOOK - TITLE
AUTHOR - DATE - HOOK
DESCRIPTION
HOOK

What you want

Let's say you wanted to move the tags to the top, next to the category, like this:

AVATAR - TITLE
AUTHOR - DATE - CATEGORY - TAGS
DESCRIPTION
COMMENTS - FLAG IT!

How you do it

To do that, you need to understand the plugin hook itself. Let's take a look:

<?php $h->pluginHook('show_post_extra_fields'); ?>

The pluginHook function takes the following parameters:

  1. $hook = "";
  2. $folder = "";
  3. $parameters = array();
  4. $exclude = array();
  1. is the name of the plugin hook.
  2. is if you want to specify which plugin to use. In most cases, this will be blank so all plugins with the same hook will run.
  3. an array of additional arguments to pass to each function at that hook.
  4. an array of plugins you don't want to be included.

So, if you want to show only the tags, you can do this:

<?php $h->pluginHook('show_post_extra_fields', 'tags'); ?>

And to exclude tags from the original plugin hook (which you still need to show categories and the alert flag), do this:

<?php $h->pluginHook('show_post_extra_fields', '', array(), array('tags')); ?>

If you want to exclude more than one plugin, just list them in the last array, like this:

array('tags', 'categories', 'plugin3', 'plugin4')

Summary

The pluginHook, although not pretty, gives you enough flexibility to completely redesign your theme without breaking things if you choose to add more plugins later on. For a more in-depth look at plugin hooks, read Working with Plugin Hooks. (link needed)

Comment

When the documentation was part of the forums, JonH responded with this example:

"Going by your tutorial, I moved the Gravatar to another spot in the template. I kept the Gravatar plugin from using the default hook by using your example by changing

<?php $h->pluginHook('show_post_pre_title'); ?>

to:

<?php $h->pluginHook('show_post_pre_title', '', array(), array('gravatar')); ?>

and used this where I wanted the Gravatar to appear:

<?php $h->pluginHook('show_post_pre_title', 'gravatar'); ?>
Getting StartedDesign and LayoutPlugin DevelopmentAdvanced TopicsFunction ReferenceTroubleshooting