From 52b1c0c9d3ed0b3cdf831dc7b386d0dd8144623e Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Mon, 22 Jun 2020 18:16:30 +0000 Subject: [PATCH] Administration: Improve the plugin and theme auto-update emails. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes several improvements to the emails sent to site admins when plugin and theme auto-updates are attempted. - Emails are now specifically tailored to the three results (success, failed, or mixed). - Subject lines and body copy for mixed and failed results now correctly convey the importance of double checking the site in question. - The site’s URL is now included in all emails. - When failures occur, links to the Plugins and/or Themes pages in the admin are now included so that site owners can easily take action. Props audrasjb, desrosj, azaozz, garrett-eclipse, paaljoachim, johnbillion, marybaum, pbiron. Follow up to [47835]. See #50052. Fixes #50268. git-svn-id: https://develop.svn.wordpress.org/trunk@48123 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-automatic-updater.php | 176 ++++++++++++------ 1 file changed, 121 insertions(+), 55 deletions(-) diff --git a/src/wp-admin/includes/class-wp-automatic-updater.php b/src/wp-admin/includes/class-wp-automatic-updater.php index 016e36b771..f9020f7a3b 100644 --- a/src/wp-admin/includes/class-wp-automatic-updater.php +++ b/src/wp-admin/includes/class-wp-automatic-updater.php @@ -940,75 +940,141 @@ class WP_Automatic_Updater { if ( empty( $successful_updates ) && empty( $failed_updates ) ) { return; } - $body = array(); + + $body = array(); + $successful_plugins = ( ! empty( $successful_updates['plugin'] ) ); + $successful_themes = ( ! empty( $successful_updates['theme'] ) ); + $failed_plugins = ( ! empty( $failed_updates['plugin'] ) ); + $failed_themes = ( ! empty( $failed_updates['theme'] ) ); switch ( $type ) { case 'success': - /* translators: %s: Site title. */ - $subject = __( '[%s] Some plugins or themes were automatically updated' ); + if ( $successful_plugins && $successful_themes ) { + /* translators: %s: Site title. */ + $subject = __( '[%s] Some plugins and themes have automatically updated' ); + $body[] = sprintf( + /* translators: %s: Home URL. */ + __( 'Howdy! Some plugins and themes have automatically updated to their latest versions on your site at %s. No further action is needed on your part.' ), + home_url() + ); + } elseif ( $successful_plugins ) { + /* translators: %s: Site title. */ + $subject = __( '[%s] Some plugins were automatically updated' ); + $body[] = sprintf( + /* translators: %s: Home URL. */ + __( 'Howdy! Some plugins have automatically updated to their latest versions on your site at %s. No further action is needed on your part.' ), + home_url() + ); + } else { + /* translators: %s: Site title. */ + $subject = __( '[%s] Some themes were automatically updated' ); + $body[] = sprintf( + /* translators: %s: Home URL. */ + __( 'Howdy! Some themes have automatically updated to their latest versions on your site at %s. No further action is needed on your part.' ), + home_url() + ); + } + break; case 'fail': - /* translators: %s: Site title. */ - $subject = __( '[%s] Some plugins or themes have failed to update' ); - $body[] = sprintf( - /* translators: %s: Home URL. */ - __( 'Howdy! Failures occurred when attempting to update plugins/themes on your site at %s.' ), - home_url() - ); - $body[] = "\n"; - $body[] = __( 'Please check out your site now. It’s possible that everything is working. If it says you need to update, you should do so.' ); - break; case 'mixed': - /* translators: %s: Site title. */ - $subject = __( '[%s] Some plugins or themes were automatically updated' ); - $body[] = sprintf( - /* translators: %s: Home URL. */ - __( 'Howdy! Failures occurred when attempting to update plugins/themes on your site at %s.' ), - home_url() - ); - $body[] = "\n"; - $body[] = __( 'Please check out your site now. It’s possible that everything is working. If it says you need to update, you should do so.' ); - $body[] = "\n"; + if ( $failed_plugins && $failed_themes ) { + /* translators: %s: Site title. */ + $subject = __( '[%s] Some plugins and themes have failed to update' ); + $body[] = sprintf( + /* translators: %s: Home URL. */ + __( 'Howdy! Plugins and themes failed to update on your site at %s.' ), + home_url() + ); + } elseif ( $failed_plugins ) { + /* translators: %s: Site title. */ + $subject = __( '[%s] Some plugins have failed to update' ); + $body[] = sprintf( + /* translators: %s: Home URL. */ + __( 'Howdy! Plugins failed to update on your site at %s.' ), + home_url() + ); + } else { + /* translators: %s: Site title. */ + $subject = __( '[%s] Some themes have failed to update' ); + $body[] = sprintf( + /* translators: %s: Home URL. */ + __( 'Howdy! Themes failed to update on your site at %s.' ), + home_url() + ); + } + break; } - // Get failed plugin updates. - if ( in_array( $type, array( 'fail', 'mixed' ), true ) && ! empty( $failed_updates['plugin'] ) ) { - $body[] = __( 'The following plugins failed to update:' ); - // List failed updates. - foreach ( $failed_updates['plugin'] as $item ) { - $body[] = "- {$item->name}"; + if ( in_array( $type, array( 'fail', 'mixed' ), true ) ) { + $body[] = "\n"; + $body[] = __( 'Please check your site now. It’s possible that everything is working. If there are updates available, you should update.' ); + $body[] = "\n"; + + // List failed plugin updates. + if ( ! empty( $failed_updates['plugin'] ) ) { + $body[] = __( 'These plugins failed to update:' ); + + foreach ( $failed_updates['plugin'] as $item ) { + $body[] = "- {$item->name}"; + } + $body[] = "\n"; } + + // List failed theme updates. + if ( ! empty( $failed_updates['theme'] ) ) { + $body[] = __( 'These themes failed to update:' ); + + foreach ( $failed_updates['theme'] as $item ) { + $body[] = "- {$item->name}"; + } + $body[] = "\n"; + } + } + + // List successful updates. + if ( in_array( $type, array( 'success', 'mixed' ), true ) ) { + $body[] = "\n"; + + // List successful plugin updates. + if ( ! empty( $successful_updates['plugin'] ) ) { + $body[] = __( 'These plugins are now up to date:' ); + + foreach ( $successful_updates['plugin'] as $item ) { + $body[] = "- {$item->name}"; + } + $body[] = "\n"; + } + + // List successful theme updates. + if ( ! empty( $successful_updates['theme'] ) ) { + $body[] = __( 'These themes are now up to date:' ); + // List successful updates. + foreach ( $successful_updates['theme'] as $item ) { + $body[] = "- {$item->name}"; + } + $body[] = "\n"; + } + } + + if ( $failed_plugins ) { + $body[] = sprintf( + /* translators: %s: Plugins screen URL. */ + __( 'To manage plugins on your site, visit the Plugins page: %s' ), + admin_url( 'plugins.php' ) + ); $body[] = "\n"; } - // Get failed theme updates. - if ( in_array( $type, array( 'fail', 'mixed' ), true ) && ! empty( $failed_updates['theme'] ) ) { - $body[] = __( 'The following themes failed to update:' ); - // List failed updates. - foreach ( $failed_updates['theme'] as $item ) { - $body[] = "- {$item->name}"; - } + + if ( $failed_themes ) { + $body[] = sprintf( + /* translators: %s: Themes screen URL. */ + __( 'To manage themes on your site, visit the Themes page: %s' ), + admin_url( 'themes.php' ) + ); $body[] = "\n"; } - // Get successful plugin updates. - if ( in_array( $type, array( 'success', 'mixed' ), true ) && ! empty( $successful_updates['plugin'] ) ) { - $body[] = __( 'The following plugins were successfully updated:' ); - // List successful updates. - foreach ( $successful_updates['plugin'] as $item ) { - $body[] = "- {$item->name}"; - } - $body[] = "\n"; - } - // Get successful theme updates. - if ( in_array( $type, array( 'success', 'mixed' ), true ) && ! empty( $successful_updates['theme'] ) ) { - $body[] = __( 'The following themes were successfully updated:' ); - // List successful updates. - foreach ( $successful_updates['theme'] as $item ) { - $body[] = "- {$item->name}"; - } - $body[] = "\n"; - } - $body[] = "\n"; // Add a note about the support forums. $body[] = __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' );