Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Themer's Guide to WP-CLI

439 views

Published on

A 30 minute presentation and demonstration about using WP-CLI as a toolbox for automating your workflow.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

The Themer's Guide to WP-CLI

  1. 1. 1. Intro 2. WP-CLI Basics 3. Install WordPress 4. Plugin and Theme Automation 5. PHP7 Compatibility Checker 6. Advanced Agenda
  2. 2. _____ _ _ _ _ |_ _| | | | | | | (_) | | _ __ | |_ _ __ ___ __| |_ _ ___| |_ _ ___ _ __ | | | '_ | __| '__/ _ / _` | | | |/ __| __| |/ _ | '_ _| |_| | | | |_| | | (_) | (_| | |_| | (__| |_| | (_) | | | | |_____|_| |_|__|_| ___/ __,_|__,_|___|__|_|___/|_| |_|
  3. 3. •Sales Engineer - WP Engine •Developer, Freelancer •CMS Specialist •Open Source •Speaker Edmund Turbin WordCamp Stockholm - Nov 2016
  4. 4. THERE ARE TWO TYPES OF PEOPLE IN THE WORLD
  5. 5. I ❤
  6. 6. WHY USE COMMANDS? •Quickly execute a task •Bundle many tasks together in scripts •Avoid using the keyboard and mouse •Simplify repetitive tasks •and also…
  7. 7. WHY USE COMMANDS?SO WE CAN BE LAZY
  8. 8. ____ _ | _ (_) | |_) | __ _ ___ _ ___ ___ | _ < / _` | / __| | | / __| / __| | |_) | | (_| | __ | | | (__ __ |____/ __,_| |___/ |_| ___| |___/
  9. 9. WHAT DO I NEED TO GET STARTED? •Local Dev Environment with PHP - VVV, MAMP, WAMP •Terminal - Terminal App, iTerm 2, PuTTY •Text Editor - Sublime, Atom PREREQUISITES
  10. 10. INSTALL WP-CLI curl -O https://raw.githubusercontent.com/wp-cli/ builds/gh-pages/phar/wp-cli.phar https://make.wordpress.org/cli/handbook/installing/
  11. 11. INSTALL WP-CLI # Make file executable chmod +x wp-cli.phar # Move file to proper location sudo mv wp-cli.phar /usr/local/bin/wp https://make.wordpress.org/cli/handbook/installing/
  12. 12. INSTALL WP-CLI • change into a WP directory • run $wp cli info https://make.wordpress.org/cli/handbook/installing/ TEST THE INSTALLATION
  13. 13. COMMAND STRUCTURE $wp command subcommand value $wp theme install twentysixteen
  14. 14. _____ __ _ _ _ / ____| / _(_) | | (_) | | ___ _ __ | |_ _ __ _ _ _ _ __ __ _| |_ _ ___ _ __ | | / _ | '_ | _| |/ _` | | | | '__/ _` | __| |/ _ | '_ | |___| (_) | | | | | | | (_| | |_| | | | (_| | |_| | (_) | | | | ________/|_| |_|_| |_|__, |__,_|_| __,_|__|_|___/|_| |_| __/ | |___/
  15. 15. WHAT HAVE I DONE? • Installed WP-CLI locally • Configured a WP-CLI alias to SSH into remotes • I can execute remote commands as if they were on my local machine • No need for local MySQL/PHP/Apache • Alternate - use SSH directly into VVV using vagrant ssh
  16. 16. CONFIGURATION •Alias called @dev allows me to run remote commands • $wp @dev cli info is different than $wp cli info • @dev connects via SSH and runs on Vagrant box https://make.wordpress.org/cli/handbook/config/ wp-cli.yml - Aliases with Vagrant
  17. 17. CONFIGURATION •Allows you to configure WP-CLI variables •File can be at the Global, Project and Local levels •e.g.: Local overrides Global •Allows you to set up Aliases per site https://make.wordpress.org/cli/handbook/config/ wp-cli.yml
  18. 18. CONFIGURATION @dev: ssh: vagrant@wpcli-test.dev/srv/www/wpcli-test https://make.wordpress.org/cli/handbook/installing/ wp-cli.yml - Aliases with Vagrant
  19. 19. _____ _ / ____| | | | | ___ _ __ ___ _ __ ___ __ _ _ __ __| | ___ | | / _ | '_ ` _ | '_ ` _ / _` | | '_ / _` | / __| | |____ | (_) | | | | | | | | | | | | | | (_| | | | | | | (_| | __ _____| ___/ |_| |_| |_| |_| |_| |_| __,_| |_| |_| __,_| |___/
  20. 20. CORE OPERATIONS •Downloads the recent version of WordPress to the current directory $wp core download
  21. 21. CORE OPERATIONS •Creates WordPress configuration file. •This file tells WP-CLI how connect to you’re site’s database $wp core config
  22. 22. DATABASE OPERATIONS •Create a database for your WordPress install •Depends on a wp-config.php file to work $wp db create
  23. 23. CORE OPERATIONS •Completes the WordPress install process $wp core install
  24. 24. INSTALL WORDPRESS # Download WordPress $wp core download # Create WordPress configuration - wp-config.php $wp core config —-dbuser=root --dbpass=root —-dbname=wpcli-test
  25. 25. INSTALL WORDPRESS # Create Database for install $wp db create wpcli-test # Run the install process $wp core install —url=wpcli-test.dev —-title=“wpcli test” —admin_user=admin --admin_password=password --admin_email=info@example.com
  26. 26. INSTALL WORDPRESS •Not needed if you’re using VVV •WP installs can be created and provisioned via Vagrant Note for VVV Users https://varyingvagrantvagrants.org/
  27. 27. GETTING HELP $wp help
  28. 28. INSTALL A PLUGIN $wp plugin install wp-site-migrate —-activate
  29. 29. _ _ _ / | | | | (_) / _ _ | |_ ___ _ __ ___ __ _ | |_ _ ___ _ __ / / | | | | | __| / _ | '_ ` _ / _` | | __| | | / _ | '_ / ____ | |_| | | |_ | (_) | | | | | | | | (_| | | |_ | | | (_) | | | | | /_/ _ __,_| __| ___/ |_| |_| |_| __,_| __| |_| ___/ |_| |_|
  30. 30. SHELL SCRIPTING •You can use WP CLI with like any other command •e.g. tie commands together and run them as a list
  31. 31. INSTALL WORDPRESS PLUGINS, THEME #!/bin/bash # list of plugins plugins=("user-switching" "debug-objects""wp-cfm") # loop through plugin list and install for plugin in ${plugins[*]}; do wp plugin install $plugin wp plugin activate $plugin done
  32. 32. CREATE CHILD THEME wp scaffold child-theme generated-child-theme -- parent_theme=twentyseventeen --theme_name='Generated Child Theme' --activate
  33. 33. INSTALL UNDERSCORE_S THEME #!/bin/bash # Installl _s theme with Unit Tests echo "Enter site name:" read theme_name wp scaffold _s $theme_name wp theme activate $theme_name wp scaffold theme-tests $theme_name
  34. 34. GENERATE CONTENT wp any-ipsum generate-posts wp post generate --count=10 --post_type=page wp comment generate --count=10
  35. 35. _____ _ _ _____ ______ _____ _ _ | __ | | | | | __ |____ | / ____| | | | | | |__) | | |__| | | |__) | / / | | | |__ ___ ___ | | __ | ___/ | __ | | ___/ / / | | | '_ / _ / __| | |/ / | | | | | | | | / / | |____ | | | | | __/ | (__ | < |_| |_| |_| |_| /_/ _____| |_| |_| ___| ___| |_|_
  36. 36. PHP COMPATIBILITY COMMAND •Run PHP7 Compatibility Checker •Plugin needs to be installed •Version supplied as an argument wp phpcompat 7.0
  37. 37. RUN PHP COMPATIBILITY CHECK SCRIPT #!/bin/bash wp plugin install php-compatibility-checker wp plugin activate php-compatibility-checker wp phpcompat 7.0 > php-compat-results.txt
  38. 38. PLUGINS WITH COMMANDS •ACF •Elastic press •Migrate, migrated •caching plugins •PHP Compatibility •Regen thumbs •widget import/export •developer •wp-cfm •backupwordpress https://make.wordpress.org/cli/handbook/tools/
  39. 39. _ _ / | | | | / __| | __ __ __ _ _ __ ___ ___ __| | / / / _` | / / / _` | | '_ / __| / _ / _` | / ____ | (_| | V / | (_| | | | | | | (__ | __/ | (_| | /_/ _ __,_| _/ __,_| |_| |_| ___| ___| __,_|
  40. 40. SHELL ALIAS COMMAND Create a shortcut command for things that are frequently used to cut down on keystrokes. alias - show all aliases
  41. 41. SHELL ALIASES Create an alias alias pu=“wp plugin update --all”
  42. 42. SHELL ALIASES Remove an alias unalias pu
  43. 43. SHELL ALIASES Arguments alias pi='wp plugin install’ pi wp-smushit
  44. 44. SHELL ALIASES Aliases can be saved and managed from .bash_profile
  45. 45. CUSTOM SHELL COMMANDS • functions can be created in your shell profile (.bash_profile) and executed globaly gen-content () { wp any-ipsum generate-posts wp comment generate --count=10 }
  46. 46. WP-CLI is a toolbox Commands can be linked together via scripts to automate complex tasks
  47. 47. WP-CLI for Themeing WP-CLI can be one of many tools to get your development process started quickly
  48. 48. Good, Better, Best •Single Commands & Aliases •Shell Scripts •Custom Shell Commands
  49. 49. Helpful Links Command Cookbook https://make.wordpress.org/cli/handbook/commands-cookbook/ Shell Friends https://make.wordpress.org/cli/handbook/shell-friends/ Plugins that work with WP-CLI https://make.wordpress.org/cli/handbook/tools/ WP-CLI Configuration https://make.wordpress.org/cli/handbook/config/ Shell Scripting https://www.shellscript.sh/ Advanced WordPress Management with WP-CLI https://www.smashingmagazine.com/2015/09/wordpress-management-with-wp-cli/
  50. 50. Thank you! @spicecadet edmund.turbin@wpengine.com

×