888888.888888.88""Yb..dP"Yb..8888b..Yb..dP.88b.88....db....8b....d8.88..dP""b8..dP"Y8
88__...88__...88__dP.dP...Yb..8I..Yb.YbdP..88Yb88...dPYb...88b..d88.88.dP...`".`Ybo."
88""...88""...88"Yb..Yb...dP..8I..dY..8P...88.Y88..dP__Yb..88YbdP88.88.Yb......o.`Y8b
88.....888888.88..Yb..YbodP..8888Y"..dP....88..Y8.dP""""Yb.88.YY.88.88..YboodP.8bodP'


88b.88.888888.888888.Yb........dP.dP"Yb..88""Yb.88..dP
88Yb88.88__.....88....Yb..db..dP.dP...Yb.88__dP.88odP.
88.Y88.88"".....88.....YbdPYbdP..Yb...dP.88"Yb..88"Yb.
88..Y8.888888...88......YP..YP....YbodP..88..Yb.88..Yb

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

Fun With Sidebar Tabs Styling
Styling tabs css?
2 comments
page 336
Post Image The Easy Peasy Way
Theimage wordpress?
26 comments
page 1065
How To Add Sidebars To A Theme
Add widgetized footer in wordpress theme?
10 comments
page 1053
Html 5 Gallery
Html5 image gallery?
6 comments
page 1305
Wordpress Vs Graffiti
Graffiti yb combined?
8 comments
page 95
Poll Daddy Reviewed
Polldaddy poll?
2 comments
page 42
Why I Ditched Disqus
Add wordpress comments to friendfeed?
5 comments
page 1175
Html 5 Gallery
Html5 gallery?
6 comments
page 1305
Html 5 Gallery
Html5 gallery?
6 comments
page 1305
Post Image The Easy Peasy Way
Wp display all post images?
26 comments
page 1065
Quick N Dirty Post Exclusion
Fitler theloop addfilter?
11 comments
page 124
Using Your Own Url Shortener
Constructor and link shortner?
4 comments
page 1190
My Experience Of Flexx
Flexx of genesis wp theme?
4 comments
page 1026
Html 5 Gallery
Html5?
6 comments
page 1305
Wordpress Chat
Tchat page wordpress?
3 comments
page 1308
Quick N Dirty Post Exclusion
Filter wordpress posts plugin?
11 comments
page 124
Post Image The Easy Peasy Way
Wordpress attach images to post?
26 comments
page 1065
Post Image The Easy Peasy Way
Wp post orderby?
26 comments
page 1065
Auto Cycle Fun With Sidebar Tabs
Wordpress make your plugin updateable?
one comment
page 1129
Post Image The Easy Peasy Way
Wp add attachment?
26 comments
page 1065
Html 5 Gallery
Html 5 gallery?
6 comments
page 1305
Html 5 Gallery
Pictures html5?
6 comments
page 1305
Html 5 Gallery
Pictures html5?
6 comments
page 1305
Wordpress Chat
Postimagetheeasypeasyway?
3 comments
page 1308
Using Your Own Url Shortener
How to flushrewriterules?
4 comments
page 1190
Custom Hooks For Admin Pages
Addaction adminpost?
one comment
page 430
Custom Hooks For Admin Pages
Addaction adminpost?
one comment
page 430
Wordpress Chat
Chat themes?
3 comments
page 1308
Html 5 Gallery
Html5 wordpress?
6 comments
page 1305
Html 5 Gallery
Html5 photo gallery?
6 comments
page 1305
How To Add Sidebars To A Theme
Add more than one widget area to wordpress?
10 comments
page 1053
Post Image The Easy Peasy Way
Wordpress postimage img tag?
26 comments
page 1065
  1 query every 1272 seconds, 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 [...]