I have used:

register_activation_hook(__FILE__, 'CrayonWP::install');

In install() I would like to check the plugin version being installed, and if it is below a certain version, I would like to alter the existing database model to the new format. How would I determine the version being installed?

  • My understanding is.. you want to check if older version of plugin is installed or have the db from older plugin you want to upgrade it when installing newer version of the plugin? Jan 23, 2012 at 10:28
  • Yep, that's right Jan 23, 2012 at 10:50
  • Rather, I was wondering if there was a built in way to do it, or a preferred method provided by WP. Jan 23, 2012 at 10:53

1 Answer 1


register_activation_hook() is only called when the user activates the plugin. It is not called after a plugin upgrade.

The preferred method of handling upgrades is using register_activation_hook() to store the current version in the wp_options table and then checking it on each admin page load.

  • 2
    You're quite right. codex.wordpress.org/Function_Reference/register_activation_hook. Very ambiguous though, since the auto update says reactivating plugin... Jan 23, 2012 at 16:17
  • But if we use register_activation_hook to store current version and this will only fire on the initial activation and not following upgrades, what's the point?
    – chifliiiii
    Apr 3, 2019 at 18:05
  • @chifliiiii so that if the stored version is either lower that current - or not present - you can then run any update procedures and bump the value to the current version.
    – majick
    Oct 11, 2019 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.