WordPress Core Automatic Updates: Add a post-upgrade summary email to the WordPress install's admin email address. See #22704
git-svn-id: https://develop.svn.wordpress.org/trunk@25496 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fb0b86a078
commit
f52d0a96af
@ -539,7 +539,7 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
|
|||||||
* @since 3.7.0
|
* @since 3.7.0
|
||||||
*/
|
*/
|
||||||
class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
|
class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||||
var $messages = array();
|
private $messages = array();
|
||||||
|
|
||||||
function request_filesystem_credentials( $error = false, $context = '' ) {
|
function request_filesystem_credentials( $error = false, $context = '' ) {
|
||||||
if ( $context )
|
if ( $context )
|
||||||
@ -553,6 +553,10 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_upgrade_messages() {
|
||||||
|
return $this->messages;
|
||||||
|
}
|
||||||
|
|
||||||
function feedback( $data ) {
|
function feedback( $data ) {
|
||||||
if ( is_wp_error( $data ) )
|
if ( is_wp_error( $data ) )
|
||||||
$string = $data->get_error_message();
|
$string = $data->get_error_message();
|
||||||
|
@ -1183,7 +1183,7 @@ class Core_Upgrader extends WP_Upgrader {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 2: If we're running a newer version, that's a nope
|
// 2: If we're running a newer version, that's a nope
|
||||||
if ( version_compare( $wp_version, $offered_ver, '>=' ) )
|
if ( version_compare( $wp_version, $offered_ver, '>' ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2
|
// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2
|
||||||
@ -1288,7 +1288,7 @@ class File_Upload_Upgrader {
|
|||||||
*/
|
*/
|
||||||
class WP_Automatic_Upgrader {
|
class WP_Automatic_Upgrader {
|
||||||
|
|
||||||
static $skin;
|
static $upgrade_results = array();
|
||||||
|
|
||||||
static function upgrader_disabled() {
|
static function upgrader_disabled() {
|
||||||
// That's a no if you don't want files changes
|
// That's a no if you don't want files changes
|
||||||
@ -1362,38 +1362,54 @@ class WP_Automatic_Upgrader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Checks to see if WP_Filesystem is setup to allow unattended upgrades
|
// Checks to see if WP_Filesystem is setup to allow unattended upgrades
|
||||||
static function can_auto_update( $context ) {
|
static function can_auto_update( $context, $skin = false ) {
|
||||||
if ( ! self::$skin )
|
if ( ! $skin )
|
||||||
self::$skin = new Automatic_Upgrader_Skin();
|
$skin = new Automatic_Upgrader_Skin();
|
||||||
return (bool) self::$skin->request_filesystem_credentials( false, $context );
|
return (bool) $skin->request_filesystem_credentials( false, $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
static function upgrade( $type, $item ) {
|
static function upgrade( $type, $item ) {
|
||||||
|
|
||||||
if ( ! self::$skin )
|
$skin = new Automatic_Upgrader_Skin();
|
||||||
self::$skin = new Automatic_Upgrader_Skin();
|
|
||||||
|
|
||||||
switch ( $type ) {
|
switch ( $type ) {
|
||||||
case 'core':
|
case 'core':
|
||||||
// The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter
|
// The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter
|
||||||
add_filter( 'update_feedback', array( self::$skin, 'feedback' ) );
|
add_filter( 'update_feedback', array( $skin, 'feedback' ) );
|
||||||
$upgrader = new Core_Upgrader( self::$skin );
|
$upgrader = new Core_Upgrader( $skin );
|
||||||
$context = ABSPATH;
|
$context = ABSPATH;
|
||||||
break;
|
break;
|
||||||
case 'plugin':
|
case 'plugin':
|
||||||
$upgrader = new Plugin_Upgrader( self::$skin );
|
$upgrader = new Plugin_Upgrader( $skin );
|
||||||
$context = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR
|
$context = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR
|
||||||
break;
|
break;
|
||||||
case 'theme':
|
case 'theme':
|
||||||
$upgrader = new Theme_Upgrader( self::$skin );
|
$upgrader = new Theme_Upgrader( $skin );
|
||||||
$context = get_theme_root( $item );
|
$context = get_theme_root( $item );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if we can perform this upgrade or not
|
// Determine if we can perform this upgrade or not
|
||||||
if ( ! self::should_auto_update( $type, $item, $context ) || ! self::can_auto_update( $context ) )
|
if ( ! self::should_auto_update( $type, $item, $context ) || ! self::can_auto_update( $context, $skin ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
// Boom, This sites about to get a whole new splash of paint!
|
// Boom, This sites about to get a whole new splash of paint!
|
||||||
$upgrade_result = $upgrader->upgrade( $item, array(
|
$upgrade_result = $upgrader->upgrade( $item, array(
|
||||||
'clear_update_cache' => false,
|
'clear_update_cache' => false,
|
||||||
@ -1402,33 +1418,17 @@ class WP_Automatic_Upgrader {
|
|||||||
// Core doesn't output this, so lets append it so we don't get confused
|
// Core doesn't output this, so lets append it so we don't get confused
|
||||||
if ( 'core' == $type ) {
|
if ( 'core' == $type ) {
|
||||||
if ( is_wp_error( $upgrade_result ) ) {
|
if ( is_wp_error( $upgrade_result ) ) {
|
||||||
self::$skin->error( __( 'Installation Failed' ), $upgrade_result );
|
$skin->error( __( 'Installation Failed' ), $upgrade_result );
|
||||||
} else {
|
} else {
|
||||||
self::$skin->feedback( __( 'WordPress updated successfully' ) );
|
$skin->feedback( __( 'WordPress updated successfully' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear cache's and transients
|
self::$upgrade_results[ $type ][] = (object) array(
|
||||||
switch ( $type ) {
|
'item' => $item,
|
||||||
case 'core':
|
'result' => ! is_wp_error( $upgrade_result ) && $upgrade_result,
|
||||||
delete_site_transient( 'update_core' );
|
'name' => $item_name,
|
||||||
break;
|
'messages' => $skin->get_upgrade_messages()
|
||||||
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 )
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $upgrade_result;
|
return $upgrade_result;
|
||||||
@ -1476,17 +1476,100 @@ class WP_Automatic_Upgrader {
|
|||||||
// Finally, Process any core upgrade
|
// Finally, Process any core upgrade
|
||||||
wp_version_check(); // Check for Core updates
|
wp_version_check(); // Check for Core updates
|
||||||
$core_update = find_core_auto_update();
|
$core_update = find_core_auto_update();
|
||||||
if ( $core_update )
|
if ( $core_update ) {
|
||||||
self::upgrade( 'core', $core_update );
|
self::upgrade( 'core', $core_update );
|
||||||
|
delete_site_transient( 'update_core' );
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup, These won't trigger any updates this time due to the locking transient
|
// Cleanup, These won't trigger any updates this time due to the locking transient
|
||||||
wp_version_check(); // check for Core updates
|
wp_version_check(); // check for Core updates
|
||||||
wp_update_themes(); // Check for Theme updates
|
wp_update_themes(); // Check for Theme updates
|
||||||
wp_update_plugins(); // Check for Plugin updates
|
wp_update_plugins(); // Check for Plugin updates
|
||||||
|
|
||||||
|
self::send_email();
|
||||||
|
|
||||||
// Clear the lock
|
// Clear the lock
|
||||||
delete_site_option( $lock_name );
|
delete_site_option( $lock_name );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user