This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Plugin Architecture: Simple, but watch out
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
I have been working with Wordpress and a bunch of plugins (there are more plugins than I have had hot dinners).
It is great that you have so much out there to plugin and play, but when you actually start using some of these plugins you see a lot of abuse by the plugin writers :)
Plugin Architecture
The plugin architecture in Wordpress is amazingly simple. You throw a single php file, or a directory, in the plugins directory.
The only other thing you need to do is put some comments in the file. These are read from the plugin admin interface.
Now, it is truly great how simple this is. Anyone can write a plugin!
The problem is that... anyone can write a plugin! :)
enablePlugin()
Since the plugin API is so loose, there isn't a specific hook to enable/disable a plugin.
In a couple of plugins that I was using, I found that the setup code was running on EVERY REQUEST.
That's right. Every page load caused "DESC sometable" to work out if an "ALTER TABLE" needs to run.
This doesn't have to be the case of course. You can check for $_GET["activate"] explicitly (which gets passed in the plugin activation page) and just do the setup/destroy code there.
It would be nice if Wordpress had a nicer hook than this of course.
For most things you can hook into actions and filters via add_action('action_name', 'func_name'), so maybe there will be one for plugin activation.