WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Difference between revisions of "Function Reference/wp schedule event"

(Using Parameter template)
Line 8: Line 8:
   
 
== Parameters ==
 
== Parameters ==
+
{{Parameter|$timestamp|integer|The first time that you want the event to occur. This must be in a UNIX timestamp format.}}
; timestamp: The first time you want the event to occur (unix timestamp)
+
{{Parameter|$recurrance|string|How often the event should reoccur. Valid values:<ul><li><tt>hourly</tt></li><li><tt>daily</tt></li></ul>}}
+
{{Parameter|$hook|string|The name of an action hook to execute.}}
; recurrance: How often you want the event to recurr, either 'hourly' or 'daily'
+
{{Parameter|$args|array|Arguments to pass to the hook function(s).|optional}}
 
; hook: Name of action hook to fire (string) (you need to define an action for the hook)
 
 
; args: Arguments to pass into the hook function(s) (array)
 
   
 
== Examples ==
 
== Examples ==

Revision as of 02:29, 13 January 2008

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.

Usage

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

Parameters

$timestamp
(integer) (required) The first time that you want the event to occur. This must be in a UNIX timestamp format.
Default: None
$recurrance
(string) (required) How often the event should reoccur. Valid values:
  • hourly
  • daily
Default: None
$hook
(string) (required) The name of an action hook to execute.
Default: None
$args
(array) (optional) Arguments to pass to the hook function(s).
Default: None

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
}