WordPress Command Line Interface

OMG it’s been a year since my last update. So bad of me and so much has changed! Personal life is for a different post. This is all about the developer part. 

Two years ago, I was working on a customed plugin that made calls to NASDAQ. There were a LOT of cron commands making API calls for updates. I found out pretty early that the ‘Run now’ button doesn’t do what it says if there are 2 minutes or so before the next scheduled run. This became really annoying really quickly. Then, I had the most recent updates to plugins, I could turn on debug just fine and get errors to log just fine and dandy.

Fast forward two years, I have now switched from Windows machine to Linux and I’m tweaking the plugin for a complete different API and with outdated plugins that would cost to upgrade that throw errors all the time when WP_DEBUG  is set to true, the cron commands became INCREDIBLY hard to test. 

Poking around on google, I found the WP-CLI package. This has SAVED ME big time. You can do a bunch of developer tasks from the command line–including running cron tasks!!!! You can run them all, run any due, or run a specific one by the event hook. Simply do this in your favorite shell:

// Run specific cron
wp cron event run <hook>

// RUN THEM ALLLLLL
wp cron event --all

From what I briefly looked at when I looked at help, you can do a lot of other things to like clear cache, run a database query, even create a post! I wouldn’t do that last one from command line though. 

Have fun with this new knowledge! 😀