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

mark waterous mark at watero.us
Thu Nov 19 20:28:14 UTC 2009

I have a couple of 'newbie' questions I'm hoping might someone here could
help me clarify; I've attempted to search the Codex and Google thoroughly
before asking, and while I've found tentative answers, they don't completely
clear up the situation for me.

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

This is 'what if' #2 spurred on by another developer suggesting that they
thought during the automatic upgrade of a plugin, Wordpress was deactivating
the old before activating the new, instead of just laying it in over top
(such as if you were to ftp the new version).

2) When releasing a new plugin, is there any way to mimic an automatic
upgrade to see how it will affect users blogs before actually tagging the
new release? (aka, do you have any suggestions for helping me to improve my
testing process before releasing a new plugin into the wild?)

This may seem like a stupid question, but I'm asking it anyways - I try and
test as much as I can, throwing different possible scenarios at my plugin,
running with WP_DEBUG on and so forth, but all my testing includes direct
editing of my files on my sandbox. I've even begun a routine where by before
I release a new version of the plugin, I install an old version, activate
it, upload a newer, activate it, and upload the latest, and make sure
nothing breaks along the way. Nevertheless I'm worried that this isn't
enough, and I would like to be able to test it from every possible angle,
such as what would happen during an automatic upgrade, before releasing the
next version.

My plugin is still technically in beta, but by the time I get it to a stable
version 1.0 release I would like to have a rock solid testing routine to
make sure that when I tag a new version, I'm not going to bring anybodies
site down. Any past experience or blogs I could read and research on the
subject would be greatly appreciated!

Mark Waterous
(mark at watero.us) 

More information about the wp-hackers mailing list