Reading register_activation_hook() told me that in wordpress 3.1, this will only work for every plugin activation, not plugin upgrade.
What I want to know is, what’s the best plugin upgrade strategy?
My though is:
- on action ‘admin_init’ check for ‘{plugin_name}_version’ option
- if ‘{plugin_name}_version’ doesn’t exist, let’s assume it’s from previous version (because at that version, we don’t have ‘{plugin_name}_version’ option, yet. Go to process 2.
- if ‘{plugin_name}_version’ option exists and doesn’t match with ‘{plugin_name}_version’ set in script, go to process 2.
- if ‘{plugin_name}_version’ option match with ‘{plugin_name}_version’ set in script, exit process.
- launch our plugin upgrade function with ‘{plugin_name}_version’ value as parameter
- do whatever needed for this upgrade process
- after upgrade process finished, set ‘{plugin_name}_version’ option to ‘{plugin_name}_version’ from script.
Any comment for this process?
This was recently discussed at length on the wp-hackers list. Here’s the thread:
Quoting Otto from the list: