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



Wordpress feature image page?
24 comments on page 1065

Addsettingsfield?
3 comments on page 793

Shorter link?
4 comments on page 1190

Shorter link?
4 comments on page 1190

Cssimageforlogin?
no comment on page 128

Cssimageforlogin?
no comment on page 128

Get featured image url wordpress?
24 comments on page 1065

How to clear wpcache?
9 comments on page 1310

Photo gallry code html5?
6 comments on page 1305

Wordpress get image size?
24 comments on page 1065

Sitecouk wptheme?
2 comments on page 1376

Wordpress chat disqus?
no comment on page 1308

Howtocreategoodsizelayout?
4 comments on page 1026

Friend connect profile?
6 comments on page 1364

Get medium image from post?
24 comments on page 1065

Tabbed widgets wp?
no comment on page 333

Wordpress plugin post separator?
no comment on page 1371

Wordpress pictue cache lschen?
9 comments on page 1310

Display photos html 5?
6 comments on page 1305

Fun wordpress themes?
2 comments on page 1376

Wp featured image without size?
24 comments on page 1065

Wordpress get url global?
4 comments on page 1190

Wp unlimited?
3 comments on page 1141

Html5 image gallery?
6 comments on page 1305

Wordpress exif plugin?
12 comments on page 230

Css login screen?
no comment on page 128

Htlm 5 photo gallery?
6 comments on page 1305

Css login screen?
no comment on page 128

Comments by intensedebate?
7 comments on page 1175

Image gallery html 5?
6 comments on page 1305

Wordpress andrew rickmann?
2 comments on page 1376

Wordpress medium large?
24 comments on page 1065

Fun with uninstallation wordpress?
53 comments on page 100

How to clear wp cache?
9 comments on page 1310

Photoshop frameworks?
3 comments on page 296

Html5 gallery?
6 comments on page 1305

Html 5 photo gallery?
6 comments on page 1305

Login screen css template?
no comment on page 128

Html5 photo gallery code?
6 comments on page 1305

Wordpress post multiple images?
24 comments on page 1065
  every 1985s, 1s ago, in 0.03s.
 __
(__)
   `
 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 [...]

 __
(__)
   `
 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. [...]

 __
(__)
   `
 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.
=-)

 __
(__)
   `
 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 [...]

 __
(__)
   `
 Fun with Uninstallation

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


0s