使用指定的参数取消计划附加到挂钩的所有事件。

原型

wp_clear_scheduled_hook( string $hook, array $args = array() )

参数

$hook (string) (Required) 动作钩子,其执行将被取消预定。

$args (array) (Optional)  要传递给hook的回调函数的参数。

源文件

路径:wp-includes/cron.php

<?php
...
function wp_clear_scheduled_hook( $hook, $args = array() ) {
	// Backward compatibility
	// Previously this function took the arguments as discrete vars rather than an array like the rest of the API
	if ( !is_array($args) ) {
		_deprecated_argument( __FUNCTION__, '3.0.0', __('This argument has changed to an array to match the behavior of the other cron functions.') );
		$args = array_slice( func_get_args(), 1 );
	}
	// This logic duplicates wp_next_scheduled()
	// It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing,
	// and, wp_next_scheduled() returns the same schedule in an infinite loop.
	$crons = _get_cron_array();
	if ( empty( $crons ) )
		return;
	$key = md5( serialize( $args ) );
	foreach ( $crons as $timestamp => $cron ) {
		if ( isset( $cron[ $hook ][ $key ] ) ) {
			wp_unschedule_event( $timestamp, $hook, $args );
		}
	}
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_clear_scheduled_hook/