【发布时间】:2014-09-05 11:21:45
【问题描述】:
按一定间隔执行的方法
function informant_main_action(){
die('working');
}
Cron 作业的自定义计划
function my_cron_definer($schedules){
$schedules['weekly'] = array('interval'=> 120, //604800
'display'=> __('Once Every week')
);
return $schedules;
}
add_filter('cron_schedules','my_cron_definer');
注册插件激活时间表
register_activation_hook( __FILE__, 'informant_run_on_activation' );
function informant_run_on_activation(){
if(!wp_next_scheduled('informantweeklynewsletter')){
wp_schedule_event(time(), 'weekly', 'informantweeklynewsletter');
}
}
调用我的方法以在自定义事件上执行
add_action('informantweeklynewsletter','informant_main_action');
我已经安装了一个插件 Cron Gui 用于查看计划的 cronjob,它正确列出了我的事件,因为我每两分钟重复一次,cron gui 显示正确的结果,即更新时间 +2 分钟。
但是我的方法informant_main_action() 不起作用。我犯了什么错误。 ?
谢谢
【问题讨论】:
-
尝试使用邮件功能而不是死机......你永远无法确定你是否会成为触发 cron 的人......