Skip to content

Instantly share code, notes, and snippets.

@afragen
Last active May 2, 2023 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afragen/e2f40ed2e71e590a127e8adc1db05948 to your computer and use it in GitHub Desktop.
Save afragen/e2f40ed2e71e590a127e8adc1db05948 to your computer and use it in GitHub Desktop.
Stop success update email for plugin/theme auto updates.
<?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.2.0
* 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_update_send_email', 'send_email_on_failure', 10, 2 );
add_filter( 'auto_theme_update_send_email', 'send_email_on_failure', 10, 2 );
/**
* Sends update emails only when at least one plugin/theme update has failed.
*
* @param bool $enabled Whether the update email is enabled.
* @param array $update_results An array of update results.
* @return bool
*/
function send_email_on_failure( $enabled, $update_results ) {
foreach ( $update_results as $update_result ) {
if ( true !== $update_result->result ) {
return true;
}
}
return false;
}
@paaljoachim
Copy link

Lets turn it around:

function plugin_update_email_on_failure( $enabled, $update_results ) {
	foreach ( $update_results as $update_result ) {
		if ( false === $update_result->result ) {
			return true;
		}
	}
    return false;
}

Tutorial added here: https://easywebdesigntutorials.com/how-to-disable-update-emails-on-success/

@afragen
Copy link
Author

afragen commented Apr 26, 2023

Should now disable success email for both plugins and themes.

@paaljoachim
Copy link

Thanks Andy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment