WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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? – Hameedullah Khan Jan 23 '12 at 10:28
Yep, that's right – Aram Kocharyan Jan 23 '12 at 10:50
Rather, I was wondering if there was a built in way to do it, or a preferred method provided by WP. – Aram Kocharyan Jan 23 '12 at 10:53
up vote 2 down vote accepted

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.

share|improve this answer
You're quite right. codex.wordpress.org/Function_Reference/register_activation_hook. Very ambiguous though, since the auto update says reactivating plugin... – Aram Kocharyan Jan 23 '12 at 16:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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