I have developed a plugin, that requires to do some maintenance tasks after a certain WordPress plugin has been updated in my sites.
Currently, what I do, is to have this WP plugin on manual updates, and every time I update it manually, I run the code afterwards.
But I would like to automate this process.
Any ideas to makes this possible?
I have developed a plugin, that requires to do some maintenance tasks after a certain WordPress plugin has been updated in my sites.
Currently, what I do, is to have this WP plugin on manual updates, and every time I update it manually, I run the code afterwards.
But I would like to automate this process.
Any ideas to makes this possible?
Share Improve this question asked Feb 16, 2022 at 14:28 SirLouenSirLouen 857 bronze badges 2- 1 Try checking the following questions: stackoverflow.com/questions/24187990/plugin-update-hook wordpress.stackexchange.com/questions/144870/… – user1460692 Commented Feb 16, 2022 at 15:38
- note that if the plugin is updated using any method other than the updater, or your code runs but fails, maybe because it ran out of time or something else interfered, then you will have no opportunities to re-run your code. Likewise if it's a multisite and the upgrade happens from a blog where your plugin is not present. – Tom J Nowell ♦ Commented Feb 16, 2022 at 16:34
1 Answer
Reset to default 6I've always used the upgrader_process_complete
hook:
function my_plugins_update_completed( $upgrader_object, $options ) {
// If an update has taken place and the updated type is plugins and the plugins element exists
if ( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
foreach( $options['plugins'] as $plugin ) {
// Check to ensure it's my plugin
if( $plugin == plugin_basename( __FILE__ ) ) {
// do stuff here
}
}
}
}
add_action( 'upgrader_process_complete', 'my_plugins_update_completed', 10, 2 );
More info in the Codex: https://developer.wordpress.org/reference/hooks/upgrader_process_complete/
Hope that helps