[wp-hackers] Plugin uninstall/deactivate in 2.7 vs 2.6

Jacob Santos wordpress at santosj.name
Sun Nov 2 03:11:51 GMT 2008


Sigh, I wrote about this on my blog when ever it was first introduced, 
but I guess many missed that. No worries, Frank's article appears to be 
better written.

Your code will not work the way you think. The constant 
WP_UNINSTALL_PLUGIN does not exist until uninstall. It is something you 
look for the existence of, not the lack of existence of.

For backwards compatibility, you should use the method that DD32 wrote 
about in his reply.

Jacob Santos

A Walker wrote:
> Having read Frank's excellent article here: http://wpengineer.com/wordpress-plugin-deinstall-data-automatically/ I think I understood much better how the plugin uninstall routines work in 2.7. Thanks Frank!
>
> It seems to me that for 2.7+ the register_deactivation_hook is no longer required provided the plugin author provides an uninstall.php file with the appropriate code. So, I was wondering about adding some backwards compatibility for 2.6 etc, so that the plugin's options are deleted from the db if a user with less than 2.7 decides to deactivate the plugin. I tried adding this to my plugin, but found that the deactivation hook was still being registered under WP 2.7 beta 1:
>
> <code>if ( !defined ( WP_UNINSTALL_PLUGIN ) ) {
> register_deactivation_hook(function to delete options...)
> }</code>
>
> Then, create an uninstall.php with delete_options(blah blah) for 2.7+. 
>
> In case I haven't explained myself very well (probably not, lol) the idea is to only register the deactivation hook if the plugin is installed on WP 2.6 and below.
>
> I'm scratching my head on this, and if anyone can point out where I've overlooked the obvious - please do! Thanks!  :-) 
>
> Ade.
> _________________________________________________________________
> Découvrez la nouvelle génération des servives de Windows Live
> http://get.live.com_______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>   



More information about the wp-hackers mailing list