小编Nic*_*ick的帖子

wp_schedule_event 挂钩已计划但未工作

我正在尝试从我正在编写的 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
}
Run Code Online (Sandbox Code Playgroud)

php wordpress cron cron-task

5
推荐指数
1
解决办法
3137
查看次数

标签 统计

cron ×1

cron-task ×1

php ×1

wordpress ×1