Ferodynamics Network

popular: profile privacy, mobile privacy

January 11, 2008

After reading the comments on my first uninstallation plugin attempt, and the WordPress Trac, it become clear that the approach of using an external file probably wasn’t going to cut it. So I have taken that on board and produced a revised version.

I think version 0.2 is a significant step forward, not least because it solves the problem of needing a separate file.

So how does this version work?

The plugin author needs to do two things. The first is to add an uninstall option at the top of the plugin file, somthing like this:

[php]
if ( !is_plugin_active( __FILE__ ) ) {

class my_plugin{

function uninstall(){

}
}

return;
}

What this does is to only expose the uninstall methods if the plugin is not active, and further, the addition of the return at the end stops the rest of the plugin being loaded.

Important Note: An inactive plugin is only loaded if it is in the process of being uninstalled. It will not be loaded at any other time and so won’t impact on performance or security any more than they already do.

The second thing the plugin author needs to do is to register the uninstall function. This should be done when the plugin is activated. The function that needs to be called is:

[php]
register_uninstall_hook( 'uninstall_sample' , __FILE__ , array( 'my_plugin' , 'uninstall' ) );

The first argument is a friendly name, the second is the plugin url, the third is the uninstall function itself. It is essential to remember that the class is not the main plugin class, but the one inside the block that runs if the plugin in not installed, so using &$this isn’t going to work.

What happens, when?

when the plugin is activated it is added to a list of uninstallable plugins in a database option.

The plugins page checks whether a plugin is active, if it is not and it is in the list of uninstallable plugins it offers the uninstall option.

If you select the unstall option it loads the plugin, activates the hook, and removes the plugin from the list of uninstallable plugins so that the option to uninstall is no longer shown.

The zip file below includes 0.2 of the plugin and another sample plugin that has the uninstall instructions. On activation it creates a database table, and cleans it up when it is uninstalled.

You can download it here: Fun with uninstallation 2

Update I am most of the way through version 0.3. 0.3 will emulate the patch I intend to submit to the trac later on today. It will work a little differently to this, automating more of the uninstallation process. Full details will follow later on.

Details of version three can be found here

Quick N Dirty Admin Login Screen
no comment
page 128
Wordpress Chat
one comment
page 1308
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Silence Is Golden
3 comments
page 213
Questions About Habari For Wordpress Users
6 comments
page 424
Theming Habari Vs Wordpress
13 comments
page 440
My Experience Of Flexx
4 comments
page 1026
Plugin Update Fun With Photo Data 2
one comment
page 815
Post Image The Easy Peasy Way
26 comments
page 1065
Categories Vs Tags Either Neither Or Both
12 comments
page 7
Gaining Benefits From Plugins
8 comments
page 1167
Fun With Theme Widgets
24 comments
page 867
Beware Wp Cache
8 comments
page 1310
Six Million Ways To Die Choose One
14 comments
page 1128
Post Image The Easy Peasy Way
26 comments
page 1065
Post Image The Easy Peasy Way
26 comments
page 1065
Wordpress Chat
one comment
page 1308
Post Image The Easy Peasy Way
26 comments
page 1065
Wordpress Chat
one comment
page 1308
Beware Wp Cache
8 comments
page 1310
Wp Polls Reviewed
one comment
page 58
Fun With Photo Data
12 comments
page 330
Fun With Sidebar Tabs Styling
2 comments
page 336
Html 5 Gallery
6 comments
page 1305
Using Your Own Url Shortener
4 comments
page 1190
Html 5 Gallery
6 comments
page 1305
My Experience Of Flexx
4 comments
page 1026
Fun With Sidebar Tabs
193 comments
page 57
Html 5 Gallery
6 comments
page 1305
Fun With Plugins
27 comments
page 14
Wordpress 25 Exif Fields
12 comments
page 230
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
  updated 1 seconds ago
Saturday, 8am
WordPress plugin uninstaller | WP FUN

[...] 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 [...]

Thursday, 10pm
WordPress Weekly – Episode 2 » Jeffro2pt0.com

[...] Andrew Rickmann – An Uninstall tool that adds an uninstallation option on the plugins page. The uninstall option will only show up if the plugin has been deactivated and if the plugin author has created an uninstall file. Check out the second iteration of his tool, here. [...]

Sunday, 8am
James

Great idea! Keep up the great work. I hate looking at my localhost DB and seeing the mess that is left after looking for a great plugin.
=-)

Friday, 11pm
Weblog Tools Collection » Blog Archive » WordPress Plugin Uninstall Tool

[...] the plugins page.  Update Jan 11: Andrew has released a second iteration of the uninstall tool.  Click here to check it out. (18 votes, average: 4.94 out of 5)  Loading … Sphere: Related [...]

Friday, 8pm
Fun with Uninstallation

[...] 2: This has now been superseded by this post, fun with uninstallation 2 [...]