【问题标题】:WordPress wp_schedule_event not triggeringWordPress wp_schedule_event 未触发
【发布时间】:2013-07-19 19:27:13
【问题描述】:

我正在尝试创建一个每五分钟查找一次触发器的调度程序。

当我初始化插件时,我得到一个初始响应,但我没有像我试图完成的那样每五分钟触发一次。这是我的代码:

add_filter('cron_schedules', 'add_scheduled_interval');

function add_scheduled_interval($schedules) {
    $schedules['minutes_5'] = array('interval'=>300, 'display'=>'Once 5 minutes');
    return $schedules;
    global $schedules;
  }
if (!wp_next_scheduled('sms_cron')) {
    wp_schedule_event(time(), 'minutes_5', 'sms_cron');
    }

add_action('sms_cron', 'send_text_alerts');

function send_text_alerts() {
    //My function
    }

我的问题是,我错过了什么?有什么明显的跳出来吗?提前致谢!

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您需要将以下内容添加到操作中:

    if (!wp_next_scheduled('sms_cron')) {
    wp_schedule_event(time(), 'minutes_5', 'sms_cron');
    }
    

    所以是这样的:

    add_action( 'wp', 'setup_schedule' );
    function setup_schedule() {
    if (!wp_next_scheduled('sms_cron')) {
    wp_schedule_event(time(), 'minutes_5', 'sms_cron');
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2014-11-26
      • 2017-01-24
      • 2013-11-14
      • 2021-07-30
      相关资源
      最近更新 更多