admin管理员组文章数量:1433530
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 protected]', $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
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 protected]', $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
Share Improve this question edited Apr 9, 2019 at 13:19 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Jul 7, 2011 at 9:40 ElliottElliott 5426 silver badges15 bronze badges 3- did you check your spam? – Ramkumar M Commented Jul 7, 2011 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 Commented Jul 7, 2011 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 Commented Jul 7, 2011 at 10:01
2 Answers
Reset to default 0I 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.
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.
本文标签: updatesEmail user on WordPress upgrade
版权声明:本文标题:updates - Email user on WordPress upgrade 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745610395a2666079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论