September 21, 2008

Every now and again you read a post that makes such an obvious point that you wonder why it hasn’t been made before. The benefits of hooks over plugin-specific functions is one of them.

WordPress hooks, whether they be actions or filters, are simple bits of code that plugin authors can use to attach events to. Most of these hooks are deep within functions in the WordPress core, but some are within the standard template files. The following line comes from the default comment form:

[php]
do_action('comment_form', $post->ID);

This particular hook is used to add extras, such as the subscribe to comments tick box, at the bottom of the comment form.

The usual course of action if there isn’t a hook where a plugin author wants one is simply to define a function and ask the blog owner to insert it into their theme. This does cause some problems though, the biggest being that when you switch the plugin off the function will cease to exist and error messages will sully your theme. Not ideal.

The approach that W-Shadow is advocating is that instead of writing a new function, the plugin author should attach events to a hook that doesn’t exist yet and ask the blog owner to insert the hook instead. That way, when the plugin is deactivated, no errors will occur. But even better, if plugins that want to achieve similar things all use the same hook then they will be interchangeable.

My plugin doesn’t have the one killer feature that you want, but a similar plugin does? Just turn mine off and the other on. Job done.

I haven’t had much time to really think it through, but it seems to me that a really good extension of this would be for plugin developers to get toghether to define a load of hooks to help make the benefits a reality. For example, plugins that create menus could attach to hooks called ‘main_menu’, ’secondary_menu’, or ‘footer_menu’.

I do think there is scope for this to bring about some interesting results.



Wordpress title showing space?
no comment on page 1371

Wordpress fun?
one comment on page 1376

Live blogging plugin?
4 comments on page 1258

Wordpress 3 admin speed up?
4 comments on page 1321

Framework photoshop?
3 comments on page 296

Fun wp plugins?
one comment on page 1376

Habari vs wordpress?
12 comments on page 440

Wp tags vs categories?
12 comments on page 7

Wordpress rss seo?
one comment on page 1361

Photo albums html5?
6 comments on page 1305

Wordpress chat?
no comment on page 1308

Wordpress exif data?
12 comments on page 230

Css sidear tab?
2 comments on page 336

Wordpress theme html5 blueprint?
6 comments on page 1305

Wordpress shortcode in plugin?
no comment on page 236

Html 50 photo album?
6 comments on page 1305

Get the post attachement?
24 comments on page 1065

Wordpress plugin development 30?
one comment on page 1373

Wordpress plugin development 30?
one comment on page 1373

Disqus formatting?
7 comments on page 1175

Html5 photoalbum?
6 comments on page 1305

Html5 photoalbum?
6 comments on page 1305

Wordpress fun?
one comment on page 1376

Fun wordpress plugins?
one comment on page 1376

Url shortener ideas?
4 comments on page 1190

Url shortener ideas?
4 comments on page 1190

Html 5 photo gallery?
6 comments on page 1305

Multiple post navigation?
no comment on page 1147

Html5 photo galleries?
6 comments on page 1305

Adding images to a wordpress 3 post?
24 comments on page 1065

Html5 photo gallery code?
6 comments on page 1305

Wordpress multiple blog master?
one comment on page 1376

Wordpress 3 tableprefix?
one comment on page 1376

Wordpress 3 tableprefix?
2 comments on page 1374

Using wordpress as a framework?
2 comments on page 335

Single post image size?
24 comments on page 1065

Get featured image src wordpress?
24 comments on page 1065

Disqus wordpress mu?
7 comments on page 1175

Image gallery html 5?
6 comments on page 1305

Wordpress theimage?
24 comments on page 1065

Wpgetattachmentimagesrc size?
24 comments on page 1065
  every 1731s, 1s ago, in 0.02s.
Post a comment?

0s