【问题标题】:Cron Job not appearing in the cron list of WP-Control pluginCron Job 未出现在 WP-Control 插件的 cron 列表中
【发布时间】:2020-02-06 14:14:53
【问题描述】:

我正在尝试为我的所有客户设置一个 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;
}

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

【问题讨论】:

  • 我非常怀疑plugins_loaded 操作会以$schedules 的任何合理值调用您的函数……
  • 它适用于其他操作,但我将其更改为 'wp' 仍然无法正常工作

标签: php wordpress woocommerce cron jobs


【解决方案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查看crons

【讨论】:

  • 我是 Wordpress 开发的新手。 'Your_Function_Hook' 应该是 Worpress 上已经存在的钩子,例如 'admin_menu' 或类似的东西?还是在这种情况下我要创建一个钩子?我的意思是,什么会触发日程安排?
猜你喜欢
  • 2017-01-04
  • 2017-09-25
  • 2015-07-01
  • 2019-09-27
  • 2015-10-22
  • 1970-01-01
  • 2017-06-14
  • 2015-09-12
  • 1970-01-01
相关资源
最近更新 更多