2

Pretty much a newbie to WordPress here but was wondering if there are any hooks or anything that could be used to send a notification out if either a WordPress update fails or a plugin update fails?

Preferably both if possible but definitely the main core of WordPress being updated.

I noticed there are a couple of plugins for WordPress which allow you to send notifications to emails or Slack channels depending on certain actions happening on a site. Most of these are to do with new posts or comments to posts and so on and so forth though.

One of the plugins allows you to specify a 'hook' which when it fires will send a notification to a Slack channel so I was wondering is there any way of plugging into this in any way when an update of any sort fails?

Many thanks.

1 Answer 1

3

Yes, there is a hook you can use, it's called upgrader_process_complete. This hook fires after plugins or core has been upgraded.

You can hook to this action and send an email:

function send_custom_email( $object, $options ) {
    // Get the path for plugins
    $plugin_path = plugin_basename( __FILE__ );
    // Check if the plugin is upgraded
    if ($options['type'] == 'plugin' && $options['action'] == 'update' ){
        foreach($options['packages'] as $plugin){
            if ($plugin == $plugin_path){
            // Do some stuff here
            }
        }
    }
}

add_action( 'upgrader_process_complete', 'send_custom_email',10, 2);

This function allows you to do whatever you want whenever a plugin is updated. You can do so with the core updates, too.

2
  • Hi Jack. Many thanks for that. Just wondering if there's a way to use this so that if an update fails to get a notification or is that what this code does do already? Sorry my coding skills aren't fantastic and so don't totally understand everything in the above code.
    – Mark Bowen
    Jun 17, 2017 at 9:44
  • @MarkBowen Hi! You're welcome. If you aren't familiar with coding, you can use WP Update Notifier plugin. It hasn't been updated for a while, but based on user ratings it appears that it's compatible with the recent WordPress versions.
    – Johansson
    Jun 17, 2017 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.