Make WordPress Core

Changeset 49166 for trunk


Ignore:
Timestamp:
10/15/2020 11:25:19 PM (6 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-automatic-updater.php

    r49061 r49166  
    893893                $failed_updates     = array();
    894894
    895                 /**
    896                  * Filters whether to send an email following an automatic background plugin update.
    897                  *
    898                  * @since 5.5.0
    899                  * @since 5.5.1 Added the `$update_results` parameter.
    900                  *
    901                  * @param bool  $enabled        True if plugin update notifications are enabled, false otherwise.
    902                  * @param array $update_results The results of plugins update tasks.
    903                  */
    904                 $notifications_enabled = apply_filters( 'auto_plugin_update_send_email', true, $update_results['plugin'] );
    905 
    906                 if ( ! empty( $update_results['plugin'] ) && $notifications_enabled ) {
    907                         foreach ( $update_results['plugin'] as $update_result ) {
    908                                 if ( true === $update_result->result ) {
    909                                         $successful_updates['plugin'][] = $update_result;
    910                                 } else {
    911                                         $failed_updates['plugin'][] = $update_result;
    912                                 }
    913                         }
    914                 }
    915 
    916                 /**
    917                  * Filters whether to send an email following an automatic background theme update.
    918                  *
    919                  * @since 5.5.0
    920                  * @since 5.5.1 Added the `$update_results` parameter.
    921                  *
    922                  * @param bool  $enabled        True if theme update notifications are enabled, false otherwise.
    923                  * @param array $update_results The results of theme update tasks.
    924                  */
    925                 $notifications_enabled = apply_filters( 'auto_theme_update_send_email', true, $update_results['theme'] );
    926 
    927                 if ( ! empty( $update_results['theme'] ) && $notifications_enabled ) {
    928                         foreach ( $update_results['theme'] as $update_result ) {
    929                                 if ( true === $update_result->result ) {
    930                                         $successful_updates['theme'][] = $update_result;
    931                                 } else {
    932                                         $failed_updates['theme'][] = $update_result;
     895                if ( ! empty( $update_results['plugin'] ) ) {
     896                        /**
     897                         * Filters whether to send an email following an automatic background plugin update.
     898                         *
     899                         * @since 5.5.0
     900                         * @since 5.5.1 Added the `$update_results` parameter.
     901                         *
     902                         * @param bool  $enabled        True if plugin update notifications are enabled, false otherwise.
     903                         * @param array $update_results The results of plugins update tasks.
     904                         */
     905                        $notifications_enabled = apply_filters( 'auto_plugin_update_send_email', true, $update_results['plugin'] );
     906
     907                        if ( $notifications_enabled ) {
     908                                foreach ( $update_results['plugin'] as $update_result ) {
     909                                        if ( true === $update_result->result ) {
     910                                                $successful_updates['plugin'][] = $update_result;
     911                                        } else {
     912                                                $failed_updates['plugin'][] = $update_result;
     913                                        }
     914                                }
     915                        }
     916                }
     917
     918                if ( ! empty( $update_results['theme'] ) ) {
     919                        /**
     920                         * Filters whether to send an email following an automatic background theme update.
     921                         *
     922                         * @since 5.5.0
     923                         * @since 5.5.1 Added the `$update_results` parameter.
     924                         *
     925                         * @param bool  $enabled        True if theme update notifications are enabled, false otherwise.
     926                         * @param array $update_results The results of theme update tasks.
     927                         */
     928                        $notifications_enabled = apply_filters( 'auto_theme_update_send_email', true, $update_results['theme'] );
     929
     930                        if ( $notifications_enabled ) {
     931                                foreach ( $update_results['theme'] as $update_result ) {
     932                                        if ( true === $update_result->result ) {
     933                                                $successful_updates['theme'][] = $update_result;
     934                                        } else {
     935                                                $failed_updates['theme'][] = $update_result;
     936                                        }
    933937                                }
    934938                        }
Note: See TracChangeset for help on using the changeset viewer.