WordPress:Function Reference/wp schedule event

来自站长百科
Xxf3325讨论 | 贡献2008年7月19日 (六) 15:32的版本 (新页面: == Description == Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPre...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

Description

Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed. See the WordPress:Plugin API for a list of hooks.

Usage

%%% <?php wp_schedule_event(time(), 'hourly', 'my_schedule_hook'); ?> %%%

Parameters

Examples

Schedule an hourly event

To schedule an hourly event in a plugin, call wp_schedule_event on activation (otherwise you will end up with a lot of scheduled events!):

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
}

Further Reading

For a comprehensive list of functions, take a look at the category Functions

Also, see WordPress:Function_Reference