Sell digital downloads with WordPress, for free

As of late, I’ve found myself doing quite a few things via the command line with WP-CLI. If you’ve never used it before, it’s an extremely powerful command line interface for interacting with your WordPress installation. It comes bundled with some great utilities to help you out, including a WPCLI progress bar, but we’ll get to that in a minute.

Where it becomes extremely powerful is with tasks that can cause a web based interface to timeout or reach the max execution times. I have found it very helpful when running migration, import, and export scripts. If you’ve ever executed a long running task in the command line, you’ve felt the pain of thinking:

Is it still going? Did it break? What’s happening?

Enter…the progress bar

WP-CLI has an awesome built in method that allows you to output a progress bar, complete with the percentages, running time, and estimated time to completion.

The code to make this happen is surprisingly simple. It consists of 3 lines:

First you define what the text will be in front of the progress bar, and the total number of items to complete.
$progress = \WP_CLI\Utils\make_progress_bar( 'Progress Bar', $total );

Next, during each step of your loop, you tick the progress bar.
$progress->tick();

After your loop is complete, you finish the progress bar
$progress->finish();

Example Plugin

 

Post Promoter Pro

Posted by Chris Klosowski

Hi, I'm Chris Klosowski. Currently I am a Lead Developer of Easy Digital Downloads, where we build the easiest way to sell digital products with WordPress.

I am also the person behind Post Promoter Pro, the most effective way to promote your WordPress Content.

One Comment

  1. Hey Chris,

    Thanks for the post. Are you using Phpstorm IDE? do you know how to remove WP_CLI Undefined class error from IDE?

    Reply

Leave a reply

Your email address will not be published. Required fields are marked *