13

My plugin needs to fire an init/build/checker function when the plugin is updated via auto updates in the WP dashboard.

Is there a WordPress hook that is fired after a plugin has been updated from the wordpress.org repository?

I'm not looking for register_activation_hook or register_deactivation_hook as those only execute on manual activation/deactivation.

Darren Cooney
  • 1,012
  • 16
  • 25

1 Answers1

21

Yes, upgrader_process_complete [see also: core reference] does that. Inspect the second parameter to know if it is a core, plugin or theme update; and if it is bulk or not.

add_action( 'upgrader_process_complete', function( $upgrader_object, $options ) {
    // inspect $options
}, 10, 2 );
T.Todua
  • 53,146
  • 19
  • 236
  • 237
brasofilo
  • 25,496
  • 15
  • 91
  • 179
  • Thanks. This seems promising. Do you know how recent this hook was added? The docs are incomplete. – Darren Cooney Jun 13 '14 at 13:11
  • 1
    Looks like [14 months ago](https://core.trac.wordpress.org/changeset/23912). Well, you can test it and update the Codex with your findings ;) – brasofilo Jun 13 '14 at 13:18
  • 3
    If someone is actually trying to use the code from codex, I've realized there was a little mistake. I've just fixed it. **$options['packages']** should be **$options['plugins']** – Pablo S G Pacheco Oct 07 '17 at 15:21
  • Seems to have been added on 4th April 2013, according to @brasofilo 's comment – Max Carroll May 25 '20 at 08:29
  • 4
    Worth noting that the documentation also says "Use with caution: When you use the upgrader_process_complete action hook in your plugin and your plugin is the one which under upgrade, then this action will run the old version of your plugin." Just thought that this is – Max Carroll May 25 '20 at 08:32
  • 2
    ... and, indeed, this will make `upgrader_process_complete` totally useless for the purposes stated by the OP. – Gwyneth Llewelyn Jul 30 '21 at 15:34