10 advanced WP-CLI tricks

These examples are adapted from my “WP-CLI: Advanced Usage” VIP Workshop presentation last week. I will now only ever use GIFs in slides.

wp-cli update --nightly

Live life on the bleeding edge by running latest and greatest version of WP-CLI.

The master branch is typically stable enough to use in local and staging environments. Or production too, yolo.

wp scaffold theme-tests

You probably knew you could scaffold plugin tests, but you probably didn’t know that you could also scaffold theme tests.

wp scaffold theme-tests gives you everything you need to write PHPUnit tests that leverage the WordPress test suite. Specifically:

  • bin/install-wp-tests.sh is a setup script to download the WordPress test suite and create the test database.
  • .travis.yml is a configuration file to automatically run your tests every time you push to GitHub (Travis account required).
  • tests/ contains the PHPUnit-specific files. You can modify test-sample.php to your liking.

Functionally, theme tests are pretty much the same as plugin tests. Check out the generated tests/bootstrap.php file for the secret of how your theme gets loaded into the test suite.

wp role reset

If you’ve been monkeying about with core’s default roles, wp role reset will set them back to the basics.

Reset a single role, or reset them all with --all.

wp rewrite list --match=<uri>

Rewrite rules are WordPress’ API for routing URI patterns to WP_Query instances.

For historical reasons, rewrite rules are stored in an option, which means you need to “flush” (regenerate) rewrite rules any time you register a new one.

The --match=<uri> argument makes it possible to see which rewrite rules match the URI you’ve provided, making it simple to debug why your rewrite rule doesn’t seem to be working. Because rewrite rules never work the first time.

wp shell

Ever wish you could literally write and run PHP code against WordPress?

Well, now you can. Actually, you’ve been able to for years.

wp site empty

If you want to delete all content in your WordPress install, but keep users, options, etc., wp site empty is your new best friend.

wp cron event run

After the Rewrite API, WP Cron is the WordPress developer’s second most bane of their existence. It’s opaque, buggy, and unreliable.

But, we have to use it, so we may as well make it easier to work with.


There are some commands I still can never remember the arguments for.

--prompt works with any WP-CLI command, even those you write yourself, and interactively walks you through all of the arguments you need to complete.


WP-CLI supports global- and project-based configuration files to accelerate your workflow.

For instance, if you use the same command with the same arguments over and over again, you can define those arguments as the default arguments for the command.

“Ugh, I always have to enter the same username and password when installing WordPress”… no you don’t!


You must be a WP-CLI master.

Here are four challenges for you to complete (with WP-CLI) in two minutes or less. For the solution, click on the link to see the GIF:

Informal VIP client survey: how do you commit to SVN?

I am currently a single point of failure for getting code from our Github repo to WordPress.com VIP SVN. As such, we (Fusion) are exploring a project to auto-deploy our Github repository to VIP SVN through post-CI middleware. But, before we dive into development, we want to make sure we’ve exhausted all lower-effort options.

How does your code get from Github to VIP SVN? Would you potentially want ot use our project? Please let me know with a comment — thanks!

End of one era, on to the next

Automattic has claimed ownership of the plugins I worked on during my employment. As such, the VIP team and others will be taking responsibility for their continued development, maintenance, WordPress.org support, etc. Hopefully they remain independent and aren’t rolled into Jetpack. I’ll contribute as relevant to Human Made projects, but will no longer take an active role with the plugins.

These plugins include:

  • Edit Flow
  • Co-Authors Plus
  • Ad Code Manager
  • P2 Resolved Posts
  • Document Feedback
  • Rewrite Rules Inspector
  • Custom JavaScript Editor

Sometimes what appears to be a curse is actually a blessing in disguise. Human Made has pretty neat products in the works that I’m enjoying applying my creative energy towards. Stay tuned for that. And, on the open source side of things, I’ll have more time to contribute to wp-cli.

To everyone who’s used one of the above: it’s been a pleasure working with you. I’m looking forward to the opportunity to do so again in the future.

Ad Code Manager v0.4: Easier Configuration for Google AdSense and Doubleclick For Publishers Async

Ad Code Manager v0.4: Easier Configuration for Google AdSense and Doubleclick For Publishers Async. By “easier”, I really meant “much easier.”


Ran twenty miles this morning, the last long one before the marathon two weeks from now. The first half involved running down to the waterfront and doing a few loops — it felt great. The second half became increasingly more difficult because I ignored Leah’s advice to fuel early and often. Lesson learned.

Quartz also launched this morning. It’s the bleeding-edge of what’s being built on top of WordPress. I’m excited to see how the application continues to evolve and, being a long-time Economist reader, doubly excited to become an active reader. Quartz brings new meaning to the phrase “Powered by WordPress.com VIP.”

VIP plugin idea: Tips inbox

Quick plugin idea from a conversation with Scott from Grist: use Post By Email available on WordPress.com to funnel press releases, story ideas, etc. into the dashboard.

Upon importing, these would be saved to a custom post type that allows you to comment on the pitch, indicate that you’re working on the story, or punt it far, far away.

Seems like a fun hack to me.