wppaste
WordPress

wp_schedule_single_event( int $timestamp, string $hook, array $args = array(), bool $wp_error = false ): bool|WP_Error

Since
2.1.0, 5.1.0, 5.7.0
Source
wp-includes/cron.php:48
Schedules an event to run only once.

Description

Schedules a hook which will be triggered by WordPress at the specified UTC time.
The action will trigger when someone visits your WordPress site if the scheduled time has passed.

Note that scheduling an event to occur within 10 minutes of an existing event with the same action hook will be ignored unless you pass unique $args values for each scheduled event.

Use wp_next_scheduled() to prevent duplicate events.

Use wp_schedule_event() to schedule a recurring event.

Compatibility

WordPress
since 5.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$timestampint
Unix timestamp (UTC) for when to next run the event.
$hookstring
Action hook to execute when the event is run.
$argsarrayoptional
Array containing arguments to pass to the hook's callback function. Each value in the array is passed to the callback as an individual parameter.
The array keys are ignored. Default empty array.
These arguments are used to uniquely identify the scheduled event and must match those used when the event was originally scheduled. If the arguments do not match exactly, WordPress will treat the event as different, which can lead to duplicate cron events being scheduled unintentionally, excessive growth of the 'cron' option, and database performance issues.Default: array()
$wp_errorbooloptional
Whether to return a WP_Error on failure. Default false.Default: false

Return value

bool|WP_Error
True if event successfully scheduled. False or WP_Error on failure.

Performance profile

How much work a call to wp_schedule_single_event() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
8–96

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 150.

Plugin surface
2 hooks

Third-party callbacks on 'pre_schedule_event', 'schedule_event' run inside this call, and their cost is not bounded by anything here.

Called by
15

15 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • serializeserialisationserialize()called directly
  • optionoption read or writeget_option()one call below wp_schedule_single_event()

Further down the call graph this can also reach cache, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 15 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_schedule_single_event() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8–10none
always15–17__()
$pre !== null && $pre !== false27apply_filters()
$pre !== null28–31apply_filters(), is_wp_error()
$pre !== null && $pre === false33apply_filters(), __(), hook()
$pre === null58–71apply_filters(), _get_cron_array(), serialize(), md5(), time(), time()
$pre === null60–73apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), time()
$pre === null64–77apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), apply_filters()
$pre === null65–78apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), __()
$pre === null66–79apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), time(), apply_filters()
$pre === null67–80apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), time(), __()
$pre === null71–84apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), apply_filters(), __()
3 further outcomes, up to 96 instructions
$pre === null73–86apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), time(), apply_filters(), __()
$pre === null81–94apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), apply_filters(), uksort(), _set_cron_array()
$pre === null83–96apply_filters(), _get_cron_array(), serialize(), md5(), time(), time(), time(), apply_filters(), uksort(), _set_cron_array()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1508–9619
8.51508–9619
8.41508–96192 fewer instructions than PHP 8.3
8.315210–9819
8.215210–9819
8.115210–9819
7.415210–9819

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while wp_schedule_single_event() runs, in this order:

  1. apply_filters( pre_schedule_event )filterline 100 (+52 into the body)

    Filter to override scheduling an event.

  2. apply_filters( schedule_event )filterline 188 (+140 into the body)

    Modify an event before it is scheduled.

Uses · 6

Used by · 15

Show all 15

Changelog

Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.7.0
The $wp_error parameter was added.from the docblock
5.1.0
Return value modified to boolean indicating success or failure, 'pre_schedule_event' filter added to short-circuit the function.from the docblock
2.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/cron.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.