I'm pretty new to WordPress and I'm trying to customize my theme to send an email to myself when an upgrade is required. I'd rather not use a plugin as this means I have to install it for each WordPress site. The code below is based from the update notifier plugin.

add_action('check_updates_daily', 'check_updates');

function check_updates_daily() {
    if (!wp_next_scheduled('check_updates')) {
        wp_schedule_event(time(), 'daily', 'check_updates');

function check_updates() {

    $update_core = get_site_transient( 'update_core' );
    if (!empty($update_core) && isset($update_core->updates) && is_array($update_core->updates)
            && isset($update_core->updates[0]->response) && 'upgrade' == $update_core->updates[0]->response)
        $newversion = $update_core->updates[0]->current;
        $oldversion = $update_core->version_checked;
        $blogurl = esc_url( home_url() );
        $message = "It's time to update the version of WordPress running at $blogurl from version $oldversion to $newversion.\n\n";

        // don't let $wp_version mangling plugins mess this up
        if (!preg_match( '/^(\d+\.)?(\d+\.)?(\d+)$/', $oldversion)) {
            include( ABSPATH . WPINC . '/version.php' );
            $message = $wp_version == $newversion ? '' : "It's time to update the version of WordPress running at $blogurl from version $wp_version to $newversion.\n\n";

    //Send email
    if (!empty($message)) {     

        $subject = apply_filters( 'updatenotifier_subject', 'Updates are available for '.get_bloginfo('name').'.');

        wp_mail('email@email.com', $subject, $message);     

I did change it to check hourly to test if it worked but I didn't receive any emails I also scheduled it to just send an email without checking for updates and this also didn't work.

Any help appreciated, thanks =D

  • did you check your spam?
    – Ramkumar M
    Jul 7 '11 at 9:51
  • Are you testing on a local environment? By default local set-ups don't have the ability to send emails out so you wont get the email notification.
    – Scott
    Jul 7 '11 at 9:56
  • I'm testing on a hosted server and yes I checked my spam it doesn't appear to have sent at all. Thanks
    – Elliott
    Jul 7 '11 at 10:01

I forked the above plugin you mentioned as WP Updates Notifier

Maybe you want to look at that instead?

If you want to include it in your theme all you do is copy the plugin file and place in your theme functions file instead.

If you need further help modifying this plugin leave a comment and I'll see what I can do.

  • I did basically copy the plugin file and put it into the functions file, although I modified it to remove some of the settings etc. Does wordpress not check if the plugin is activated before it is used?
    – Elliott
    Jul 7 '11 at 10:02
  • yes you're right. In my plugin all that happens on plugin activation is to setup the cron. So you will need to use do_action("sc_wpun_enable_cron"); to setup the cron.
    – Scott
    Jul 7 '11 at 10:09
  • You can also use do_action("sc_wpun_update_check") to manually kick off an update check there and then so you dont have to wait for the cron to trigger.
    – Scott
    Jul 7 '11 at 10:11
  • I have just spent the last hour or so trying to get it working but with no luck. It works if I add updates[0]->response function outside the class (didn't add it all in comment) and then add the wp_email function. This sends me an email, but it doesnt work if its inside the class. I used do_action("sc_wpun_update_check") and added wp_email to the top of the class to email me but that didnt work either. Its like it isn't even calling the class? Thanks again.
    – Elliott
    Jul 7 '11 at 15:18

Whether you use an already available plugin or write your own plugin, you'll still need to install it on every WP site you set up. Don't waste time re-inventing the wheel, just use the plugin you already found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.