$30 off During Our Annual Pro Sale. View Details »

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
Tweet

More Decks by Doug Stewart

Other Decks in Programming

Transcript

  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

    View Slide

  2. WP-CLI: What is it?

    View Slide

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

    View Slide

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

    View Slide

  5. The other half:

    View Slide

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

    View Slide

  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)

    View Slide

  8. Yes, but why
    CLI?

    View Slide

  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.”

    View Slide

  10. …Oh, okay I

    View Slide

  11. “Programs with command-line interfaces
    are generally easier to automate via
    scripting.”
    Source: Wikipedia (http://stwrt.org/cli-wiki)

    View Slide

  12. View Slide

  13. No, really, it’s easy.

    View Slide

  14. install.php

    View Slide

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

    View Slide

  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?

    View Slide

  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

    View Slide

  18. View Slide

  19. is_multisite();

    View Slide

  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

    View Slide

  21. Multisite the Easy Way
    1. Change into your
    WordPress directory.
    2. `wp core multisite-install`*
    3. `wp site create`

    View Slide

  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

    View Slide

  23. wp_create_user();

    View Slide

  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.

    View Slide

  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.

    View Slide

  26. wp_insert_post();

    View Slide

  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”

    View Slide

  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]`

    View Slide

  29. …But wait, there’s
    more!

    View Slide

  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`

    View Slide

  31. It’s like a Swiss Army Knife
    for your WordPress

    View Slide

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

    View Slide

  33. Where do I get it?

    View Slide

  34. Straight From The Source*
    • http://wp-cli.org
    • Follow the instructions
    • *Pun intended.
    • You should also follow
    @wpcli on Twitter.

    View Slide

  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

    View Slide

  36. • Varying Vagrant Vagrants (VVV)
    • http://stwrt.org/vvv
    • Automattic’s VIP Quickstart
    • http://stwrt.org/vip-quickstart
    Various WP Environments

    View Slide

  37. Further Reading

    View Slide

  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

    View Slide

  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

    View Slide

  40. I am a sysadmin and so can you!

    View Slide

  41. Reach out and touch someone.
    • Twitter: @zamoose
    • Email: [email protected]
    • Web: literalbarrage.org/blog/
    • This presentation: http://stwrt.org/wcstl2014

    View Slide

  42. Thanks for attending!

    View Slide