1

Is there any hook for when any plugin update is found to trigger a mail using PHP? I found reference to upgrader_process_complete hook, but that is called after plugins are updated and not before.

Also, how can I fetch the list of plugins which have updates pending at a given time?

  • You're going to need to track which plugins you've sent emails for and which versions, otherwise you're going to recieve a lot of emails – Tom J Nowell May 7 at 11:25
  • @TomJNowell Right. That can be done by storing in database. But how do I fetch the plugins which has updates available? – Saeesh Tendulkar May 7 at 11:32
1

The relevant code is wp_update_plugins(). You can see that it stores its state in a site transient called 'update_plugins':

set_site_transient( 'update_plugins', $new_option );

and we can hook that:

  • pre_set_site_transient_update_plugins - called at the start of set_site_transient()
  • set_site_transient_update_plugins - called at the end, if the value was changed

Note that

  • set_site_transient( 'update_plugins', ... ) is called twice as part of the update: once to update the last_checked timestamp, and once with the new-plugins-to-update list; the first call will always therefore have a changed value without necessarily having the list of updated plugins changed
  • it can also be called when deleting plugins, to remove the update flag for any deleted plugin, but only once in this case.

I appreciate that hooking the site transient updates seems a bit of a hack, but there's no other obvious place to hook that the update check is complete. I have seen pay-for plugins hook these too as a way of generating update-needed for plugins hosted elsewhere.


Alternatively of course you don't need to hook the actual update, but you can instead schedule a cron job that checks get_site_transient( 'update_plugins' ) (and update_themes and update_core) to generate the notification email.

| improve this answer | |
0

With the answer of Rup, you can create a simple mail with the wp_mail function.

It would look like this:

 wp_mail( get_bloginfo( 'admin_email' ), 'Subject title here', 'Text for mail here'); 

With get_bloginfo( 'admin_email' ) you'll retrieve the admin's email you filled in during installation.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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