Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request audrasjb#57 from WordPress/add/notification-emails…
Browse files Browse the repository at this point in the history
…-checks

Add filters and constant to allow developers to disable plugins and themes autoupdate email notifications
  • Loading branch information
pbiron committed Apr 4, 2020
2 parents 4a1d359 + 7e242c9 commit e7a309b
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions functions.php
Expand Up @@ -846,6 +846,36 @@ function wp_autoupdates_debug_information( $info ) {
add_filter( 'debug_information', 'wp_autoupdates_debug_information' );


/**
* Checks whether plugins auto-update email notifications are enabled.
*/
function wp_autoupdates_is_plugins_auto_update_email_enabled() {
$enabled = ! defined( 'WP_DISABLE_PLUGINS_AUTO_UPDATE_EMAIL' ) || ! WP_DISABLE_PLUGINS_AUTO_UPDATE;

/**
* Filters whether plugins auto-update email notifications are enabled.
*
* @param bool $enabled True if plugins notifications are enabled, false otherwise.
*/
return apply_filters( 'send_plugins_auto_update_email', $enabled );
}


/**
* Checks whether themes auto-update email notifications are enabled.
*/
function wp_autoupdates_is_themes_auto_update_email_enabled() {
$enabled = ! defined( 'WP_DISABLE_THEMES_AUTO_UPDATE_EMAIL' ) || ! WP_DISABLE_THEMES_AUTO_UPDATE;

/**
* Filters whether themes auto-update email notifications are enabled.
*
* @param bool $enabled True if themes notifications are enabled, false otherwise.
*/
return apply_filters( 'send_themes_auto_update_email', $enabled );
}


/**
* If we tried to perform plugin or theme updates, check if we should send an email.
*
Expand All @@ -854,7 +884,7 @@ function wp_autoupdates_debug_information( $info ) {
function wp_autoupdates_automatic_updates_complete_notification( $results ) {
$successful_updates = array();
$failed_updates = array();
if ( isset( $results['plugin'] ) ) {
if ( isset( $results['plugin'] ) && wp_autoupdates_is_plugins_auto_update_email_enabled() ) {
foreach ( $results['plugin'] as $update_result ) {
if ( true === $update_result->result ) {
$successful_updates['plugin'][] = $update_result;
Expand All @@ -863,7 +893,7 @@ function wp_autoupdates_automatic_updates_complete_notification( $results ) {
}
}
}
if ( isset( $results['theme'] ) ) {
if ( isset( $results['theme'] ) && wp_autoupdates_is_themes_auto_update_enabled() ) {
foreach ( $results['theme'] as $update_result ) {
if ( true === $update_result->result ) {
$successful_updates['theme'][] = $update_result;
Expand Down

0 comments on commit e7a309b

Please sign in to comment.