wp_unschedule_event()注销一个以前预约的定时事件

目录

描述

Unschedules a previously-scheduled cron job.

Note that you need to know the exact time of the next occurrence when scheduled hook was set to run, and the function arguments it was supposed to have, in order to unschedule it. All future occurrences are unscheduled by calling this function.

wp_unschedule_event() 描述

用法

 <?php wp_unschedule_event$timestamp$hook$args ); ?> 

wp_unschedule_event() 用法

参数

$timestamp

(integer) (必填) Timestamp of the next occurrence for the scheduled hook to run. wp_next_scheduled() may be useful.

默认值: None

$hook

(string) (必填) Action hook originally provided, the execution of which will be unscheduled.

默认值: None

$args

(array) (可选) Arguments to pass to the hook's callback function. These arguments are used to uniquely identify the scheduled event, so they must be the same as those used when originally scheduling the event.

默认值: array()

wp_unschedule_event() 参数

历史

添加于 版本: 2.1.0

wp_unschedule_event() 历史

源文件

wp_unschedule_event() 函数的代码位于 wp-includes/cron.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Unschedule a previously scheduled cron job.
 *
 * The $timestamp and $hook parameters are required, so that the event can be
 * identified.
 *
 * @since 2.1.0
 *
 * @param int $timestamp Timestamp for when to run the event.
 * @param string $hook Action hook, the execution of which will be unscheduled.
 * @param array $args Arguments to pass to the hook's callback function.
 * Although not passed to a callback function, these arguments are used
 * to uniquely identify the scheduled event, so they should be the same
 * as those used when originally scheduling the event.
 */
function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
	$crons = _get_cron_array();
	$key = md5(serialize($args));
	unset( $crons[$timestamp][$hook][$key] );
	if ( empty($crons[$timestamp][$hook]) )
		unset( $crons[$timestamp][$hook] );
	if ( empty($crons[$timestamp]) )
		unset( $crons[$timestamp] );
	_set_cron_array( $crons );
}

wp_unschedule_event() 源文件

相关