<!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>[25837] trunk/src/wp-admin/includes/class-wp-upgrader.php: Introduce email templates for automatic background updates.</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/25837">25837</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-10-18 06:32:27 +0000 (Fri, 18 Oct 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce email templates for automatic background updates.

The four templates are:
 1. We successfully updated their site. If any of their themes or plugins are out of date, it also mentions that. ('success')
 2. We are not configured to update their site, so we notify them of the new release. ('notify')
 3. We tried but failed to update their site. The error was early in the process, so no harm, no foul. This is the same as template <a href="http://core.trac.wordpress.org/ticket/2">#2</a>, plus one sentence. ('fail')
 4. We tried to update their site, and failed while copying files. ('critical')

With assistance from markjaquith.

see <a href="http://core.trac.wordpress.org/ticket/10787">#10787</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<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="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (25836 => 25837)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php        2013-10-17 23:23:42 UTC (rev 25836)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php   2013-10-18 06:32:27 UTC (rev 25837)
</span><span class="lines">@@ -1836,8 +1836,103 @@
</span><span class="cx">          delete_option( $lock_name );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       function send_debug_email() {
</del><ins>+        protected function send_email( $type, $core_update, $result = null ) {
+               if ( ! apply_filters( 'automatic_updates_send_email', true, $type, $core_update, $result ) )
+                       return;
</ins><span class="cx"> 
</span><ins>+               switch ( $type ) {
+                       case 'success' : // We updated.
+                               /* translators: 1: Site name, 2: WordPress version number. */
+                               $subject = __( '[%1$s] Your site has updated to WordPress %2$s' );
+                               break;
+
+                       case 'fail' :   // We tried to update but couldn't.
+                       case 'manual' : // We can't update (and made no attempt).
+                               /* translators: 1: Site name, 2: WordPress version number. */
+                               $subject = __( '[%1$s] WordPress %2$s is available. Please update!' );
+                               break;
+
+                       case 'critical' : // We tried to update, started to copy files, then things went wrong.
+                               /* translators: 1: Site name. */
+                               $subject = __( '[%1$s] URGENT: Your site may be down due to a failed update' );
+                               break;
+
+                       default :
+                               return;
+               }
+
+               $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $core_update->current );
+
+               $body = '';
+
+               switch ( $type ) {
+                       case 'success' :
+                               $body .= sprintf( __( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ), home_url(), $core_update->current );
+                               $body .= "\n\n" . __( 'No further action is needed on your part.' );
+
+                               // Can only reference the About screen if their update was successful.
+                               list( $about_version ) = explode( '-', $core_update->current, 2 );
+                               $body .= ' ' . sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version );
+                               $body .= "\n" . admin_url( 'about.php' );
+                               break;
+
+                       case 'fail' :
+                       case 'manual' :
+                               $body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $core_update->current );
+
+                               $body .= "\n\n";
+                               if ( 'fail' == $type )
+                                       $body .= __( 'We tried but were unable to update your site automatically.' ) . ' ';
+                               $body .= __( 'Updating is easy and only takes a few moments:' );
+                               $body .= "\n" . network_admin_url( 'update-core.php' );
+                               break;
+
+                       case 'critical' :
+                               $body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.' ), home_url(), $core_update->current );
+
+                               $body .= "\n\n" . __( "This means your site may be offline or broken. Don't panic; this can be fixed." );
+
+                               $body .= "\n\n" . __( "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" . network_admin_url( 'update-core.php' );
+                               break;
+               }
+
+               // Updates are important!
+               if ( $type != 'success' )
+                       $body .= "\n\n" . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' );
+
+               // Add a note about the support forums to all emails.
+               $body .= "\n\n" . __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' );
+               $body .= "\n" . __( 'http://wordpress.org/support/' );
+
+               // If things are successful, mention plugins and themes if any are out of date.
+               if ( $type == 'success' && ( get_plugin_updates() || get_theme_updates() ) ) {
+                       $body .= "\n\n" . __( 'You also have some plugins or themes with updates available. Update them now:' );
+                       $body .= "\n" . network_admin_url();
+               }
+
+               $body .= "\n\n" . __( 'The WordPress Team' ) . "\n";
+
+               if ( 'critical' == $type && is_wp_error( $result ) ) {
+                       $body .= "\n***\n\n";
+                       $body .= __( 'We have some data that describes the error your site encountered.' );
+                       $body .= ' ' . __( 'Your hosting company, support forum volunteers, or a friendly developer may be able to use this information to help you:' );
+                       $body .= "\n" . sprintf( __( "Error code: %s" ), $result->get_error_code() );
+                       $body .= "\n" . $result->get_error_message();
+                       $body .= "\n" . implode( ', ', (array) $result->get_error_data() );
+                       $body .= "\n";
+               }
+
+               $to  = get_site_option( 'admin_email' );
+               $headers = '';
+
+               $email = compact( 'to', 'body', 'subject', 'headers' );
+               $email = apply_filters( 'automatic_update_send_email', $email, $type, $core_update, $result );
+
+               wp_mail( $email['to'], $email['subject'], $email['body'], $email['headers'] );
+       }
+
+       protected function send_debug_email() {
</ins><span class="cx">           if ( empty( $this->update_results ) )
</span><span class="cx">                  return;
</span><span class="cx"> 
</span><span class="lines">@@ -1913,8 +2008,11 @@
</span><span class="cx">                          $body[] = str_repeat( '-', strlen( $update->name ) );
</span><span class="cx">                          foreach ( $update->messages as $message )
</span><span class="cx">                                  $body[] = "  " . html_entity_decode( str_replace( '&#8230;', '...', $message ) );
</span><del>-                               if ( is_wp_error( $update->result ) )
</del><ins>+                                if ( is_wp_error( $update->result ) ) {
</ins><span class="cx">                                   $body[] = '  Error: [' . $update->result->get_error_code() . '] ' . $update->result->get_error_message();
</span><ins>+                                       if ( $update->result->get_error_data() )
+                                               $body[] = '         ' . implode( ', ', (array) $update->result->get_error_data() );
+                               }
</ins><span class="cx">                           $body[] = '';
</span><span class="cx">                  }
</span><span class="cx">          }
</span></span></pre>
</div>
</div>

</body>
</html>