Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 1 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
1  
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
add comment

Your Answer

 
discard

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.