Development on a Shoestring

Writing self-cleaning WordPress plugins

Don’t you just hate it.  You install a program on your computer to try it out, then when you go to un-install it, it leaves files scattered all over your system.  Whether it’s in the application folder that it can’t delete, or in the Application Data folder or system32, it’s not easy to find a program that cleans up after itself properly.  I’ve got more of a chance of getting my kids to tidy up the lounge room after they’ve got all the Lego out.

This issue isn’t just limited to Windows applications though.  I’ve noticed the same problem with a lot of WordPress plugins.  It may just be leaving a couple of config options in the wp_options table, or it may be as much as leaving multiple custom db tables behind or even files in the WordPress install folder.  I’m of the opinion that once you remove a plugin, it should be gone without a trace.

Now, for plugin developers, WordPress provides a simple way to do this.  The register_deactivation_hook() method lets you register a function to be called when your plugin is deactivated.  In there you can put any cleanup code to remove options, tables files, etc.

But…

This is not without it’s problems.  Often plugins require you to enter some complex config information or they may build up a history that you may not want to lose (eg. a spam filter that learns from what you mark as spam).  Sometimes you need to disable plugins temporarily, in fact the WordPress update instructions say that you should deactivate all your plugins prior to upgrading.

Also, the automatic plugin updates system introduced into WordPress deactivates plugins before it installs the updated version.  So if you put the cleanup tasks into the deactivation hook method, all the user’s settings would be gone after updating.  This really isn’t a good option.

What would be better is if the WordPress plugin admin page had 2 buttons for each plugin: deactivate & uninstall.  Deactivate would do what it does now - turn off the plugin, but leave it in place.   Uninstall would completely remove the plugin, including deleting the plugin file & firing a separate uninstallation hook callback.  Developers could then put all their cleanup code in there, with no fear that users were going to lose settings during an upgrade.

What to do for now

I think for the time being it would be best if developers included a ‘remove all data’ button on their plugin’s options page (if it has one).  This button would remove all trace of the plugin (other than deleting the plugin itself) so that the user can then deactivate it.  This button should probably be restricted to admin users and have some form of confirmation on it. I’ve added a button to do this in the latest release of the FriendFeed Comments Plugin.

There’s already a post about this ideas section of WordPress.org, and a discussion about it on Weblog Tools Collection.  I’m hoping that this gets noticed, because it would be great if developers had a simple way of tidying up after themselves.

If this is something that matters to you, please go vote up this idea on WordPress.org.

Everything old is new again

What with all the, um, unpleasantness around FriendFeed this week, it reminded me about something that I’ve been thinking on for a while now. There have been a lot of new sites starting up in the last couple of years that are primarily focused on social communication over the web. Facebook, FriendFeed, Tumblr, Pownce, Twitter, Orkut, Jaiku, about a billion blogs, and so on. The social web it’s being called.

The idea is that the new web, ‘Web 2.0′, is introducing the concept of social networks to the internet as opposed to the ‘old’ web which was just corporate marketing.  Of course this is ridiculous.  If the internet has ever had a single defining feature, it is its social nature.  The internet was originally nothing but interpersonal communication. Anyone remember bulletin boards, Usenet?  Even with the advent of html and the font tag we had newsgroups and forums.  Myspace? It’s just Geocities with music. It was only in the very late 90s that the internet started turning into the corporate marketing platform that people seem to think it is.  The new social platforms are just newer, shiner versions of newsgroups.  Bulletin boards with animated emoticons and super poke.

image So why does everyone think that the internet is just one giant marketing tool? And if social isn’t new, what is it that the new “Web 2.0” brings that is actually, well, new?  The simplistic answer to both questions is this: volume

The sheer volume of people using the internet now on a daily basis is enormous.  The advent of broadband and its relative cheapness (unless you’re in Australia that is) means that pretty much anyone can load up a page within seconds.  I’m old enough to remember waiting minutes for things to load.  Minutes!  And I’m not really that old (don’t ask my kids).  Now, if your website takes more than 5 seconds to load, people from above start asking questions.  Your average office worker now has super high-speed access to the internet. And while offices often block non-work related sites, they can’t block them all, and there are always ways around the blocks if you know what you’re doing.  The fact is that a lot of people are spending a lot of time online, and they’re bored.  Why bother with solitaire when you can load up Kongregate?  Not only do you get more entertaining games, you get to broadcast your l33t skillz through the high score lists (and parade your achievements on your Facebook account with their app).

But it’s not so much the number of people online that led to the idea that corporations own the net.  It’s the rate of growth …

(more…)

Subscribe by email

Enter your email address:

Delivered by FeedBurner


Elsewhere

Verse of the Day

And those who belong to Christ Jesus have crucified the flesh with its passions and desires. (Galatians 5:24, ESV) (Listen)

Networks & References