<!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>[25859] trunk/src/wp-admin/includes: Rename the automatic_updates_send_email filter to auto_core_update_send_email.</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/25859">25859</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-10-21 22:28:07 +0000 (Mon, 21 Oct 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Rename the automatic_updates_send_email filter to auto_core_update_send_email. (Final name change.)
fixes <a href="http://core.trac.wordpress.org/ticket/25653">#25653</a>. Also:
* Fully document all new hooks, methods, and classes in the upgrader.
* Rename 'language' to 'translation' inside the upgrader.
* Improve the readability of the crazy do-while loop in the is_vcs_checkout() method.</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 (25858 => 25859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2013-10-21 21:17:00 UTC (rev 25858)
+++ trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2013-10-21 22:28:07 UTC (rev 25859)
</span><span class="lines">@@ -591,7 +591,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>- private $messages = array();
</del><ins>+ protected $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></pre></div>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (25858 => 25859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-10-21 21:17:00 UTC (rev 25858)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-10-21 22:28:07 UTC (rev 25859)
</span><span class="lines">@@ -1097,6 +1097,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
</span><ins>+
+/**
+ * Language pack upgrader, for updating translations of plugins, themes, and core.
+ *
+ * @package WordPress
+ * @subpackage Upgrader
+ * @since 3.7.0
+ */
</ins><span class="cx"> class Language_Pack_Upgrader extends WP_Upgrader {
</span><span class="cx">
</span><span class="cx"> var $result;
</span><span class="lines">@@ -1568,15 +1576,27 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * WordPress automatic background updater.
</del><ins>+ * The WordPress automatic background updater.
</ins><span class="cx"> *
</span><ins>+ * @package WordPress
+ * @subpackage Upgrader
</ins><span class="cx"> * @since 3.7.0
</span><span class="cx"> */
</span><span class="cx"> class WP_Automatic_Updater {
</span><span class="cx">
</span><ins>+ /**
+ * Tracks update results during processing.
+ *
+ * @var array
+ */
</ins><span class="cx"> protected $update_results = array();
</span><span class="cx">
</span><del>- function is_disabled() {
</del><ins>+ /**
+ * Whether the entire automatic updater is disabled.
+ *
+ * @since 3.7.0
+ */
+ public function is_disabled() {
</ins><span class="cx"> // Background updates are disabled if you don't want file changes.
</span><span class="cx"> if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS )
</span><span class="cx"> return true;
</span><span class="lines">@@ -1587,13 +1607,35 @@
</span><span class="cx"> // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters.
</span><span class="cx"> $disabled = defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED;
</span><span class="cx">
</span><ins>+ /**
+ * Filter whether to entirely disable background updates.
+ *
+ * There are more fine-grained filters and controls for selective disabling.
+ * This filter parallels the AUTOMATIC_UPDATER_DISABLED constant in name.
+ *
+ * @since 3.7.0
+ * @param bool $disabled Whether the updater should be disabled.
+ */
</ins><span class="cx"> return apply_filters( 'automatic_updater_disabled', $disabled );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Check for GIT/SVN checkouts.
</del><ins>+ * Check for version control checkouts.
+ *
+ * Checks for Subversion, Git, Mercurial, and Bazaar. It recursively looks up the
+ * filesystem to the top of the drive, erring on the side of detecting a VCS
+ * checkout somewhere.
+ *
+ * ABSPATH is always checked in addition to whatever $context is (which may be the
+ * wp-content directory, for example). The underlying assumption is that if you are
+ * using version control *anywhere*, then you should be making decisions for
+ * how things get updated.
+ *
+ * @since 3.7.0
+ *
+ * @param string $context The filesystem path to check, in addition to ABSPATH.
</ins><span class="cx"> */
</span><del>- function is_vcs_checkout( $context ) {
</del><ins>+ public function is_vcs_checkout( $context ) {
</ins><span class="cx"> $context_dirs = array( untrailingslashit( $context ) );
</span><span class="cx"> if ( $context !== ABSPATH )
</span><span class="cx"> $context_dirs[] = untrailingslashit( ABSPATH );
</span><span class="lines">@@ -1605,7 +1647,13 @@
</span><span class="cx"> // Walk up from $context_dir to the root.
</span><span class="cx"> do {
</span><span class="cx"> $check_dirs[] = $context_dir;
</span><del>- } while ( $context_dir != dirname( $context_dir ) && $context_dir = dirname( $context_dir ) );
</del><ins>+
+ // Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here.
+ if ( $context_dir == dirname( $context_dir ) )
+ break;
+
+ // Continue one level at a time.
+ } while ( $context_dir = dirname( $context_dir ) );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $check_dirs = array_unique( $check_dirs );
</span><span class="lines">@@ -1617,13 +1665,30 @@
</span><span class="cx"> break 2;
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
+ /**
+ * Filter whether the automatic updater should consider a filesystem location to be potentially
+ * managed by a version control system.
+ *
+ * @since 3.7.0
+ *
+ * @param bool $checkout Whether a VCS checkout was discovered at $context or ABSPATH, or anywhere higher.
+ * @param string $context The filesystem context (a path) against which filesystem status should be checked.
+ */
</ins><span class="cx"> return apply_filters( 'automatic_updates_is_vcs_checkout', $checkout, $context );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Tests to see if we can and should update a specific item.
</span><ins>+ *
+ * @since 3.7.0
+ *
+ * @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
+ * @param object $item The update offer.
+ * @param string $context The filesystem context (a path) against which filesystem access and status
+ * should be checked.
</ins><span class="cx"> */
</span><del>- function should_update( $type, $item, $context ) {
</del><ins>+ public function should_update( $type, $item, $context ) {
</ins><span class="cx"> if ( $this->is_disabled() )
</span><span class="cx"> return false;
</span><span class="cx">
</span><span class="lines">@@ -1641,8 +1706,23 @@
</span><span class="cx"> else
</span><span class="cx"> $update = ! empty( $item->autoupdate );
</span><span class="cx">
</span><del>- // And does the user / plugins want it?
- // Plugins may filter on 'auto_update_plugin', and check the 2nd param, $item, to only enable it for certain Plugins/Themes
</del><ins>+ /**
+ * Filter whether to automatically update core, a plugin, a theme, or a language.
+ *
+ * The dynamic portion of the hook name, $type, refers to the type of update
+ * being checked. Can be 'core', 'theme', 'plugin', or 'translation'.
+ *
+ * Generally speaking, plugins, themes, and major core versions are not updated by default,
+ * while translations and minor and development versions for core are updated by default.
+ *
+ * See the filters allow_dev_auto_core_updates, allow_minor_auto_core_updates, and
+ * allow_major_auto_core_updates more straightforward filters to adjust core updates.
+ *
+ * @since 3.7.0
+ *
+ * @param bool $update Whether to update.
+ * @param object $item The update offer.
+ */
</ins><span class="cx"> $update = apply_filters( 'auto_update_' . $type, $update, $item );
</span><span class="cx">
</span><span class="cx"> if ( ! $update ) {
</span><span class="lines">@@ -1679,8 +1759,15 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function update( $type, $item ) {
-
</del><ins>+ /**
+ * Update an item, if appropriate.
+ *
+ * @since 3.7.0
+ *
+ * @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
+ * @param object $item The update offer.
+ */
+ public function update( $type, $item ) {
</ins><span class="cx"> $skin = new Automatic_Upgrader_Skin;
</span><span class="cx">
</span><span class="cx"> switch ( $type ) {
</span><span class="lines">@@ -1698,7 +1785,7 @@
</span><span class="cx"> $upgrader = new Theme_Upgrader( $skin );
</span><span class="cx"> $context = get_theme_root( $item );
</span><span class="cx"> break;
</span><del>- case 'language':
</del><ins>+ case 'translation':
</ins><span class="cx"> $upgrader = new Language_Pack_Upgrader( $skin );
</span><span class="cx"> $context = WP_CONTENT_DIR; // WP_LANG_DIR;
</span><span class="cx"> break;
</span><span class="lines">@@ -1723,7 +1810,7 @@
</span><span class="cx"> $item_name = $plugin_data['Name'];
</span><span class="cx"> $skin->feedback( __( 'Updating plugin: %s' ), $item_name );
</span><span class="cx"> break;
</span><del>- case 'language':
</del><ins>+ case 'translation':
</ins><span class="cx"> $language_item_name = $upgrader->get_name_for_update( $item );
</span><span class="cx"> $item_name = sprintf( __( 'Translations for %s' ), $language_item_name );
</span><span class="cx"> $skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)…' ), $language_item_name, $item->language ) );
</span><span class="lines">@@ -1757,9 +1844,11 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Kicks off a update request for each item in the update "queue".
</del><ins>+ * Kicks off the background update process, looping through all pending updates.
+ *
+ * @since 3.7.0
</ins><span class="cx"> */
</span><del>- function run() {
</del><ins>+ public function run() {
</ins><span class="cx"> global $wpdb, $wp_version;
</span><span class="cx">
</span><span class="cx"> if ( ! is_main_network() || ! is_main_site() )
</span><span class="lines">@@ -1850,7 +1939,7 @@
</span><span class="cx"> $language_updates = wp_get_translation_updates();
</span><span class="cx"> if ( $language_updates ) {
</span><span class="cx"> foreach ( $language_updates as $update ) {
</span><del>- $this->update( 'language', $update );
</del><ins>+ $this->update( 'translation', $update );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Clear existing caches
</span><span class="lines">@@ -1866,6 +1955,13 @@
</span><span class="cx"> // Send debugging email to all development installs.
</span><span class="cx"> if ( ! empty( $this->update_results ) ) {
</span><span class="cx"> $development_version = false !== strpos( $wp_version, '-' );
</span><ins>+ /**
+ * Filter whether to send a debugging email for each automatic background update.
+ *
+ * @since 3.7.0
+ * @param bool $development_version By default, emails are sent if the install is a development version.
+ * Return false to avoid the email.
+ */
</ins><span class="cx"> if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) )
</span><span class="cx"> $this->send_debug_email();
</span><span class="cx">
</span><span class="lines">@@ -1880,6 +1976,8 @@
</span><span class="cx"> /**
</span><span class="cx"> * If we tried to perform a core update, check if we should send an email,
</span><span class="cx"> * and if we need to avoid processing future updates.
</span><ins>+ *
+ * @param object $update_result The result of the core update. Includes the update offer and result.
</ins><span class="cx"> */
</span><span class="cx"> protected function after_core_update( $update_result ) {
</span><span class="cx"> global $wp_version;
</span><span class="lines">@@ -1956,6 +2054,15 @@
</span><span class="cx"> $this->send_email( 'fail', $core_update, $result );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Sends an email upon the completion or failure of a background core update.
+ *
+ * @since 3.7.0
+ *
+ * @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
+ * @param object $core_update The update offer that was attempted.
+ * @param mixed $result Optional. The result for the core update. Can be WP_Error.
+ */
</ins><span class="cx"> protected function send_email( $type, $core_update, $result = null ) {
</span><span class="cx"> update_site_option( 'auto_core_update_notified', array(
</span><span class="cx"> 'type' => $type,
</span><span class="lines">@@ -1964,7 +2071,17 @@
</span><span class="cx"> 'timestamp' => time(),
</span><span class="cx"> ) );
</span><span class="cx">
</span><del>- if ( ! apply_filters( 'automatic_updates_send_email', true, $type, $core_update, $result ) )
</del><ins>+ /**
+ * Filter whether to send an email following an automatic background core update.
+ *
+ * @since 3.7.0
+ *
+ * @param bool $send Whether to send the email. Default true.
+ * @param string $type The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'.
+ * @param object $core_update The update offer that was attempted.
+ * @param mixed $result The result for the core update. Can be WP_Error.
+ */
+ if ( ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) )
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> switch ( $type ) {
</span><span class="lines">@@ -2055,12 +2172,34 @@
</span><span class="cx"> $to = get_site_option( 'admin_email' );
</span><span class="cx"> $headers = '';
</span><span class="cx">
</span><del>- $email = compact( 'to', 'body', 'subject', 'headers' );
- $email = apply_filters( 'automatic_update_send_email', $email, $type, $core_update, $result );
</del><ins>+ $email = compact( 'to', 'subject', 'body', 'headers' );
+ /**
+ * Filter the email sent following an automatic background core update.
+ *
+ * @since 3.7.0
+ *
+ * @param array $email {
+ * Array of email arguments that will be passed to wp_mail().
+ *
+ * @type string $to The email recipient. An array of emails can be returned, as handled by wp_mail().
+ * @type string $subject The email's subject.
+ * @type string $body The email message body.
+ * @type string $headers Any email headers, defaults to no headers.
+ * }
+ * @param string $type The type of email being sent. Can be one of 'success', 'fail', 'manual', 'critical'.
+ * @param object $core_update The update offer that was attempted.
+ * @param mixed $result The result for the core update. Can be WP_Error.
+ */
+ $email = apply_filters( 'auto_core_update_email', $email, $type, $core_update, $result );
</ins><span class="cx">
</span><span class="cx"> wp_mail( $email['to'], $email['subject'], $email['body'], $email['headers'] );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Prepares and sends an email of a full log of background update results, useful for debugging and geekery.
+ *
+ * @since 3.7.0
+ */
</ins><span class="cx"> protected function send_debug_email() {
</span><span class="cx"> $update_count = 0;
</span><span class="cx"> foreach ( $this->update_results as $type => $updates )
</span><span class="lines">@@ -2083,8 +2222,8 @@
</span><span class="cx"> $body[] = '';
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // Plugins, Themes, Languages
- foreach ( array( 'plugin', 'theme', 'language' ) as $type ) {
</del><ins>+ // Plugins, Themes, Translations
+ foreach ( array( 'plugin', 'theme', 'translation' ) as $type ) {
</ins><span class="cx"> if ( ! isset( $this->update_results[ $type ] ) )
</span><span class="cx"> continue;
</span><span class="cx"> $success_items = wp_list_filter( $this->update_results[ $type ], array( 'result' => true ) );
</span><span class="lines">@@ -2128,7 +2267,7 @@
</span><span class="cx"> $body[] = '==========';
</span><span class="cx"> $body[] = '';
</span><span class="cx">
</span><del>- foreach ( array( 'core', 'plugin', 'theme', 'language' ) as $type ) {
</del><ins>+ foreach ( array( 'core', 'plugin', 'theme', 'translation' ) as $type ) {
</ins><span class="cx"> if ( ! isset( $this->update_results[ $type ] ) )
</span><span class="cx"> continue;
</span><span class="cx"> foreach ( $this->update_results[ $type ] as $update ) {
</span><span class="lines">@@ -2150,4 +2289,4 @@
</span><span class="cx">
</span><span class="cx"> wp_mail( get_site_option( 'admin_email' ), $subject, implode( "\n", $body ) );
</span><span class="cx"> }
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
</ins></span></pre>
</div>
</div>
</body>
</html>