Wordpress cronjob每3分钟一次

彼得

关于这个话题有很多关于stackoverflow的文章,但是(我不知道为什么)对我来说什么都行不通。

是)我有的

function isa_add_every_three_minutes( $schedules ) {

    $schedules['every_three_minutes'] = array(
            'interval'  => 180,
            'display'   => __( 'Every 3 Minutes', 'textdomain' )
    );

    return $schedules;
}
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );


function every_three_minutes_event_func() 
{
    // do something
}

wp_schedule_event( time(), 'every_three_minutes', 'every_three_minutes_event_func' );

任何想法我在做什么错?

西瓦姆·马图尔(Shivam Mathur)

您需要使用add_action()来将函数挂钩到预定事件。

add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' );

这是完整的代码。

// Add a new interval of 180 seconds
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );
function isa_add_every_three_minutes( $schedules ) {
    $schedules['every_three_minutes'] = array(
            'interval'  => 180,
            'display'   => __( 'Every 3 Minutes', 'textdomain' )
    );
    return $schedules;
}

// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'isa_add_every_three_minutes' ) ) {
    wp_schedule_event( time(), 'every_three_minutes', 'isa_add_every_three_minutes' );
}

// Hook into that action that'll fire every three minutes
add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' );
function every_three_minutes_event_func() {
    // do something
}
?>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章