Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Making Your Whole* Life Easier With WP-CLI

Making Your Whole* Life Easier With WP-CLI

Presentation from WordCamp St. Louis 2014.

*Okay, maybe not your WHOLE life.


Doug Stewart

March 01, 2014


  1. Doug Stewart ! @zamoose Senior Systems Engineer 10up *Okay, maybe

    not your whole life. Making Your Whole* Life Easier With WP-CLI WordCamp St. Louis 2014
  2. WP-CLI: What is it?

  3. • WP: WordPress • CLI: Command Line Interface WP-CLI

  4. The reaction of perhaps half of you: …?

  5. The other half:

  6. I got the “WordPress” part, but what’s a “CLI”?

  7. “A command-line interface (CLI) […] is a means of interacting

    with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines).” Source: Wikipedia (http://stwrt.org/cli-wiki)
  8. Yes, but why CLI?

  9. “Command-line interfaces are often preferred by more advanced computer users,

    as they often provide a more Source: Wikipedia (http://stwrt.org/cli-wiki) concise and powerful means to control a program or operating system.”
  10. …Oh, okay I

  11. “Programs with command-line interfaces are generally easier to automate via

    scripting.” Source: Wikipedia (http://stwrt.org/cli-wiki)
  12. None
  13. No, really, it’s easy.

  14. install.php

  15. WordPress: Infamous* for its easy “5 minute install” *It means

    “More than famous”.
  16. The “Hard” Easy Way 1. Download WP. 2. Extract zip.

    3. Connect to your host using SFTP*. 4. Change to the right directory. 5. Upload WordPress directory. 6. Repeat steps 1-5 for any other sites you might be installing. *You are using SFTP, right? RIGHT?
  17. The Easy Way 1. Log in to server via SSH*.

    2. Change to the right directory**. 3. Run `wp core download`. 4. Run steps 2-3 for any other sites you might be installing. • Oh, by the way, WP-CLI caches the WP download, so every subsequent install will go even faster. *You are using SSH, right? RIGHT? **Technically, you can just pass “—path=[path to directory]” to WP-CLI
  18. None
  19. is_multisite();

  20. Multisite the Hard Way 1. Prepare your WordPress 2. Allow

    Multisite A. Edit wp-config.php 3. Installing a Network B. Sub-domains or sub-folders? C. Double-check values D. Click “Install” 4. Enabling the Network E. Edit wp-config.php F. Edit .htaccess 5. Network Admin Settings 6. Administration From http://codex.wordpress.org/Create_A_Network
  21. Multisite the Easy Way 1. Change into your WordPress directory.

    2. `wp core multisite-install`* 3. `wp site create`
  22. *Due to a bug** in current versions of WP- CLI,

    .htaccess rules don’t get auto-generated. Copy and paste*** the rules from the Codex****. **http://stwrt.org/wp-cli-bug-790 ! ***C’mon, you’re already on the command line. A little vim won’t hurt. ! ****http://stwrt.org/codex-htaccess
  23. wp_create_user();

  24. Test Users the Hard Way 1. Log in to /wp-admin/.

    2. Navigate to Users->Add New. 3. Fill out dummy information for your test users. 4. Repeat steps 2-3 a hundred times.
  25. Test Users the Easy Way 1. Log in to your

    server. 2.Change into your WordPress installation’s directory*. 3.Run `wp user generate`. 4.There is no step 4.
  26. wp_insert_post();

  27. Create Dummy Content the Hard Way 1. Navigate to Posts->Add

    New. 2. Open another browser tab. 3. Go to http://loripsum.net/ 4. Copy dummy text. 5. Go back to the New Post screen. 6. Paste the Lorem. 7. Save the post. 8. Repeat steps 1-7 several hojillion* times. *Old English Standard unit for measure of quantity. SI equivalent is “metric boat-load”
  28. Create Dummy Content the Easy Way 1. Log on to

    your server. 2. Change to your WordPress directory. 3. Run `curl http://loripsum.net/api/5 | wp post generate --post_content —count=[one hojillion]`
  29. …But wait, there’s more!

  30. Lots of stuff the Easy way 1. `wp scaffold` •

    Plugin • Child theme • _s • Custom post type • Custom taxonomy 2. `wp search-replace` 3. `wp db` • Optimize/repair/import/export/CLI 4. `wp theme-test` 5. `wp export`/`wp import`
  31. It’s like a Swiss Army Knife for your WordPress

  32. Via ix64.com It’s turbo + slow-mo

  33. Where do I get it?

  34. Straight From The Source* • http://wp-cli.org • Follow the instructions

    • *Pun intended. • You should also follow @wpcli on Twitter.
  35. • Amimoto • Bluehost • Dreamhost • Media Temple •

    NearlyFreeSpeech.NET • SiteGround • Synthesis • TVC.Net • WordPress.com VIP Via http://stwrt.org/wp-cli-hosting Site Hosts With WP-CLI
  36. • Varying Vagrant Vagrants (VVV) • http://stwrt.org/vvv • Automattic’s VIP

    Quickstart • http://stwrt.org/vip-quickstart Various WP Environments
  37. Further Reading

  38. • @getsource’s WordCamp San Francisco 2013 talk: • Post: http://stwrt.org/getsource-post

    • PDF: http://stwrt.org/getsource-pdf • DigitalOcean’s awesome tutorial on proper use of WP-CLI: • http://stwrt.org/digitalocean-wp-cli • Using WP-CLI with MAMP: • http://stwrt.org/wp-cli-mamp • Neal Stephenson’s “In The Beginning Was The Command Line”: • http://stwrt.org/itbwtcl Further Reading
  39. Topics for advanced study 1. Puppet WP • http://stwrt.org/puppet-wp 2.

    Saltstack-WP • http://stwrt.org/saltstack-wp 3. Extending WP-CLI with your own commands • http://stwrt.org/wp-cli-commands 4. Packaging your commands for others • http://stwrt.org/wp-cli-packages 5. Community packages • http://stwrt.org/wp-cli-compkgs
  40. I am a sysadmin and so can you!

  41. Reach out and touch someone. • Twitter: @zamoose • Email:

    doug@10up.com • Web: literalbarrage.org/blog/ • This presentation: http://stwrt.org/wcstl2014
  42. Thanks for attending!