cron_schedules

最后更新于:2021-11-26 04:02:49

apply_filters( ‘cron_schedules’, array $new_schedules )

Filters the non-default cron schedules.

参数

$new_schedules

(array)
An array of non-default cron schedules. Default empty.

function my_add_intervals($schedules) {
	// add a 'weekly' interval
	$schedules['weekly'] = array(
		'interval' => 604800,
		'display' => __('Once Weekly')
	);
	$schedules['monthly'] = array(
		'interval' => 2635200,
		'display' => __('Once a month')
	);
	return $schedules;
}
add_filter( 'cron_schedules', 'my_add_intervals'); 

源文件

文件: gc-includes/cron.php

View on Trac

function custom_cron_job_recurrence( $schedules ) 
{
	if(!isset($schedules['10sec']))
	{
		$schedules['10sec'] = array(
			'display' => __( 'Every 10 Seconds', 'twentyfifteen' ),
			'interval' => 10,
		);
	}
	
	if(!isset($schedules['15sec']))
	{
		$schedules['15sec'] = array(
		'display' => __( 'Every 15 Seconds', 'twentyfifteen' ),
		'interval' => 15,
		);
	}
	
	return $schedules;
}
add_filter( ‘cron_schedules’, ‘custom_cron_job_recurrence’ );

     add_filter( 'cron_schedules', array( $this, 'add_cron_interval' ) );

    /**
     * Adds custom time intervals for the cron.
     */
    private function add_cron_interval( $schedules ) {
          $options = get_option( 'gcdocs_custom_interval' );
          $interval = ( ! empty( $options ) ? absint( $options ) * HOUR_IN_SECONDS : DAY_IN_SECONDS );

          $schedules['gcdocs_interval'] = array(
               'interval' => $interval,
               'display' => esc_html__( 'Custom Interval' )
          );

          return $schedules;
    }