Skip to content

Commit

Permalink
Merge pull request #1 from helloarpitgshah/50448-auto-update-failure-…
Browse files Browse the repository at this point in the history
…emails

50448-auto-update-failure-emails
  • Loading branch information
helloarpitgshah committed Jul 1, 2020
2 parents b2cc1df + 37656cb commit 27eca3d
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion src/wp-admin/includes/class-wp-automatic-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -1011,26 +1011,99 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
$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";


// Check for failed themes and plugins listing with failed_update_plugins_themes option_name
$failed_update_plugins_themes = (array) get_site_option( 'failed_update_plugins_themes', array() );

// List failed plugin updates.
if ( ! empty( $failed_updates['plugin'] ) ) {
$body[] = __( 'These plugins failed to update:' );

foreach ( $failed_updates['plugin'] as $item ) {
$body[] = "- {$item->name}";

/*
* Failed Plugin list to store into the database
*/
$failed_plugin = array( 'name' => $item->name, 'failure_time' => time(), 'file_name' => $item->item->plugin );
if( isset( $failed_update_plugins_themes['plugin'] ) && !empty( $failed_update_plugins_themes['plugin'] ) ){
if( array_search($item->item->plugin, array_column($failed_update_plugins_themes['plugin'], 'file_name')) === false ) {
$failed_update_plugins_themes['plugin'][] = $failed_plugin;
}
}else{
$failed_update_plugins_themes['plugin'][] = $failed_plugin;
}

}
$body[] = "\n";
}


/*
* Check for 3 days passed or not
*/
if( isset( $failed_update_plugins_themes['plugin'] ) && !empty( $failed_update_plugins_themes['plugin'] ) ){
foreach( $failed_update_plugins_themes['plugin'] as $key => $failed_plugin ){
if( isset( $failed_plugin ) && !empty( $failed_plugin['failure_time'] ) ){
$current_time = time();
$lastcheck = $failed_plugin['failure_time'];
$datediff = $current_time - $lastcheck;

$days_check = round($datediff / (60 * 60 * 24));
if( $days_check >= 3 ){
unset($failed_update_plugins_themes['plugin'][$key]);
$body[] = $failed_plugin['name'];
}
}
}
}

// List failed theme updates.
if ( ! empty( $failed_updates['theme'] ) ) {
$body[] = __( 'These themes failed to update:' );

foreach ( $failed_updates['theme'] as $item ) {
$body[] = "- {$item->name}";

/*
* Failed Plugin list store in database
*/
$failed_theme = array( 'name' => $item->name, 'failure_time' => time(), 'file_name' => $item->item->theme );
if( isset( $failed_update_plugins_themes['plugin'] ) && !empty( $failed_update_plugins_themes['theme'] ) ){
if( array_search($item->item->theme, array_column($failed_update_plugins_themes['theme'], 'file_name')) === false ) {
$failed_update_plugins_themes['theme'][] = $failed_theme;
}
}else{
$failed_update_plugins_themes['theme'][] = $failed_theme;
}

}
$body[] = "\n";
}

/*
* Check for 3 days passed or not
*/
if( isset( $failed_update_plugins_themes['theme'] ) && !empty( $failed_update_plugins_themes['theme'] ) ){
$body[] = "\n";
foreach( $failed_update_plugins_themes['theme'] as $key => $failed_theme ){

if( isset( $failed_theme ) && !empty( $failed_theme['failure_time'] ) ){

$current_time = time();
$lastcheck = $failed_theme['failure_time'];
$datediff = $current_time - $lastcheck;

$days_check = round($datediff / (60 * 60 * 24));
if( $days_check >= 3 ){
unset($failed_update_plugins_themes['theme'][$key]);
$body[] = $failed_theme['name'];
}

}
}
}
update_site_option( 'failed_update_plugins_themes', $failed_update_plugins_themes );
}

// List successful updates.
Expand Down

0 comments on commit 27eca3d

Please sign in to comment.