我希望插件的用户能够根据标准WP设置定义任务是每天运行、每天运行两次、每小时运行还是根本不运行。我将它们存储为“每日”、“两天”、“每小时”或“obr\\u scheduled\\u interval”选项。
问题是,我希望“obr\\u grab”的任务在每次页面访问时运行,而不是在选定的时间段之后每次页面访问时运行。
这些是类中的相关代码位。
function __construct(){
register_activation_hook(__FILE__, array(&$this, \'obr_activate_scheduled_task\'));
add_action(\'obr_scheduled_task\', array(&$this, \'obr_activate_scheduled_task\'));
add_shortcode(\'obr_grab\', array(&$this, \'obr_grab\'));
register_deactivation_hook(__FILE__, array(&$this, \'obr_deactivate_scheduled_task\'));
}
function obr_activate_scheduled_task() {
// function to activate the scheduled task (if there is one);
if (wp_next_scheduled(\'obr_scheduled_task\')){
wp_clear_scheduled_hook(\'obr_scheduled_task\');
}
$interval = get_option(\'obr_scheduled_interval\');
if (strlen($interval) > 0){
wp_schedule_event(time(), $interval, \'obr_scheduled_task\');
}
}
function obr_scheduled_task(){
// if called we need to use the grab function
$this->obr_grab();
}
function obr_deactivate_scheduled_task(){
// clear the schedule on deactivation
wp_clear_scheduled_hook(\'obr_scheduled_task\');
}
我已经看过了core control 但那里只有两个标准作业:wp\\u scheduled\\u auto\\u draft\\u delete和wp\\u scheduled\\u delete非常感谢大家的帮助!