0

我想创建一个 wordpress 插件,它在 X 分钟等特定分钟间隔内执行操作。查看 WP-API 有一种方法wp_schedule_event可以每小时、每天或每天两次安排操作。有没有办法在 WP 中真正安排事件,我可以定义事件应该运行的确切时间?

4

1 回答 1

1

尝试

wp_schedule_event('YOUR_LINUX_TIMESTAMP', 'daily', 'my_wp_cron_file' );  

YOUR_LINUX_TIMESTAMP 是time()

或查看全文:http ://codex.wordpress.org/Function_Reference/wp_schedule_event

唯一有效的值是“hourly”、“twicedaily”和“daily”

但:

打开cron.php并在“wp_includes/”文件夹中找到代码并找到:

function wp_get_schedules() {
    $schedules = array(
        'hourly'     => array( 'interval' => HOUR_IN_SECONDS,      'display' => __( 'Once Hourly' ) ),
        'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ),
            // YOU CODE PUT THERE // 
        'daily'      => array( 'interval' => DAY_IN_SECONDS,       'display' => __( 'Once Daily' ) ),
    );
    return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
}

添加:

'minutes'     => array( 'interval' => 60,      'display' => __( 'Once Minutes' ) ),

或每小时:

'hourly'     => array( 'interval' => 3600,      'display' => __( 'Once Hourly' ) ),

并将其更改为简单:

wp_schedule_event('YOUR_LINUX_TIMESTAMP', 'hourly', 'my_wp_cron_file' );   // as exmaple hourly cron is called
于 2013-03-08T13:10:00.053 回答