我知道这个答案现在可能对你没有帮助,因为为时已晚:)但这里有一个完整的例子,为即将遇到相同问题的开发人员提供了一个插件中的cronjob工作;
////////////////////////////////////////////
/* CRON Work STARTS HERE */
/////////////////////////////////////////////
function sh_booking_cronstarter_activation() {
if( !wp_next_scheduled( \'sh_booking_cronjob_hourly\' ) ) {
wp_schedule_event( time(), \'hourly\', \'sh_booking_cronjob_hourly\' ,array());
}
if( !wp_next_scheduled( \'sh_booking_cronjob_daily\' ) ) {
wp_schedule_event( time(), \'twicedaily\', \'sh_booking_cronjob_daily\' ,array());
}
}
register_activation_hook (__FILE__, \'sh_booking_cronstarter_activation\');
function sh_booking_cronstarter_deactivate() {
$timestamp = wp_next_scheduled (\'sh_booking_cronjob_hourly\');
wp_unschedule_event ($timestamp, \'sh_booking_cronjob_hourly\',array());
$timestampp = wp_next_scheduled (\'sh_booking_cronjob_daily\');
wp_unschedule_event ($timestampp, \'sh_booking_cronjob_daily\',array());
}
register_deactivation_hook (__FILE__, \'sh_booking_cronstarter_deactivate\');
add_action (\'sh_booking_cronjob_hourly\', \'cron_sh_booking_cronjob_hourly_6cc9234b\',10,0);
add_action (\'sh_booking_cronjob_daily\', \'cron_sh_booking_cronjob_daily_6cc9234b\',10,0);
function cron_sh_booking_cronjob_hourly_6cc9234b(){
/* your logic goes here ;) */
}
function cron_sh_booking_cronjob_daily_6cc9234b(){
/* your logic goes here ;) */
}
有帮助的跳跃;)