Email When Plugin or Theme Updates Are Available
Checks once a day for plugin, theme and WordPress updates and emails the admin a list when there is something new to install, so outdated software does not linger.
Opens WPIDE on
Code
add_action( 'init', function () {
if ( ! wp_next_scheduled( 'wpide_updates_alert' ) ) {
wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'wpide_updates_alert' );
}
} );
add_action( 'wpide_updates_alert', function () {
$lines = array();
$plugins = get_site_transient( 'update_plugins' );
$themes = get_site_transient( 'update_themes' );
$core = get_site_transient( 'update_core' );
if ( ! empty( $plugins->response ) ) {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$installed = get_plugins();
foreach ( $plugins->response as $file => $data ) {
$name = isset( $installed[ $file ]['Name'] ) ? $installed[ $file ]['Name'] : $file;
$lines[] = sprintf( 'Plugin: %s → %s', $name, $data->new_version );
}
}
if ( ! empty( $themes->response ) ) {
foreach ( $themes->response as $slug => $data ) {
$lines[] = sprintf( 'Theme: %s → %s', $slug, $data['new_version'] );
}
}
if ( ! empty( $core->updates[0] ) && 'upgrade' === $core->updates[0]->response ) {
$lines[] = 'WordPress → ' . $core->updates[0]->current;
}
$hash = md5( implode( '|', $lines ) );
if ( ! $lines || get_option( 'wpide_updates_alert_hash' ) === $hash ) {
return;
}
update_option( 'wpide_updates_alert_hash', $hash, false );
wp_mail( get_option( 'admin_email' ), sprintf( '[%s] %d update(s) available', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), count( $lines ) ), "These updates are ready to install:\n\n" . implode( "\n", $lines ) . "\n\nUpdate now: " . admin_url( 'update-core.php' ) );
} );
Notes
Only emails when the list of available updates changes, so you are not reminded daily about the same ones.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.