Last active
July 17, 2024 22:43
-
-
Save afragen/e2f40ed2e71e590a127e8adc1db05948 to your computer and use it in GitHub Desktop.
Stop success update email for plugin/theme auto updates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Stop success email from auto-updates. | |
* | |
* @package StopAutoUpdateSuccessEmail | |
* | |
* Plugin Name: Stop Auto-update Success Email | |
* Plugin URI: https://gist.github.com/afragen/e2f40ed2e71e590a127e8adc1db05948 | |
* Description: Stop success email from auto-updates. | |
* Version: 0.5.1 | |
* Author: WordPress Core Contributors | |
* License: MIT | |
* Requires at least: 5.2 | |
* Requires PHP: 5.6 | |
* Gist Plugin URI: https://gist.github.com/afragen/e2f40ed2e71e590a127e8adc1db05948 | |
*/ | |
add_filter( 'auto_plugin_theme_update_email', 'send_email_on_failure', 10, 2 ); | |
// Send debug email on failures. | |
add_filter( 'automatic_updates_debug_email', 'send_debug_email_on_failure', 10, 3 ); | |
// Disable sending debug email. | |
// add_filter( 'automatic_updates_send_debug_email', '__return_false', 10, 2 ); | |
/** | |
* Sends update emails only when at least one plugin/theme update has failed. | |
* | |
* @param array $email Array of email args. | |
* @param string $type The type of email being sent. Can be one of 'success', 'fail', 'mixed'. | |
* | |
* @return array | |
*/ | |
function send_email_on_failure( $email, $type ) { | |
if ( 'success' === $type ) { | |
$email = array( | |
'to' => '', | |
'subject' => '', | |
'body' => '', | |
'headers' => '', | |
); | |
} | |
return $email; | |
} | |
/** | |
* Sends debug email on plugin/theme failures. | |
* | |
* @param array $email Array of email data. | |
* @param int $failures Number of failures. | |
* @param mixed $results The results of all attempted updates. | |
* | |
* @return array | |
*/ | |
function send_debug_email_on_failure( $email, $failures, $results ) { | |
$empty_email = array( | |
'to' => '', | |
'subject' => '', | |
'body' => '', | |
'headers' => '', | |
); | |
foreach ( $results as $result ) { | |
foreach ( $result as $res ) { | |
if ( is_wp_error( $res->result ) ) { | |
++$failures; | |
} | |
} | |
} | |
if ( 0 === $failures ) { | |
$email = $empty_email; | |
} | |
return $email; | |
} |
Should now disable success email for both plugins and themes.
Thanks Andy!
large reorg for 0.4.0
large reorg for 0.4.0
Do you mean 0.5.0?
Does that mean the above code has recently been updated?
@paaljoachim both, but it really was 0.4.0. I added the sending of debug emails for failures. Then in 0.5.0 I added the filter to stop sending debug emails as they had become annoying in my continued testing of Rollback Auto-Update.
You can comment out the filter that stops all debug emails if you want to see them.
I had that last filter in WordPress Beta Tester but decided it really didn’t belong there.
0.5.1 comments out filter that stops debug email from being sent. Uncomment if you don’t want to see them either.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lets turn it around:
Tutorial added here: https://easywebdesigntutorials.com/how-to-disable-update-emails-on-success/