[wp-hackers] register_uninstall_hook VS uninstall.php

The WordPress Web Warlock wordpress at web-warlocks.net
Sat May 8 10:39:16 UTC 2010


En/na Davit Barbakadze ha escrit:
> (...)
> Ok, what I do is I have my small framework, from which I inherit my all new
> plugins. My friends are using it too, so I needed a simple, transparent way
> to clean up after plugin, when it gets uninstalled. (...)

Why not hook into the uninstall hook?
I mean:

function my_plugin_main_uninstall(){
$args_init = array( 'foo' => 'bar' , 'bar' => 'foo' );
$args_init = apply_filter( 'my_plugin_args_init' , $args_init );
if( $args_init['include'] ) include
do_action( 'my_namespaced_uninstall_init' , $args_init );
if( $args_init['foo'] ) do_action( 'my_plugin_foo_uninstall' );
if( $args_init['bar'] ) do_action( 'my_plugin_bar_uninstall' );
};
register_uninstall_hook( $my_file , 'my_plugin_main_uninstall' );


Maybe I'm missing something, but by what I have understood, all you need 
is to declare a gazillion things. By creating your uninstall hooks, you 
can add the declaration functions both to plugins_loaded/admin/whatever 
AND my_unique_namespaced_uninstall_init.
I've been working with a "framework plugin", too, and this approach of 
uninstalling looks easier to me than all the uninstall.php & other 
approaches. I've got some dependencies that may be, or may be not, used 
by some of the "child plugins". There are options that may need removal, 
and maybe not because they simply don't exist — so it's better to skip 
that part of the uninstall process, instead of just checking every time 
if there is anything that needs removal. Besides, some plugins using 
shared optional components may have contradictory uninstall options — 
some parsing is needed here. This way I can do anything I need, in the 
right order, without having to duplicate selection code in each of the 
child plugins (which could even break older child plugins).


More information about the wp-hackers mailing list