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 single event"

m (Schedule an event one hour from now)
(Using Parameter template)
Line 28: Line 28:
   
 
== Parameters ==
 
== Parameters ==
+
{{Parameter|$timestamp|integer|The time you want the event to occur. This must be in a UNIX timestamp format.}}
; timestamp: The time you want the event to occur (unix timestamp)
+
{{Parameter|$hook|string|The name of an action hook to execute.}}
+
{{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, optional)
 
 
   
 
[[Category:Functions]]
 
[[Category:Functions]]
[[Category:New page created]]
 
 
[[Category:WP-Cron Functions]]
 
[[Category:WP-Cron Functions]]

Revision as of 02:20, 13 January 2008

Description

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.

Usage

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

Examples

Schedule an event one hour from now

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.

Parameters

$timestamp
(integer) (required) The time you want the event to occur. This must be in a UNIX timestamp format.
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