WordPress in version 3.7 introduced a most welcome and a game changing feature – automatic updates. This slightly controversial-at-the-time feature allowed WordPress to automatically update minor or security releases without the need of user intervention. This was needed, as more WordPress installations out there are secure and safe, with fewer bugs. It is a good thing. A very, good thing.
However, if you manage a number of sites using something like ManageWP or WPRemote, you can get hundreds, even thousands of emails saying you need to update your site. Whilst useful for those with a small number of sites, it can be a bit much if you have a lot of users.
Furthermore, if a lot of your sites are hosted on the same server, or use the same email delivery method over a number of sites, this mass-sending of emails can cause problems. I trust WordPress to stagger the updates, but you never know.
As a result, you may wish to prevent emails being sent, but still go through the updates. Luckily, this is incredibly easy using a WordPress filter.
The auto_core_update_send_email
filter
The filter you need is the auto_core_update_send_email filter
. This filter accepts a number of arguments dependant on the email that is being sent.
To do so, create a new WordPress plugin. Simply include the following lines after the header:-
1 2 3 4 5 6 7 8 9 | /** * Make WordPress not send automatic update emails * * @link https://www.winwar.co.uk/2017/04/disable-automatic-update-emails/?utm_source=codesnippet * @return false */ function winwar_dont_send_email() { return false; } add_filter( 'auto_core_update_send_email', 'winwar_dont_send_email' ); |
This will stop all email being sent after updates, but unfortunately it will stop all emails. You may want to allow some emails such as failures or critical errors through so you can act on them. Luckily this is quite possible.
The auto_core_update_send_email
Parameters
There are a number of associated parameters with the auto_core_update_send_email. They are the following:-
- $send – The result of whether to send an email. This is what you need to return.
- $type – The type of the email to send. This is one off three values: “success”, “fail” or “critical”. “fail” means that the update failed. “Critical” means that the update failed and it has taken down the site.
- $core_update – The update offer that is attempted. I’m not 100% sure what this is.
- $result – The result of the update attempted, this can be an error message.
With this knowledge, we can build something better for email wise. To receive the emails only when there is an error, do the following code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Make WordPress only send emails based on critical or failures * * @link https://www.winwar.co.uk/2017/04/disable-automatic-update-emails/?utm_source=codesnippet * * @param boolean $send Whether to send the email. Default true. * @param string $type The type of email to send. Can be one of 'success', 'fail', 'critical'. * @param object $core_update The update offer that was attempted. * @param mixed $result The result for the core update. Can be WP_Error. * @return boolean True to send the email, false if not. */ function winwar_dont_send_email( $send, $type, $core_update, $result ) { if ( $type == 'fail' || $type == 'critical' ) { return true; } else { return false; } } add_filter( 'auto_core_update_send_email', 'winwar_dont_send_email', 10, 4 ); |
I hope this turns out to be useful. As said earlier you shouldn’t have to disable your updates, but it is probably a good idea to limit the amount of emails to be sent, especially is nothing is wrong.
I hadn’t realized how big of a deal this could be for those managing a high volume of websites. Good call with the quick plugin solution.
May 7, 2017 at 10:22 am