Cron Job未出现在WP-Control插件的cron列表中

问题描述 投票:2回答:1

我正在尝试为所有客户设置Cron作业以更新其库存。我研究了Cron job in WordPress not workingcron 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;
}

我正在使用它只是为了测试我是否可以使它出现在列表中。我想念什么吗?谢谢

php wordpress woocommerce cron jobs
1个回答
1
投票

好,所以我明白了。完整代码:

//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。希望对您有所帮助!

编辑:如果您安装插件,则可以看到带有gui的cron作业,我有wp-control。可以在yourdomain/wp-admin/tools.php?page=crontrol_admin_manage_page处检查权杖>

© www.soinside.com 2019 - 2024. All rights reserved.