number. * @param int $range_end Ending batch number. * @param string $single_batch_action Action to schedule for a single batch. * @param array $action_args Action arguments. * @return void */ public static function queue_batches( $range_start, $range_end, $single_batch_action, $action_args = array() ) { $batch_size = static::get_batch_size( 'queue_batches' ); $range_size = 1 + ( $range_end - $range_start ); $action_timestamp = time() + 5; if ( $range_size > $batch_size ) { // If the current batch range is larger than a single batch, // split the range into $queue_batch_size chunks. $chunk_size = (int) ceil( $range_size / $batch_size ); for ( $i = 0; $i < $batch_size; $i++ ) { $batch_start = (int) ( $range_start + ( $i * $chunk_size ) ); $batch_end = (int) min( $range_end, $range_start + ( $chunk_size * ( $i + 1 ) ) - 1 ); if ( $batch_start > $range_end ) { return; } self::schedule_action( 'queue_batches', array( $batch_start, $batch_end, $single_batch_action, $action_args ) ); } } else { // Otherwise, queue the single batches. for ( $i = $range_start; $i <= $range_end; $i++ ) { $batch_action_args = array_merge( array( $i ), $action_args ); self::schedule_action( $single_batch_action, $batch_action_args ); } } } /** * Clears all queued actions. */ public static function clear_queued_actions() { if ( version_compare( \ActionScheduler_Versions::instance()->latest_version(), '3.0', '>=' ) ) { \ActionScheduler::store()->cancel_actions_by_group( static::$group ); } else { $actions = static::get_actions(); foreach ( $actions as $action ) { self::queue()->cancel_all( $action, null, static::$group ); } } } }