Make your life easy with WP-CLI
-
Upload
michael-corkum -
Category
Presentations & Public Speaking
-
view
71 -
download
2
description
Transcript of Make your life easy with WP-CLI
![Page 1: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/1.jpg)
Make Your Life Easier With WP-CLI
![Page 2: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/2.jpg)
WordCamp Montreal - August 2014
About Me• Web developer with over
15 years of experience.
• Senior Web Developer at Carleton University in Ottawa, Ontario.
• Developing for WordPress for since 2005.
![Page 3: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/3.jpg)
WordCamp Montreal - August 2014
About Carleton• Over 26,000 students and 4,000 Staff.
• Over 250 WordPress sites.
• More than a million page views per month.
• Small team who are responsible for the support, maintenance and training for all WordPress powered sites on campus.
• WP-CLI, along with other tools helps us do this with a relatively small team.
![Page 4: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/4.jpg)
WordCamp Montreal - August 2014
What is WP-CLI?
A super awesome open-source tool to manage your WordPress installations.
http://wp-cli.org/!
![Page 5: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/5.jpg)
WordCamp Montreal - August 2014
Why?Simple and faster then traditional methods
Automate and script common tasks
Efficient (uses WordPress to perform operations)
Extensible (user contributed commands / custom commands)
![Page 6: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/6.jpg)
WordCamp Montreal - August 2014
What’s RequiredSSH access to your WordPress install's directory
PHP 5.3+
WordPress 3.3+
Enough server memory for shell processes to run WordPress
![Page 7: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/7.jpg)
WordCamp Montreal - August 2014
![Page 8: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/8.jpg)
WordCamp Montreal - August 2014
Fear Not!Read a few simple guides about SSH and learn basic commands:
How to SSH: http://code.tutsplus.com/tutorials/ssh-what-and-how--net-25138
Basic Commands: http://www.servermom.org/top-most-used-common-ssh-commands/56/
![Page 9: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/9.jpg)
WordCamp Montreal - August 2014
Installing WP-CLIInstructions at: http://wp-cli.org/
Hosts with WP-CLI pre-installed: https://github.com/wp-cli/wp-cli/wiki/List-of-hosting-companies
![Page 10: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/10.jpg)
WordCamp Montreal - August 2014
What Can It Do?All the things.
![Page 11: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/11.jpg)
WordCamp Montreal - August 2014
Anatomy of a Command
wp generate posts --count=500!
“generate” is the command
“posts” is the subcommand
“count” is a parameter
![Page 12: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/12.jpg)
WordCamp Montreal - August 2014
Global Command Parameters
The following parameters can be passed to any command:
--user = set the current user--url = set the current URL
--path = set the current path to the WP install --require = load a file before running the command
--versionprint = WP-CLI version
![Page 13: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/13.jpg)
WordCamp Montreal - August 2014
Manage Corewp core download!
wp core config --dbname=testing --dbuser=wp!
wp core update!
wp core update-db!
wp core multisite-convert!
![Page 14: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/14.jpg)
WordCamp Montreal - August 2014
Manage Pluginswp plugin update --all!
wp plugin install bbpress --activate!
wp plugin uninstall hello!
wp plugin delete hello!
![Page 15: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/15.jpg)
WordCamp Montreal - August 2014
Search & Replacewp search-replace 'http://example.dev' 'http://
example.com' --skip-columns=guid!
wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run!
WP-CLI will correctly handle serialized values, and will not change primary key values.
![Page 16: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/16.jpg)
WordCamp Montreal - August 2014
Database Import / Export
wp db export mybackup.sql!
wp db import mybackup.sql!
!
![Page 17: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/17.jpg)
WordCamp Montreal - August 2014
Manage Media / Dummy Data
wp media regenerate —yes!
wp generate posts --count=500!
wp generate users --role=contributor!
!
![Page 18: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/18.jpg)
WordCamp Montreal - August 2014
So Much MoreA full list of commands is available with full
documentation and examples:
http://wp-cli.org/commands/
!
![Page 19: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/19.jpg)
WordCamp Montreal - August 2014
Custom CommandsSite specific tasks
One-off fixes / Annoying client requests
Commands that don’t currently exist
There is a large list of community commands: http://wp-cli.org/package-index/
![Page 20: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/20.jpg)
WordCamp Montreal - August 2014
Lets Make a Plugin
![Page 21: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/21.jpg)
WordCamp Montreal - August 2014
Defining a CommandI use sub-commands to keep things organized.
![Page 22: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/22.jpg)
WordCamp Montreal - August 2014
Subcommand
$args: stand-alone arguments$assoc_args: --arg=value in associative array
wp example example-command Hello World --param=Hello!
$args[0] == ‘Hello’$args[1] == ‘World’
$assoc_args[‘param’] == ‘Hello’
![Page 23: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/23.jpg)
WordCamp Montreal - August 2014
Example CommandLet’s see some code!
Basics / PHPDoc Guide: https://github.com/wp-cli/wp-cli/wiki/Commands-Cookbook
WP-CLI API: https://github.com/wp-cli/wp-cli/wiki/API
WP-CLI Example Code: https://github.com/cuweb/wp-cli
![Page 24: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/24.jpg)
WordCamp Montreal - August 2014
Resourceshttp://wp-cli.org/
http://code.tutsplus.com/tutorials/ssh-what-and-how--net-25138
http://www.servermom.org/top-most-used-common-ssh-commands/56/
https://github.com/wp-cli/wp-cli/wiki/List-of-hosting-companies
http://wp-cli.org/commands/
https://github.com/wp-cli/wp-cli/wiki
https://github.com/cuweb/wp-cli
![Page 25: Make your life easy with WP-CLI](https://reader033.fdocuments.us/reader033/viewer/2022060118/558a60a4d8b42a476e8b461b/html5/thumbnails/25.jpg)
Questions?