Skip to content

Instantly share code, notes, and snippets.

@Oceas
Created September 16, 2019 16:42
Show Gist options
  • Save Oceas/76ee6e7dbf1bec56c1833bdf0d218591 to your computer and use it in GitHub Desktop.
Save Oceas/76ee6e7dbf1bec56c1833bdf0d218591 to your computer and use it in GitHub Desktop.
WP-CLI 101 Progress Bar
/**
* Displays progress bar to demonstrate progression through a time consuming process.
*
* @param Array $args Arguments in array format.
* @param Array $assoc_args Key value arguments stored in associated array format.
* @since 1.0.0
* @author Scott Anderson
*/
public function generate_posts_progress_bar( $args, $assoc_args ) {
$desired_posts_to_generate = (int) $args[0];
$progress = \WP_CLI\Utils\make_progress_bar( 'Generating Posts', $desired_posts_to_generate );
for ( $i = 0; $i < $desired_posts_to_generate; $i++ ) {
// Code used to generate a post.
$progress->tick();
}
$progress->finish();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment