<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[25496] trunk/src/wp-admin/includes: WordPress Core Automatic Updates: Add a post-upgrade summary email to the WordPress install's admin email address.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/25496">25496</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2013-09-19 08:45:06 +0000 (Thu, 19 Sep 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>WordPress Core Automatic Updates: Add a post-upgrade summary email to the WordPress install's admin email address. See <a href="http://core.trac.wordpress.org/ticket/22704">#22704</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpupgraderskinsphp">trunk/src/wp-admin/includes/class-wp-upgrader-skins.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswpupgraderphp">trunk/src/wp-admin/includes/class-wp-upgrader.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpupgraderskinsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader-skins.php (25495 => 25496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2013-09-19 08:39:51 UTC (rev 25495)
+++ trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2013-09-19 08:45:06 UTC (rev 25496)
</span><span class="lines">@@ -539,7 +539,7 @@
</span><span class="cx"> * @since 3.7.0
</span><span class="cx"> */
</span><span class="cx"> class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
</span><del>- var $messages = array();
</del><ins>+ private $messages = array();
</ins><span class="cx">
</span><span class="cx"> function request_filesystem_credentials( $error = false, $context = '' ) {
</span><span class="cx"> if ( $context )
</span><span class="lines">@@ -553,6 +553,10 @@
</span><span class="cx"> return $result;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ function get_upgrade_messages() {
+ return $this->messages;
+ }
+
</ins><span class="cx"> function feedback( $data ) {
</span><span class="cx"> if ( is_wp_error( $data ) )
</span><span class="cx"> $string = $data->get_error_message();
</span></span></pre></div>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (25495 => 25496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-09-19 08:39:51 UTC (rev 25495)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-09-19 08:45:06 UTC (rev 25496)
</span><span class="lines">@@ -1183,7 +1183,7 @@
</span><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> // 2: If we're running a newer version, that's a nope
</span><del>- if ( version_compare( $wp_version, $offered_ver, '>=' ) )
</del><ins>+ if ( version_compare( $wp_version, $offered_ver, '>' ) )
</ins><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2
</span><span class="lines">@@ -1288,7 +1288,7 @@
</span><span class="cx"> */
</span><span class="cx"> class WP_Automatic_Upgrader {
</span><span class="cx">
</span><del>- static $skin;
</del><ins>+ static $upgrade_results = array();
</ins><span class="cx">
</span><span class="cx"> static function upgrader_disabled() {
</span><span class="cx"> // That's a no if you don't want files changes
</span><span class="lines">@@ -1362,38 +1362,54 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Checks to see if WP_Filesystem is setup to allow unattended upgrades
</span><del>- static function can_auto_update( $context ) {
- if ( ! self::$skin )
- self::$skin = new Automatic_Upgrader_Skin();
- return (bool) self::$skin->request_filesystem_credentials( false, $context );
</del><ins>+ static function can_auto_update( $context, $skin = false ) {
+ if ( ! $skin )
+ $skin = new Automatic_Upgrader_Skin();
+ return (bool) $skin->request_filesystem_credentials( false, $context );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static function upgrade( $type, $item ) {
</span><span class="cx">
</span><del>- if ( ! self::$skin )
- self::$skin = new Automatic_Upgrader_Skin();
</del><ins>+ $skin = new Automatic_Upgrader_Skin();
</ins><span class="cx">
</span><span class="cx"> switch ( $type ) {
</span><span class="cx"> case 'core':
</span><span class="cx"> // The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter
</span><del>- add_filter( 'update_feedback', array( self::$skin, 'feedback' ) );
- $upgrader = new Core_Upgrader( self::$skin );
</del><ins>+ add_filter( 'update_feedback', array( $skin, 'feedback' ) );
+ $upgrader = new Core_Upgrader( $skin );
</ins><span class="cx"> $context = ABSPATH;
</span><span class="cx"> break;
</span><span class="cx"> case 'plugin':
</span><del>- $upgrader = new Plugin_Upgrader( self::$skin );
</del><ins>+ $upgrader = new Plugin_Upgrader( $skin );
</ins><span class="cx"> $context = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR
</span><span class="cx"> break;
</span><span class="cx"> case 'theme':
</span><del>- $upgrader = new Theme_Upgrader( self::$skin );
</del><ins>+ $upgrader = new Theme_Upgrader( $skin );
</ins><span class="cx"> $context = get_theme_root( $item );
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Determine if we can perform this upgrade or not
</span><del>- if ( ! self::should_auto_update( $type, $item, $context ) || ! self::can_auto_update( $context ) )
</del><ins>+ if ( ! self::should_auto_update( $type, $item, $context ) || ! self::can_auto_update( $context, $skin ) )
</ins><span class="cx"> return false;
</span><span class="cx">
</span><ins>+ switch ( $type ) {
+ case 'core':
+ $skin->feedback( __( 'Updating to WordPress %s' ), $item->version );
+ $item_name = sprintf( __( 'WordPress %s' ), $item->version );
+ break;
+ case 'theme':
+ $theme = wp_get_theme( $item );
+ $item_name = $theme->Get( 'Name' );
+ $skin->feedback( __( 'Updating Theme: %s' ), $item_name );
+ break;
+ case 'plugin':
+ $plugin_data = get_plugin_data( $context . '/' . $item );
+ $item_name = $plugin_data['Name'];
+ $skin->feedback( __( 'Updating Plugin: %s' ), $item_name );
+ break;
+ }
+
</ins><span class="cx"> // Boom, This sites about to get a whole new splash of paint!
</span><span class="cx"> $upgrade_result = $upgrader->upgrade( $item, array(
</span><span class="cx"> 'clear_update_cache' => false,
</span><span class="lines">@@ -1402,33 +1418,17 @@
</span><span class="cx"> // Core doesn't output this, so lets append it so we don't get confused
</span><span class="cx"> if ( 'core' == $type ) {
</span><span class="cx"> if ( is_wp_error( $upgrade_result ) ) {
</span><del>- self::$skin->error( __( 'Installation Failed' ), $upgrade_result );
</del><ins>+ $skin->error( __( 'Installation Failed' ), $upgrade_result );
</ins><span class="cx"> } else {
</span><del>- self::$skin->feedback( __( 'WordPress updated successfully' ) );
</del><ins>+ $skin->feedback( __( 'WordPress updated successfully' ) );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // Clear cache's and transients
- switch ( $type ) {
- case 'core':
- delete_site_transient( 'update_core' );
- break;
- case 'theme':
- wp_clean_themes_cache();
- break;
- case 'plugin':
- wp_clean_plugins_cache();
- break;
- }
-
- wp_mail(
- get_site_option( 'admin_email' ),
- __METHOD__,
- var_export( array(
- $upgrade_result,
- $upgrader,
- self::$skin,
- ), true )
</del><ins>+ self::$upgrade_results[ $type ][] = (object) array(
+ 'item' => $item,
+ 'result' => ! is_wp_error( $upgrade_result ) && $upgrade_result,
+ 'name' => $item_name,
+ 'messages' => $skin->get_upgrade_messages()
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> return $upgrade_result;
</span><span class="lines">@@ -1476,17 +1476,100 @@
</span><span class="cx"> // Finally, Process any core upgrade
</span><span class="cx"> wp_version_check(); // Check for Core updates
</span><span class="cx"> $core_update = find_core_auto_update();
</span><del>- if ( $core_update )
</del><ins>+ if ( $core_update ) {
</ins><span class="cx"> self::upgrade( 'core', $core_update );
</span><ins>+ delete_site_transient( 'update_core' );
+ }
</ins><span class="cx">
</span><span class="cx"> // Cleanup, These won't trigger any updates this time due to the locking transient
</span><span class="cx"> wp_version_check(); // check for Core updates
</span><span class="cx"> wp_update_themes(); // Check for Theme updates
</span><span class="cx"> wp_update_plugins(); // Check for Plugin updates
</span><span class="cx">
</span><ins>+ self::send_email();
+
</ins><span class="cx"> // Clear the lock
</span><span class="cx"> delete_site_option( $lock_name );
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ static function send_email() {
+
+ if ( empty( self::$upgrade_results ) )
+ return;
+
+ $upgrade_count = 0;
+ foreach ( self::$upgrade_results as $type => $upgrades )
+ $upgrade_count += count( $upgrades );
+
+ $subject = sprintf( '[%s] %s updates have finished', get_bloginfo( 'name' ), $upgrade_count );
+
+ $body = '';
+ if ( isset( self::$upgrade_results['core'] ) ) {
+ $result = self::$upgrade_results['core'][0];
+ if ( $result->result && ! is_wp_error( $result->result ) )
+ $body[] = sprintf( __( 'WordPress was successfully updated to %s' ), $result->name );
+ else
+ $body[] = sprintf( __( 'WordPress unsuccessfully attempted to update to %s' ), $result->name );
+ }
+
+ // Plugins
+ if ( isset( self::$upgrade_results['plugin'] ) ) {
+ $success_plugins = wp_list_filter( self::$upgrade_results['plugin'], array( 'result' => true ) );
+
+ if ( $success_plugins )
+ $body[] = sprintf( _n( 'The following plugin was successfully updated: %s', 'The following plugins were successfully updated: %s', count( $success_plugins ) ), implode( ', ', wp_list_pluck( $success_plugins, 'name' ) ) );
+ if ( $success_plugins != self::$upgrade_results['plugin'] ) {
+ // Failed updates
+ $failed_plugins = array();
+ foreach ( self::$upgrade_results['plugin'] as $plugin ) {
+ if ( ! $plugin->result || is_wp_error( $plugin->result ) )
+ $failed_plugins[] = $plugin;
+ }
+ $body[] = sprintf( _n( 'The following plugin failed to successfully update: %s', 'The following plugins failed to successfully update: %s', count( $success_plugins ) ), implode( ', ', wp_list_pluck( $failed_plugins, 'name' ) ) );
+ }
+ }
+
+ // Themes
+ if ( isset( self::$upgrade_results['theme'] ) ) {
+ $success_themes = wp_list_filter( self::$upgrade_results['theme'], array( 'result' => true ) );
+
+ if ( $success_themes )
+ $body[] = sprintf( _n( 'The following theme was successfully updated: %s', 'The following themes were successfully updated: %s', count( $success_themes ) ), implode( ', ', wp_list_pluck( $success_themes, 'name' ) ) );
+ if ( $success_themes != self::$upgrade_results['theme'] ) {
+ // Failed updates
+ $failed_themes = array();
+ foreach ( self::$upgrade_results['theme'] as $theme ) {
+ if ( ! $theme->result || is_wp_error( $theme->result ) )
+ $failed_themes[] = $theme;
+ }
+ $body[] = sprintf( _n( 'The following theme failed to successfully update: %s', 'The following themes failed to successfully update: %s', count( $failed_themes ) ), implode( ', ', wp_list_pluck( $failed_themes, 'name' ) ) );
+ }
+ }
+
+ $body[] = '';
+ $body[] = __( 'Below is the upgrade logs for update performed' );
+
+ foreach ( array( 'core', 'plugin', 'theme' ) as $type ) {
+ if ( ! isset( self::$upgrade_results[ $type ] ) )
+ continue;
+ foreach ( self::$upgrade_results[ $type ] as $upgrade ) {
+ $body[] = $upgrade->name;
+ $body[] = str_repeat( '=', strlen( $upgrade->name ) );
+ foreach ( $upgrade->messages as $message )
+ $body[] = " " . html_entity_decode( $message );
+ $body[] = '';
+ }
+ }
+
+ //echo "<h1>$subject</h1>";
+ //echo '<pre>' . implode( "\n", $body ) . '</pre>';
+
+ wp_mail(
+ get_site_option( 'admin_email' ),
+ $subject,
+ implode( "\n", $body )
+ );
+ }
+
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>