【问题标题】:Run function in to the wordpress plugin with real Cron job使用真正的 Cron 作业在 wordpress 插件中运行函数
【发布时间】:2015-03-10 11:04:08
【问题描述】:

我写wordpress插件..那个插件有功能(以下代码)..

我想用真正的 Cron 作业而不是 Wp 玉米来运行功能

首先我使用以下代码停用 wordpress cron

define('DISABLE_WP_CRON', true);

然后将以下代码添加到我的主机 cron

wget -q -O - http://kharidsanj.ir/wp-cron.php?doing_wp_cron >/dev/null 2>&1

现在我想用真正的 Cron 作业命令运行以下函数

function import_into_db(){

////My code

}

我该怎么办?

【问题讨论】:

    标签: php wordpress cron


    【解决方案1】:

    如果您在主机 cron 上运行 wp-cron.php,请使用以下代码。它对我有用。

    add_filter('cron_schedules','cliv_cron_add_syncdays');
    function cliv_cron_add_syncdays($schedules){
       $schedules['syncdays'] = array(
           'interval' => (86400),
           'display'=> 'Sync Days'
       );
       return $schedules;
    }
    
    add_action('init','cliv_create_recurring_schedule');
    add_action('cron_action','cron_function');
    
    function cron_function(){
       import_into_db(); // your desired function
    }
    
    function cliv_create_recurring_schedule(){
      if(!wp_next_scheduled('cron_action'))
       wp_schedule_event (time(), 'syncdays', 'cron_action');
    }
    

    【讨论】:

    • 这些功能在工作时是否会在现场击中用户,自动工作? @Pokhrel Kiran
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 2021-09-11
    • 2023-04-02
    • 2015-07-01
    相关资源
    最近更新 更多