我编写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
}
我该怎么办?
如果您在主机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');
}