【发布时间】:2015-08-30 15:37:15
【问题描述】:
我正在尝试从我正在编写的 WordPress 插件中触发 cron 作业(它将每天获取所有新产品并将它们导出到 CSV)所以问题是当我将此代码放入 functions.php 时一切都很好,代码是有效的,但是从插件文件夹中它被安排了,我可以看到它(使用 Cron View 插件)但没有执行..我发现了另一个相同的问题,但没有答案.. 似乎它并没有真正被触发或有什么东西阻止了它.. 看看我的代码..
function csv_init(){
add_action('my_hourly_event', 'Download_CSV_with_args');
}
function starthere(){
// some code here
$file = $_SERVER['DOCUMENT_ROOT'].'/wp-content/csv_settings.php';
$content = serialize($args);
file_put_contents($file, $content);
wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event');
$schedule = wp_get_schedule( 'my_hourly_event' );
echo wp_next_scheduled( 'my_hourly_event' ).'<br>';
if ($schedule){
echo '<h3>The "'.$schedule.'" Cron Job is running..</h3>';
}else {
echo '<h3>There are no Cron Jobs that running..</h3>';
}
}
function Download_CSV_with_args() {
//execution of my code
}
【问题讨论】:
标签: php wordpress cron cron-task