[wp-trac] [WordPress Trac] #12754: register_uninstall_hook() doesn't allow multiple callbacks
WordPress Trac
wp-trac at lists.automattic.com
Mon Mar 29 07:58:24 UTC 2010
#12754: register_uninstall_hook() doesn't allow multiple callbacks
--------------------------+-------------------------------------------------
Reporter: scribu | Owner: westi
Type: defect (bug) | Status: new
Priority: normal | Milestone: 3.0
Component: Plugins | Version: 3.0
Severity: normal | Keywords: has-patch
--------------------------+-------------------------------------------------
Comment(by nacin):
A deactivation hook is run when the plugin is deactivated. That means that
the plugin is already activated and thus already included. The
deactivation callback is then run and the active_plugins option is updated
to remove the plugin for the next page load.
The uninstall hook may be run on a plugin that is not active, and thus not
included. The way it currently works, is you can run
register_uninstall_hook() on activation. By global scope, I meant on
inclusion. It works both on a regular hook like init and on a one-off like
activation.
If there's no conditional case involved, then there's little reason to
keep updating the database option, so on activation is fine. But, if you
were running it on the init hook, that hook is already fired by the time a
deactivated plugin file is included for the uninstall callback to be run.
That means no callback would be registered.
So, the only way the patch would work is if it is run in global scope.
This may be a requirement for register_activation_hook(), but it is not a
requirement for register_uninstall_hook(), which works perfectly fine if
done only on activation. I'm not speaking for the original developer or
committer, of course -- that could have been the idea.
I just searched briefly through the plugin directory and found a number of
plugins using it in global scope, but I also found a few that did it on
init, activation, or admin_init.
> So, as long as the plugin includes the file with the callback(s), it
doesn't matter where they are.
Sure, and that's a good practice, but if for whatever reason you wanted to
keep the function in a separate file (and not use uninstall.php, for
whatever reason) and use register_uninstall_hook(), that would no longer
work under your patch, as register_uninstall_hook() would not be fired.
Sure, that's a silly use case. I was just pointing out that you were
making an assumption.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/12754#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list