WP-Fun.co.uk

Uninstall Plugins

There is a discussion going on over at Weblog Tools Collection about the difference between uninstalling, and deactivating, plugins. There are a lot of very good points made about the things that plugin authors can do to help maintain the WordPress user’s database.

To add to the discussion I have written a plugin that adds an uninstall option to the plugins page where there is a separate uninstall file included.

The file needs to have the same name as the plugin itself except but with the addition of _uninstaller on the end. So if the plugin is called my_plugin.php the uninstaller will be called my_plugin_uninstaller.php.

It will actually just include this file directly so it can’t echo anything to the browser. It can however register failure by redirecting back to the plugins page:

[php]
if ( $failure) {
wp_redirect('plugins.php?uninstalled=false');
}

There are a number of things in this plugin that are a tad kludgy and so it isn’t something I intend to release unless an unexpected demand occurs, but it is one idea to add to the mix. Perhaps seeing something in action will give someone else some other ideas.

You can download it here: Fun with uninstallation 0.1

It comes with an empty uninstall file for hello dolly.

Update: With 40 comments to date it is clear that there is a demand for this. I have opened a ticket in the WordPress trac to gain feedback from developers and hopefully move things forward with similar functionality being included.

When I was building this I wanted to make it use a hook in the same way as a normal plugin would and I struggled to find a way to do it, which is why I went with a separate file; however, the trac discussion may have yielded a better alternative. If that is the case, I will amend this plugin to use that methodology and hope that it gets included in the core in one of the later point releases.