wp_schedule_single_event()
wp_schedule_single_event( int $timestamp, string $hook,…
wp_schedule_single_event( int $timestamp, string $hook, array $args = array() )
安排事件只运行一次。
Schedules an event to run only once.
目录锚点:#说明#参数#源码#笔记
说明(Description)
计划在指定时间由WordPress触发的钩子。当有人访问你的WordPress站点时,如果已经过了预定的时间,该操作将被触发。请注意,除非为每个计划的事件传递唯一的$args值,否则将忽略将事件安排在具有相同操作钩子的现有事件10分钟内发生。使用wp_next_scheduled()可防止重复事件。使用wp_schedule_event()来计划定期事件。
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$timestamp | (int) | 下次运行事件的时间戳(UTC)。 |
$hook | (string) | 要在事件运行时执行的操作钩子。 |
$args | (array) | 数组,包含要传递给钩子的回调函数的每个独立参数。 |
源码(Source)
/** * Schedules a hook to run only once. * * Schedules a hook which will be executed once by the WordPress actions core at * a time which you specify. The action will fire off when someone visits your * WordPress site, if the schedule time has passed. * * @since 2.1.0 * @link https://codex.wordpress.org/Function_Reference/wp_schedule_single_event * * @param int $timestamp Timestamp for when to run the event. * @param string $hook Action hook to execute when cron is run. * @param array $args Optional. Arguments to pass to the hook's callback function. * @return void|false */ function wp_schedule_single_event( $timestamp, $hook, $args = array()) { // don't schedule a duplicate if there's already an identical event due within 10 minutes of it $next = wp_next_scheduled($hook, $args); if ( $next && abs( $next - $timestamp ) <= 10="" *="" minute_in_seconds="" )="" {="" return;="" }="" $crons="_get_cron_array();" $event="(object)" array(="" 'hook'=""> $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args ); /** * Filter a single event before it is scheduled. * * @since 3.1.0 * * @param object $event An object containing an event's data. */ $event = apply_filters( 'schedule_event', $event ); // A plugin disallowed this event if ( ! $event ) return false; $key = md5(serialize($event->args)); $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); uksort( $crons, "strnatcasecmp" ); _set_cron_array( $crons ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
5.1.0 | wp-includes/cron.php | 13 | 19 |
笔记(Notes)
安排一小时后的活动
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!