[wp-hackers] Will Activation Hook Be Executed During Plugin Upgradation?

Otto otto at ottodestruct.com
Mon Sep 20 18:17:37 UTC 2010


On Mon, Sep 20, 2010 at 1:10 PM, Rich Pedley <elfin at elfden.co.uk> wrote:
> A lot of plugin authors, myself included (but I can easily change things if
> necessary) use this 'feature' (well that's what MS calls it...) to upgrade
> things. So if this really is the case that we shouldn't be using it, what
> would be the correct way to upgrade?

Depends on what exactly you're "upgrading".

The simplest method that would work everywhere would be simply to
store the version number of the plugin somewhere (like in your options
entry in the database), then compare the stored version with your
known current and hardcoded version. When you detect the difference,
then that means an upgrade has taken place, and you can act
accordingly.

Another way is simply to make the plugin detect outdated options or
older schemas and upgrade them on-the-fly. This is probably the most
reliable, but it does depend on what exactly you're upgrading. You
can't necessarily make this "generic".

-Otto


More information about the wp-hackers mailing list