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

 

Posted by Chris Klosowski

Chris Klosowski is the Director of Technology at Sandhills Development, LLC, creators of fine WordPress plugins, and ecommerce solutions.

27 Comments

  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

  2. If you’ve ever executed a long running task in the command line, you’ve felt the pain of thinking:
    Is it still going?

    Reply

  3. If you’ve never used it before, it’s an extremely powerful command line interface for interacting with your WordPress installation.

    Reply

  4. Thanks for ones marvelous posting! I certainly enjoyed reading it, you happen to be a great
    author. I will always bookmark your blog and will come back
    from now on. I want to encourage continue your great
    work, have a nice morning!

    Reply

  5. I’m really enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more enjoyable for me to come here
    and visit more often. Did you hire out a developer to create your theme?
    Exceptional work!

    Reply

  6. Hello there! I know this is kinda off topic but I was wondering
    if you knew where I could locate a captcha plugin for
    my comment form? I’m using the same blog platform as yours and I’m having problems finding one?
    Thanks a lot!

    Reply

  7. professional viagra cialis how to tell if a man is taking viagra hhgivvx – how to buy viagra online without

    Reply

  8. generic viagra purchase with mastercard viagra over the counter walgreens ViagraCND100Mg – ganaric viagra

    Reply

  9. doxycycline 100mg price cheap doxycycline online – doxycycline hyclate 100 mg cap

    Reply

  10. prednisone 0.5 mg buy prednisone – where can i order prednisone 20mg

    Reply

  11. zithromax online usa cheap azitromycin – zithromax online paypal

    Reply

  12. ivermectin 2mg best price on ivermectin pills – stromectol for sale

    Reply

  13. stromectol for humans ivermectin 6mg dosage – buy ivermectin

    Reply

  14. stromectol covid stromectol for sale – cost of ivermectin

    Reply

  15. ivermectin rx stromectol tablets – stromectol 15 mg

    Reply

  16. drugs prices prescription drugs online without doctor – mens ed pills

    Reply

  17. ed in men buy prescription drugs without doctor – online medications

    Reply

  18. best ed pills that work buy prescription drugs online – cheap medications

    Reply

  19. herbal ed prescription drugs without doctor approval – ed drug comparison

    Reply

  20. lexapro generic discount buy lexapro – prescription price for lexapro

    Reply

  21. generic ivermectin cream stromectol prices – ivermectin lotion

    Reply

  22. lipitor india generic buy lipitor – lipitor 10mg price singapore

    Reply

  23. purchase clomid buy clomid – cost of clomid

    Reply

  24. viagra amazon viagra pills – best place to buy generic viagra online

    Reply

  25. Hi to every , as I am really keen of reading this weblog’s post to be updated daily.

    It includes fastidious data.

    Reply

Leave a reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.