Make your life easy with WP-CLI

Preview:

DESCRIPTION

WP-CLI presentation from WordCamp Montreal 2014

Citation preview

Make Your Life Easier 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.

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.

WordCamp Montreal - August 2014

What is WP-CLI?

A super awesome open-source tool to manage your WordPress installations.

http://wp-cli.org/!

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)

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

WordCamp Montreal - August 2014

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/

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

WordCamp Montreal - August 2014

What Can It Do?All the things.

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

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

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!

WordCamp Montreal - August 2014

Manage Pluginswp plugin update --all!

wp plugin install bbpress --activate!

wp plugin uninstall hello!

wp plugin delete hello!

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.

WordCamp Montreal - August 2014

Database Import / Export

wp db export mybackup.sql!

wp db import mybackup.sql!

!

WordCamp Montreal - August 2014

Manage Media / Dummy Data

wp media regenerate —yes!

wp generate posts --count=500!

wp generate users --role=contributor!

!

WordCamp Montreal - August 2014

So Much MoreA full list of commands is available with full

documentation and examples:

http://wp-cli.org/commands/

!

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/

WordCamp Montreal - August 2014

Lets Make a Plugin

WordCamp Montreal - August 2014

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

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’

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

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

Questions?