Upgrade/Install: Check if plugin or theme update results are available before applying the notification filters.

This avoids a PHP notice for an undefined index of either `plugin` or `theme` in the `auto_{plugin|theme}_update_send_email` filter hook.

Props afragen, audrasjb.
Fixes #51400.

git-svn-id: https://develop.svn.wordpress.org/trunk@49166 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-10-15 23:25:19 +00:00
parent 805351a478
commit 45432f4c39
1 changed files with 36 additions and 32 deletions

View File

@ -892,44 +892,48 @@ class WP_Automatic_Updater {
$successful_updates = array(); $successful_updates = array();
$failed_updates = array(); $failed_updates = array();
/** if ( ! empty( $update_results['plugin'] ) ) {
* Filters whether to send an email following an automatic background plugin update. /**
* * Filters whether to send an email following an automatic background plugin update.
* @since 5.5.0 *
* @since 5.5.1 Added the `$update_results` parameter. * @since 5.5.0
* * @since 5.5.1 Added the `$update_results` parameter.
* @param bool $enabled True if plugin update notifications are enabled, false otherwise. *
* @param array $update_results The results of plugins update tasks. * @param bool $enabled True if plugin update notifications are enabled, false otherwise.
*/ * @param array $update_results The results of plugins update tasks.
$notifications_enabled = apply_filters( 'auto_plugin_update_send_email', true, $update_results['plugin'] ); */
$notifications_enabled = apply_filters( 'auto_plugin_update_send_email', true, $update_results['plugin'] );
if ( ! empty( $update_results['plugin'] ) && $notifications_enabled ) { if ( $notifications_enabled ) {
foreach ( $update_results['plugin'] as $update_result ) { foreach ( $update_results['plugin'] as $update_result ) {
if ( true === $update_result->result ) { if ( true === $update_result->result ) {
$successful_updates['plugin'][] = $update_result; $successful_updates['plugin'][] = $update_result;
} else { } else {
$failed_updates['plugin'][] = $update_result; $failed_updates['plugin'][] = $update_result;
}
} }
} }
} }
/** if ( ! empty( $update_results['theme'] ) ) {
* Filters whether to send an email following an automatic background theme update. /**
* * Filters whether to send an email following an automatic background theme update.
* @since 5.5.0 *
* @since 5.5.1 Added the `$update_results` parameter. * @since 5.5.0
* * @since 5.5.1 Added the `$update_results` parameter.
* @param bool $enabled True if theme update notifications are enabled, false otherwise. *
* @param array $update_results The results of theme update tasks. * @param bool $enabled True if theme update notifications are enabled, false otherwise.
*/ * @param array $update_results The results of theme update tasks.
$notifications_enabled = apply_filters( 'auto_theme_update_send_email', true, $update_results['theme'] ); */
$notifications_enabled = apply_filters( 'auto_theme_update_send_email', true, $update_results['theme'] );
if ( ! empty( $update_results['theme'] ) && $notifications_enabled ) { if ( $notifications_enabled ) {
foreach ( $update_results['theme'] as $update_result ) { foreach ( $update_results['theme'] as $update_result ) {
if ( true === $update_result->result ) { if ( true === $update_result->result ) {
$successful_updates['theme'][] = $update_result; $successful_updates['theme'][] = $update_result;
} else { } else {
$failed_updates['theme'][] = $update_result; $failed_updates['theme'][] = $update_result;
}
} }
} }
} }