【问题标题】:wp_schedule_event not firingwp_schedule_event 未触发
【发布时间】:2020-07-28 15:04:03
【问题描述】:

我正在尝试在主题的functions.php 中安排一个活动,但我无法让它“触发”。我正在使用 Cron View 插件,它显示了正确安排的事件,但什么时候执行都没有发生。

这是我的代码

if ( ! wp_next_scheduled( 'prefix_hourly_event' ) ) {
    wp_schedule_event( time(), 'hourly', 'prefixhourlyevent');       
}
add_action( 'prefixhourlyevent', 'prefix_do_this_hourly' );

function prefix_do_this_hourly() {                
    wp_mail('myemail@gmail.com','Cron is working', 'Cron is working: ','','');
}

【问题讨论】:

  • 看来问题来自服务器配置 - 我发现以下错误日志 [Tue Nov 05 08:07:04 2013] [error] [client 174.123.61.234] client denied by server configuration :/home/xxxx/public_html/original/wp-cron.php。试图解决这个问题。
  • 这实际上对我帮助很大。通过检查我的日志,我能够找到问题所在。谢谢你的帮助:)
  • 每当我使用 wp_schedule_event 时,我经常使用trigger_error() 函数来查看变量并查看后台实际发生的情况。

标签: php wordpress


【解决方案1】:

您可以转到http://www.example.com/wp-cron.php?doing_cron 手动运行 WordPress cron 作业。在这里您可以看到脚本创建的任何错误,这在调试 wp 计划任务时非常有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多