[wp-hackers] Plugin activation/deactivation and testing?

Dion Hulse (dd32) wordpress at dd32.id.au
Thu Nov 19 21:09:56 UTC 2009


Long post.. But i'll fill you in:

Upon plugin upgrade the process is:
  * Fetch download
  * Extract into temp table
  * Deacivate plugin (Note, Hoooks are NOT called at this deactivation. In  
bulk upgrade in 2.9, he blog goes into maintainence mode insead)
  * Current plugin's folder is deleted
  * New files are moved into its place
  * Plugin is reactivated, activation hooks ARE called at this point.

The activation hook should be used to create tables/defaults if they are  
not already set. You may want to change your deactivation hook to ask for  
confirmation before removing all the data.. Alternativly, You can have a  
look at the plugin uninstall hooks which are run on plugin DELETE, So  
users can deactivate your plugin, yet keep the settings until they decide  
to delete it through the admin interface.

Thats just on the upgrade proceedure.. I'd like to hear what others have  
to say about the rest of your items tho.

On Fri, 20 Nov 2009 07:28:14 +1100, mark waterous <mark at watero.us> wrote:

> 1) According to the Codex, register_activation_hook and
> register_deactivation_hook should only be called once during the  
> lifetime of
> an installed plugin. Is this *completely* accurate?
>
> The reason I ask, despite the Codex saying so, is twofold; the first  
> reason
> is that I've been dissecting some of my favorite plugins while trying to
> improve the upgrade process I'm using in my own, and it looks like a few  
> of
> them are relying on their activation hook to complete necessary  
> upgrades, ie
> database changes or options updates. They don't appear to have any  
> specific
> version checks outside of the activation hooks that would call it  
> directly,
> yet they have specifically named upgrade methods running inside of it.  
> I'm
> assuming this is to provide for people who deactivate their plugins  
> before
> activating a new version, but it's gotten me to wonder 'what if'...
>
> The second reason is that I've had some reports of data loss when  
> upgrading
> my plugin, and the only possible cause I've been able to track down is  
> the
> fact that I have a deactivation hook which does cleanup on uninstall and
> removes the additional db tables and options. One of two things is most
> likely happening and I haven't gotten a clear answer from the bug  
> reports;
> either they're deactivating the plugin manually, in which case I think  
> I'm
> going to move the uninstall feature to the options page and remove my
> deactivation hook, or the deactivation hook is being called at some  
> stage of
> the upgrade process and wiping the data clean before reactivating the  
> latest
> version.
-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the wp-hackers mailing list