【发布时间】: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()函数来查看变量并查看后台实际发生的情况。