Way back in the mists of time, following an article on Weblog tools collection, I started looking at writing an uninstaller for WordPress plugins. There was a significant interest in this at the time so I wrote a patch and submitted it to core where it stayed for some time.
The process was documented in three posts: Fun with uninstallation part 1, part 2 and part 3. Note that the sample plugins that are linked to in these posts have been removed as some users were misunderstanding them and using them despite the fact that they were practically useless.
My hope that the patch would be included in WordPress 2.5 was not to be. 2.6 has also been released. Finally though, thanks to Jacob Santos who pushed it along, with 2.7 it will be possible for plugin authors to write an uninstall routine.
How to write the uninstall routine
The final implementation is actually closest to my first attempt. It bypasses the problem of creating hooks in a plugin that will not be active and does not add to the core more than it has to.
To produce the uninstaller you need to include a separate file (uninstall.php) within the plugin folder. This should include all the code needed to remove options, database tables, etc.
This file will be run when the plugin delete routine runs, so it will not be possible to uninstall the plugin without deleting it. If the plugin is deleted manually, using FTP, then the plugin will need to be re-uploaded before anything can be uninstalled.
Given that WordPress 2.7 will include a plugin installer that will let you search for and install plugins directly from the plugin repository without any FTP shenanigans it is reasonable to presume that users will usually delete the plugin through the interface as well.
I think that users might want to uninstall a plugin in order to wipe the settings so it may not be a bad idea to write the uninstaller in a way that allows it to be run manually and to trigger the plugins activation function to reinstall the defaults. I am working on an implementation of this for the next version of my fun with plugins tool.
Related Stuff
The Ultimate Wordpress SEO ChecklistHey everyone, I am back. This post is going to be about Wordpress SEO. It’s a checklist of the steps you should take to ensure that ...
Essential WordPress SEO PluginsSEO is a critical part of getting people to your site and these WordPress plugins help you acheive your goals quickly and ...
WordPress Configuration TricksMany WordPress users know the wp-config.php file as the key to the WordPress database. It is where you set the database name, username, ...
WordPress as a Comic Publishing PlatformThis post was spurred along by a comment at webcomics.com which has since been deleted, though I’ve been meaning to write something ...
8 WordPress Plugins to make your 404 error pages user friendly & efficient404 error pages are unavoidable, they creep in somehow no matter how well you build your site. But its normal. 404 error pages could appear ...

Original Source: