WordPress: Function Reference/wp schedule event:修订间差异
来自站长百科
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
== 描述== | == 描述== | ||
确定WordPress actions core 在你规定的特别的时间间隔内执行hook的时间。如果预定的时间已经过去,有人访问你的站点的时候,action就会引发。请看看[[WordPress:Plugin API|插件API]]上的hooks列表。 | 确定WordPress actions core 在你规定的特别的时间间隔内执行hook的时间。如果预定的时间已经过去,有人访问你的站点的时候,action就会引发。请看看[[WordPress:Plugin API|插件API]]上的hooks列表。 | ||
== 用法 == | == 用法 == | ||
第13行: | 第7行: | ||
%%% <?php wp_schedule_event(time(), 'hourly', 'my_schedule_hook'); ?> %%% | %%% <?php wp_schedule_event(time(), 'hourly', 'my_schedule_hook'); ?> %%% | ||
== 参数 == | == 参数 == | ||
{{Parameter|$timestamp|integer|你想要操作首次发生的时间。必须是UNIX 时间格式。}} | {{Parameter|$timestamp|integer|你想要操作首次发生的时间。必须是UNIX 时间格式。}} | ||
{{Parameter|$recurrance|string|操作应该什么时候再次发生。有效的参数值: <ul><li><tt>hourly</tt></li><li><tt>daily</tt></li></ul>}} | {{Parameter|$recurrance|string|操作应该什么时候再次发生。有效的参数值: <ul><li><tt>hourly</tt></li><li><tt>daily</tt></li></ul>}} | ||
{{Parameter|$hook|string|将要执行的action hook的名称。}} | {{Parameter|$hook|string|将要执行的action hook的名称。}} | ||
{{Parameter|$args|array|将要传递给hook函数的参数。|optional}} | {{Parameter|$args|array|将要传递给hook函数的参数。|optional}} | ||
== 例子 == | == 例子 == | ||
=== 规定每隔一小时的操作 === | === 规定每隔一小时的操作 === | ||
在插件中规定每隔一小时的操作,调用激活的<tt>wp_schedule_event</tt>(否则,你需要结束许多预定的操作!) | 在插件中规定每隔一小时的操作,调用激活的<tt>wp_schedule_event</tt>(否则,你需要结束许多预定的操作!) | ||
<pre> | <pre> | ||
register_activation_hook(__FILE__, 'my_activation'); | register_activation_hook(__FILE__, 'my_activation'); | ||
第69行: | 第31行: | ||
} | } | ||
</pre> | </pre> | ||
== 深入阅读== | == 深入阅读== | ||
关于完整的函数的列表,请看看[http://codex.wordpress.org/类别:函数类别函数] | 关于完整的函数的列表,请看看[http://codex.wordpress.org/类别:函数类别函数] | ||
也看看[[WordPress:Function_Reference|Function_Reference]] | 也看看[[WordPress:Function_Reference|Function_Reference]] |
2008年7月29日 (二) 15:08的最新版本
描述[ ]
确定WordPress actions core 在你规定的特别的时间间隔内执行hook的时间。如果预定的时间已经过去,有人访问你的站点的时候,action就会引发。请看看插件API上的hooks列表。
用法[ ]
%%% <?php wp_schedule_event(time(), 'hourly', 'my_schedule_hook'); ?> %%%
参数[ ]
例子[ ]
规定每隔一小时的操作[ ]
在插件中规定每隔一小时的操作,调用激活的wp_schedule_event(否则,你需要结束许多预定的操作!)
register_activation_hook(__FILE__, 'my_activation'); add_action('my_hourly_event', 'do_this_hourly'); function my_activation() { wp_schedule_event(time(), 'hourly', 'my_hourly_event'); } function do_this_hourly() { // do something every hour }
深入阅读[ ]
关于完整的函数的列表,请看看[1]