返回介绍

wp_clear_scheduled_hook()

发布于 2017-09-11 11:42:30 字数 3145 浏览 948 评论 0 收藏 0

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

Unschedule all events attached to the specified hook.


description


参数

$hook

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

$args

(array) (Optional) Arguments that were to be passed to the hook's callback function.

Default value: array()


源代码

File: wp-includes/cron.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 );
		}
	}
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/cron.php: _get_cron_array()
  • wp-includes/cron.php: wp_unschedule_event()
  • wp-includes/l10n.php: __()
  • wp-includes/functions.php: _deprecated_argument()

Used By

  • wp-includes/post.php: _transition_post_status()
  • wp-includes/post.php: _future_post_hook()
  • wp-includes/post.php: check_and_publish_future_post()
  • wp-includes/post.php: wp_delete_post()

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

    Basic Example

    Clear a scheduled event

    
    // If you previously added for example
    // wp_schedule_single_event( time() + 3600, 'my_new_event' );
    
    wp_clear_scheduled_hook( 'my_new_event' );
    
    // or this if you created something like
    // wp_schedule_single_event( time() + 3600, 'my_new_event', array( 'some_arg' ) );
    
    wp_clear_scheduled_hook( 'my_new_event', array( 'some_arg' ) );
    

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

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

发布评论

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