Action_Scheduler\WP_CLI\Action

Generate_Command::generate()protectedWC 1.0

Schedule multiple single actions.

Method of the class: Generate_Command{}

No Hooks.

Return

Int[]. IDs of actions added.

Usage

// protected - for code of main (parent) or child class
$result = $this->generate( $schedule_start, $interval, $count, $hook, $args, $group );
$schedule_start(int) (required)
Starting timestamp of first action.
$interval(int) (required)
How long to wait between runs.
$count(int) (required)
Limit number of actions to schedule.
$hook(string) (required)
The hook to trigger.
$args(array)
Arguments to pass when the hook triggers.
Default: array()
$group(string)
The group to assign this job to.
Default: ''

Generate_Command::generate() code WC 9.8.2

protected function generate( $schedule_start, $interval, $count, $hook, array $args = array(), $group = '' ) {
	$actions_added = array();

	$progress_bar = \WP_CLI\Utils\make_progress_bar(
		sprintf(
			/* translators: %d is number of actions to create */
			_n( 'Creating %d action', 'Creating %d actions', $count, 'woocommerce' ),
			number_format_i18n( $count )
		),
		$count
	);

	for ( $i = 0; $i < $count; $i++ ) {
		$actions_added[] = as_schedule_single_action( $schedule_start + ( $i * $interval ), $hook, $args, $group );
		$progress_bar->tick();
	}

	$progress_bar->finish();

	return $actions_added;
}