Make your life easy with WP-CLI

25
Make Your Life Easier With WP-CLI

description

WP-CLI presentation from WordCamp Montreal 2014

Transcript of Make your life easy with WP-CLI

Page 1: Make your life easy with WP-CLI

Make Your Life Easier With WP-CLI

Page 2: Make your life easy with WP-CLI

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

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

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

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

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

WordCamp Montreal - August 2014

Page 8: Make your life easy with WP-CLI

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

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

WordCamp Montreal - August 2014

What Can It Do?All the things.

Page 11: Make your life easy with WP-CLI

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

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

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

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

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

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

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

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

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

WordCamp Montreal - August 2014

Lets Make a Plugin

Page 21: Make your life easy with WP-CLI

WordCamp Montreal - August 2014

Defining a CommandI use sub-commands to keep things organized.

Page 22: Make your life easy with WP-CLI

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

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

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

Questions?