I'm pretty new to WordPress and i'm trying to customise my theme to send an email to myself when a 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 recieve any emails I also secheduled it to just send an email without checking for updates and this also didn't work.
Any help appreciated, thanks =D