wp_clear_scheduled_hook() - WordPress 函数参考中文文档

返回介绍

wp_clear_scheduled_hook()

发布于 2017-09-11 字数3144 浏览 794 评论 0

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

Unschedule all events attached to the specified hook.


描述


参数

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

更新日志

Version 描述
2.1.0 Introduced.

相关函数

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' ) );
    

上一篇:wp_clear_auth_cookie()

下一篇:wp_clone()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!