wppaste
WordPress

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

Since
2.1.0, 5.1.0, 5.7.0
Source
wp-includes/cron.php:576
Unschedules all events attached to the hook with the specified arguments.

Description

Warning: This function may return boolean false, but may also return a non-boolean value which evaluates to false. For information about casting to booleans see the https://www.php.net/manual/en/language.types.boolean.php PHP documentation. Use the === operator for testing the return value of this function.

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

$hookstring
Action hook, the execution of which will be unscheduled.
$argsarrayoptional
Array containing each separate argument to pass to the hook's callback function.
Although not passed to a callback, these arguments are used to uniquely identify the event, so they must match those used when originally scheduling the event. If the arguments do not match exactly, the event will not be found. Default empty array.Default: array()
$wp_errorbooloptional
Whether to return a WP_Error on failure. Default false.Default: false

Return value

int|false|WP_Error
On success an integer indicating number of events unscheduled (0 indicates no events were registered with the hook and arguments combination), false or WP_Error if unscheduling one or more events fail.

Performance profile

How much work a call to wp_clear_scheduled_hook() 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
20–59

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

Plugin surface
1 hook

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

Called by
9

9 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_clear_scheduled_hook()

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 · 10 distinct outcomes

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

WhenInstructionsCalls it makes
is_array($args) && $pre !== null && $pre !== false20apply_filters()
is_array($args) && $pre === null && empty($crons)21apply_filters(), _get_cron_array()
is_array($args) && $pre !== null21–24apply_filters(), is_wp_error()
is_array($args) && $pre !== null && $pre === false26apply_filters(), __()
!is_array($args) && $pre !== null && $pre !== false31__(), _deprecated_argument(), apply_filters()
!is_array($args) && $pre === null && empty($crons)32__(), _deprecated_argument(), apply_filters(), _get_cron_array()
!is_array($args) && $pre !== null32–35__(), _deprecated_argument(), apply_filters(), is_wp_error()
!is_array($args) && $pre !== null && $pre === false37__(), _deprecated_argument(), apply_filters(), __()
is_array($args) && $pre === null && !empty($crons)41–48apply_filters(), _get_cron_array(), serialize(), md5(), array_filter()
!is_array($args) && $pre === null && !empty($crons)52–59__(), _deprecated_argument(), apply_filters(), _get_cron_array(), serialize(), md5(), array_filter()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 94 instructions, 20–59 executed per call, 12 branches. The work does not change between versions.

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 · 1

One hook fires while wp_clear_scheduled_hook() runs, in this order:

  1. apply_filters( pre_clear_scheduled_hook )filterline 610 (+34 into the body)

    Filter to override clearing a scheduled hook.

Uses · 7

Used by · 9

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 indicate success or failure, 'pre_clear_scheduled_hook' 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.