WP_CLI\Utils

make_progress_bar()WP-CLI 1.0

Create a progress bar to display percent completion of a given operation.

Progress bar is written to STDOUT, and disabled when command is piped. Progress advances with $progress->tick(), and completes with $progress->finish(). Process bar also indicates elapsed time and expected total time.

# `wp user generate` ticks progress bar each time a new user is created.
#
# $ wp user generate --count=500
# Generating users  22 % [=======>                             ] 0:05 / 0:23

$progress = \WP_CLI\Utils\make_progress_bar( 'Generating users', $count );
for ( $i = 0; $i < $count; $i++ ) {
	// uses wp_insert_user() to insert the user
	$progress->tick();
}
$progress->finish();

Хуков нет.

Возвращает

cli\progress\Bar|NoOp.

Использование

make_progress_bar( $message, $count, $interval );
$message(строка) (обязательный)
Text to display before the progress bar.
$count(int) (обязательный)
Total number of ticks to be performed.
$interval(int)
The interval in milliseconds between updates.
По умолчанию: 100

Код make_progress_bar() WP-CLI 2.8.0-alpha

function make_progress_bar( $message, $count, $interval = 100 ) {
	if ( Shell::isPiped() ) {
		return new NoOp();
	}

	return new Bar( $message, $count, $interval );
}