返回介绍

wp_unschedule_event()

发布于 2017-09-11 13:01:46 字数 2814 浏览 2412 评论 0 收藏 0

wp_unschedule_event( int $timestamp,  string $hook,  array $args = array() )

Unschedule a previously scheduled event.


description

The $timestamp and $hook parameters are required so that the event can be identified.


参数

$timestamp

(int) (Required) Unix timestamp (UTC) for when to run the event.

$hook

(string) (Required) Action hook, the execution of which will be unscheduled.

$args

(array) (Optional) 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.

Default value: array()


返回值

(false|void) False if the event does not get unscheduled.


源代码

File: wp-includes/cron.php

function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
	// Make sure timestamp is a positive integer
	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
		return false;
	}

	$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 );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/cron.php: _get_cron_array()
  • wp-includes/cron.php: _set_cron_array()

Used By

  • wp-includes/cron.php: wp_clear_scheduled_hook()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    
    // Get the timestamp for the next event.
    $timestamp = wp_next_scheduled( 'my_schedule_hook' );
    
    // If this event was created with any special arguments, you need to get those too.
    $original_args = array();
    
    wp_unschedule_event( $timestamp, 'my_schedule_hook', $original_args );
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文