【问题标题】:Why would a scheduled cron show up in admin but not in wp-cron?为什么计划的 cron 会出现在 admin 中,但不会出现在 wp-cron 中?
【发布时间】:2017-09-25 23:16:27
【问题描述】:

我在 wordpress 中创建了一个新插件,它在激活时安排一个 cron。调度部分如下所示:

    $crons = _get_cron_array();
    //Use wp_next_scheduled to check if the event is already scheduled
    $timestamp = wp_next_scheduled('customers-hourly');

    if($timestamp == false) {
        //Schedule the event for right now, then to repeat daily using the hook 'wi_create_daily_backup'
        wp_schedule_event(time(), 'hourly', 'customers-hourly');
    }
    $crons = _get_cron_array();

    add_action('customers-hourly', [$this, 'hourlyCron']);

使用调试器单步执行代码时,激活代码后,_get_cron_array 包含以下内容:

$cron = [ // 12 elements
    [.. snip other crons ..]
    1493335692 => [
        'customers-hourly' => [
            'schedule' => 'hourly',
            'args' => [],
            'interval' => 3600,
        ],
    ],
    'version' => 2,
];

所以我的 cron 肯定在那里。 当我直接加载 cron.php 并调用 _get_cron_array() 时,它显示了 19 个元素,其中没有一个是客户每小时的。

知道是什么原因造成的吗?

【问题讨论】:

    标签: php wordpress cron


    【解决方案1】:

    我忽略的一个主要细节是我正在使用多站点。 cron 是在网络站点上创建的,而我正在从其中一个站点运行 cron。 从网络站点运行 cron 会显示我在 admin 中看到的所有 cron 并修复问题。

    最终结果:键盘和椅子之间存在问题。

    【讨论】:

      猜你喜欢
      • 2020-02-06
      • 2013-01-06
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多