Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.