【问题标题】:wp_schedule_event not workingwp_schedule_event 不工作
【发布时间】:2015-11-14 22:57:46
【问题描述】:

我正在制作一个程序,使用wp_schedule_event 在一个小时内检查和发送电子邮件,但它对我不起作用.. 有人知道我的情况吗?这是我的代码,我把它放在我的自定义插件myplugin-function.php

register_activation_hook(__FILE__, 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');

function my_activation() {
    wp_schedule_event(time(), 'hourly', 'my_hourly_event');
}

function do_this_hourly() {
    $headers = "From: webmaster <webmaster@test.com>\r\n";

    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    mail('mymail@test.com','Test','Hello',$headers);

}

register_deactivation_hook(__FILE__, 'my_deactivation');

function my_deactivation() {
    wp_clear_scheduled_hook('my_hourly_event');
}

【问题讨论】:

    标签: php wordpress scheduled-tasks


    【解决方案1】:

    由于您的代码似乎已从 WP 文档中删除,我认为这更像是配置问题而不是代码问题。

    也许这些步骤可以帮助你:

    1. 检查您的wp-config.php 文件中的WP_DEBUG 是否设置为true

    2. 检查DISABLE_WP_CRON 不存在,或者至少没有在您的wp-config.php 文件中设置为true

    3. 尝试检查您的活动是否安排在$schedule = wp_get_schedule( 'my_hourly_event' );,然后转储schedule

    4. 如果您可以访问您的服务器日志,请查看wp_cron.php 文件是否有错误

    5. 查看ALTERNATE_WP_CRON 选项文档,它可能会对您有所帮助,但我不太喜欢这种解决方案

    我知道我没有给你任何答案,但我们没有很多信息(因为你没有)。

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      • 2013-11-14
      • 1970-01-01
      • 2020-02-23
      相关资源
      最近更新 更多