[wp-hackers] Plugin register_activation_hook()

Dion Hulse (dd32) wordpress at dd32.id.au
Thu Dec 29 23:34:37 UTC 2011

The plugin upgrader will NOT catch a fatal error reliably. If it's a
singular plugin upgrade, it'll be caught, but if it's part of a bulk
upgrade, it won't be caught unfortunately.

The best way to handle any upgrade function you need is to store a
"Database version", for example:

add_action('admin_init', function() {
if ( get_option('plugin_db_version') != 3 ) {
  if ( get_option('plugin_db_version') < 2 ) {
  if ( get_option('plugin_db_version') < 3 ) {
  update_option('plugin_db_version', 3);

Hopefully your plugin isn't written in a way that it'll fatal if the
options haven't been updated..
Also, never perform the above checks on a non-admin page (which is why
i've used the admin_init hook), doing so will lead to concurrency
issues and much more likely that the upgrade routines will fire
multiple times.

See also:

On 30 December 2011 10:21, Ade Walker <photofantaisie at gmail.com> wrote:
> No, it doesn't run during upgrade. Just found the answer, doh!
> http://codex.wordpress.org/Function_Reference/register_activation_hook
> So, what is best practice for a plugin handling, say, a WP version check
> when upgrading? Can I rely on the plugin upgrade error checking to catch a
> PHP fatal error, and subsequently deactivate the plugin?
> Thanks for any suggestions.
> 2011/12/29 Ade Walker <photofantaisie at gmail.com>
>> Hi all,
>> Can anyone confirm that a plugin's registered activation hook is always
>> fired during the auto upgrade process?
>> Thanks!
>> Ade.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list