我正在尝试为我的所有客户设置一个 cron 作业来更新他们的库存。我调查过Cron job in WordPress not working和 cron job in wordpress但无法让它出现在 cron 列表(WP-Control)中。
我正在使用这个:
add_action('plugins_loaded', 'cron_add_everyday');
add_filter( 'cron_schedules', 'cron_add_everyday' );
function cron_add_everyday( $schedules ) {
$schedules = array('everyday' => array( 'interval' => 86400*1,
'display' => __( 'Every Day')),);
return $schedules;
}
我用它只是为了测试是否可以让它出现在列表中。我错过了什么吗?谢谢
最佳答案
好的,我明白了。完整代码:
//CUSTOM TIMER 15 minuts, you can change for your won
function myprefix_custom_cron_schedule( $schedules ) {
$schedules['15Minuts'] = array(
'interval' => 900, // 15 minuts in secounds
'display' => __( '15 minuts' ),
);
return $schedules;
}
//ADD it
add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' );
//Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'Your_Function_Hook' ) ) {
wp_schedule_event( time(), '15Minuts', 'Your_Function_Hook' );
}
///Hook into that action that'll fire every 15 minuts
add_action( 'Your_Function_Hook', 'Your_Function' );
//create your function, that runs on the cron you just made
function Your_Function() {
echo 'Hi its 15 minuts';
}
这不是我做的,积分归https://wordpress.stackexchange.com/questions/179694/wp-schedule-event-every-day-at-specific-time 。希望它对某人有所帮助!
编辑:如果你安装了一个插件,你可以用图形用户界面看到你的 cron 作业,我有 wp-control。可以在 yourdomain/wp-admin/tools.php?page=crontrol_admin_manage_page
关于php - Cron 作业未出现在 WP-Control 插件的 cron 列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58300801/