wp_get_schedule()利用参数检索用于钩子(hook)的定时事件

目录

描述

译文

利用参数检索用于钩子(hook)的定时事件。

原文

Retrieve Cron schedule for hook with arguments.

wp_get_schedule() 描述

用法

<?php wp_get_schedule$hook$args ); ?>

wp_get_schedule() 用法

参数

$hook

(callback) (必填) Action hook to execute when cron is run.

默认值: None

$args

(array) (可选) Arguments to pass to the hook function.

默认值: array

wp_get_schedule() 参数

返回值

(string|boolean) 

False, if no schedule. Schedule on success.

wp_get_schedule() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

// If you previously added for example:
// wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event' );

$schedule = wp_get_schedule( 'my_hourly_event' );

// $schedule == 'hourly'

// Or this if you created something like this:
// wp_schedule_single_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event', array( 'some_arg' ) );

$schedule = wp_get_schedule( 'my_hourly_event', array( 'some_arg' ) );

// $schedule == 'hourly'

wp_get_schedule() 示例

注意

  • Cron is named after a Unix program which runs unattended scheduled tasks.

wp_get_schedule() 注意

历史

添加于 版本: 2.1.0

wp_get_schedule() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve Cron schedule for hook with arguments.
 *
 * @since 2.1.0
 *
 * @param string $hook Action hook to execute when cron is run.
 * @param array $args Optional. Arguments to pass to the hook's callback function.
 * @return string|false False, if no schedule. Schedule on success.
 */
function wp_get_schedule($hook, $args = array()) {
	$crons = _get_cron_array();
	$key = md5(serialize($args));
	if ( empty($crons) )
		return false;
	foreach ( $crons as $timestamp => $cron ) {
		if ( isset( $cron[$hook][$key] ) )
			return $cron[$hook][$key]['schedule'];
	}
	return false;
}

//
// Private functions
//

wp_get_schedule() 源文件

相关