Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Add filters and constant to allow developers to disable plugins and themes autoupdate email notifications #57

Merged
merged 1 commit into from
Apr 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions functions.php
Original file line number Diff line number Diff line change
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