我是WordPress的新手,我正在尝试自定义我的主题,以便在需要升级时向自己发送电子邮件。我不想使用插件,因为这意味着我必须为每个WordPress站点安装插件。下面的代码基于update notifier 插件。
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);
}
}
我确实将它改为每小时检查一次,以测试它是否有效,但我没有收到任何电子邮件,我还计划只发送一封电子邮件,而不检查更新,但这也不起作用。
感谢您的帮助,谢谢