常用函数-wp_schedule_single_event()

0条评论

说明

计划某个钩子(hook)的使用时间,用户指定时间后,WordPress动作(action)函数执行一次该钩子。预定时间过去后,如果有人访问用户的WordPress网站,动作函数会停止运行。

用法

<?php wp_schedule_single_event(time(), 'my_schedule_hook'); ?> 

注意,假设有两个同名事件,如果在一个事件发生后十分钟内计划另一个事件的时间,该次计划会被忽略。

示例

计划某个事件在从现在开始一个小时后发生:

function do_this_in_an_hour() {
// do something
}
add_action('my_new_event','do_this_in_an_hour');

// put this line inside a function, 
// presumably in response to something the user does
// otherwise it will schedule a new event on every page visit

wp_schedule_single_event(time()+3600, 'my_new_event');

// time()+3600 = one hour from now.

参数

$timestamp

(整数)(必需)希望时间发生的时间,时间格式必须为UNIX时间标记格式

默认值:None

$hook

(字符串)(必需)需要被执行的动作钩子的名称

默认值:false

$args

(数组)(可选)传递给钩子函数的参数

默认值:None

延伸阅读

其它定时进程函数请见 WP-Cron functions

完整WordPress函数列表请见常用函数

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.