888888.888888.88""Yb..dP"Yb..8888b..Yb..dP.88b.88....db....8b....d8.88..dP""b8..dP"Y8
88__...88__...88__dP.dP...Yb..8I..Yb.YbdP..88Yb88...dPYb...88b..d88.88.dP...`".`Ybo."
88""...88""...88"Yb..Yb...dP..8I..dY..8P...88.Y88..dP__Yb..88YbdP88.88.Yb......o.`Y8b
88.....888888.88..Yb..YbodP..8888Y"..dP....88..Y8.dP""""Yb.88.YY.88.88..YboodP.8bodP'


88b.88.888888.888888.Yb........dP.dP"Yb..88""Yb.88..dP
88Yb88.88__.....88....Yb..db..dP.dP...Yb.88__dP.88odP.
88.Y88.88"".....88.....YbdPYbdP..Yb...dP.88"Yb..88"Yb.
88..Y8.888888...88......YP..YP....YbodP..88..Yb.88..Yb

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 25 Exif Fields
Wordpress exif plugin?
12 comments
page 230
Adding Settings To Admin Pages
Wordpress addsettingsfield?
3 comments
page 793
Updating Code Snippets Here
Fun wordpress plugins?
no comment
page 1338
Html 5 Gallery
Html5 image gallery?
6 comments
page 1305
How To Add Sidebars To A Theme
How to register two sidebars in wp?
10 comments
page 1053
Post Image The Easy Peasy Way
Wordpress theimage?
26 comments
page 1065
Using Your Own Url Shortener
Short url?
4 comments
page 1190
Using Wordpress As A Php Framework
Php framework wordpress?
2 comments
page 335
Html 5 Gallery
Html 5 gallery?
6 comments
page 1305
Wordpress Vs Graffiti
Html5 cms?
8 comments
page 95
Post Image The Easy Peasy Way
Wordpress medium size image link?
26 comments
page 1065
Wordpress Chat
Wordpress chat?
3 comments
page 1308
Html 5 Gallery
Wordpress html5?
6 comments
page 1305
Quick N Dirty Admin Login Screen
Web templte admin login page?
no comment
page 128
Post Image The Easy Peasy Way
Wp get url functions?
26 comments
page 1065
Html 5 Gallery
Wordpress html5 theme?
6 comments
page 1305
Post Image The Easy Peasy Way
Wordpress get first image attached to post?
26 comments
page 1065
Html 5 Gallery
Wordpress html5?
6 comments
page 1305
Post Image The Easy Peasy Way
Wp automatically insert image based on tags?
26 comments
page 1065
What Wordpress Workflow Needs
Word press workflow?
3 comments
page 1226
Quick N Dirty Admin Login Screen
Login screen css?
no comment
page 128
How To Add Sidebars To A Theme
Wordpress thematic modify sidebars?
10 comments
page 1053
Six Million Ways To Die Choose One
Ways to die without noticing?
14 comments
page 1128
Post Image The Easy Peasy Way
Wordpress theimage?
26 comments
page 1065
How To Add Sidebars To A Theme
How to add a sidebar to a theme?
10 comments
page 1053
Using Your Own Url Shortener
Htaccess tiny url shortner?
4 comments
page 1190
Photoshop Design Framework
Photoshop framework?
3 comments
page 296
Creating Custom Urls
Custom url for wordpress page?
6 comments
page 80
Photoshop Design Framework
Framework in photoshop?
3 comments
page 296
Html 5 Gallery
Wordpress html5?
6 comments
page 1305
Using Your Own Url Shortener
Build your own url shortener?
4 comments
page 1190
My Experience Of Flexx
Cant upload image to flexx wordpress theme?
4 comments
page 1026
Post Image The Easy Peasy Way
Wpget post image?
26 comments
page 1065
  1 query every 1606 seconds, updated 1 seconds ago.
Post a comment?