本文整理汇总了PHP中Events::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Events::instance方法的具体用法?PHP Events::instance怎么用?PHP Events::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Events
的用法示例。
在下文中一共展示了Events::instance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run_event
/**
* Execute a specific event
*/
public function run_event($request)
{
// Parse request for details needed to identify the event to execute
// `$timestamp` is, unsurprisingly, the Unix timestamp the event is scheduled for
// `$action` is the md5 hash of the action used when the event is registered
// `$instance` is the md5 hash of the event's arguments array, which Core uses to index the `cron` option
$event = $request->get_json_params();
$timestamp = isset($event['timestamp']) ? absint($event['timestamp']) : null;
$action = isset($event['action']) ? trim(sanitize_text_field($event['action'])) : null;
$instance = isset($event['instance']) ? trim(sanitize_text_field($event['instance'])) : null;
return rest_ensure_response(Events::instance()->run_event($timestamp, $action, $instance));
}
示例2: time
}
// Now we try to get it from the saved interval, in case the schedule disappears
if (0 == $interval) {
$interval = $event['interval'];
}
// If we have an interval, update the existing event entry
if (0 != $interval) {
// Determine new timestamp, according to how `wp_reschedule_event()` does
$now = time();
$new_timestamp = $event['timestamp'];
if ($new_timestamp >= $now) {
$new_timestamp = $now + $interval;
} else {
$new_timestamp = $now + ($interval - ($now - $new_timestamp) % $interval);
}
// Build the expected arguments format
$event_args = array('schedule' => $event['schedule'], 'args' => $event['args'], 'interval' => $interval);
// Update CPT store
Cron_Options_CPT::instance()->create_or_update_job($new_timestamp, $event['action'], $event_args, $job_id);
// If the event could be rescheduled, don't then delete it :)
if (is_int($job_id) && $job_id > 0) {
return;
}
}
}
// Either event doesn't recur, or the interval couldn't be determined
Cron_Options_CPT::instance()->mark_job_completed($event['timestamp'], $event['action'], $event['instance']);
}
}
Events::instance();