Make WordPress Core


Ignore:
Timestamp:
10/15/2020 11:29:17 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.
Merges [49166] to the 5.5 branch.
Fixes #51400.

Location:
branches/5.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/src/wp-admin/includes/class-wp-automatic-updater.php

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