CLI for WordPress
an introduction
Hollywood WordPress Meetup
Mike Schroder (DH-Shredder)
@GetSource - http://www.getsource.net
Slide 2
Slide 2 text
Who Am I?
• Mike Schroder, a.k.a DH-Shredder, a.k.a. @GetSource
• Third Culture Kid, enjoy Coffee & Sailing
• WordPress Core and wp-cli Contributor
• Happy DreamHost Employee
Slide 3
Slide 3 text
There are two groups
of people.
Slide 4
Slide 4 text
Those who use the
command line
Slide 5
Slide 5 text
Those who are going to use
the command line
Slide 6
Slide 6 text
Don’t be afraid of the CLI.
It’s your friend.
Slide 7
Slide 7 text
Oh, you like the CLI?
wp-cli will make your life better.
Slide 8
Slide 8 text
Command Line Interface:
A direct, text-based, interface
to a computer.
Slide 9
Slide 9 text
A direct, text-based,
interface to your server.
Slide 10
Slide 10 text
At your host, you’ll see this
referred to as SSH.
Slide 11
Slide 11 text
Perform operations directly
on your server.
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
Why would I use the CLI?
Slide 15
Slide 15 text
Efficiency!
Get things done faster.
Slide 16
Slide 16 text
Copying a WordPress
install in SFTP?
Slide 17
Slide 17 text
~5 Minutes+
Slide 18
Slide 18 text
Copying a WordPress
install in SSH?
Slide 19
Slide 19 text
~10 Seconds
Slide 20
Slide 20 text
What else can I do?
Slide 21
Slide 21 text
Deploy your site.
Slide 22
Slide 22 text
On-server file editing.
Slide 23
Slide 23 text
Plugin and theme
installation or updates.
Slide 24
Slide 24 text
Commands and Arguments
$ cmd [optional arg]
Slide 25
Slide 25 text
Windows Instructions:
- Install Putty: http://bit.ly/y99vUd
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
Mac Instructions:
Open Terminal, then:
$ ssh [user@]
Slide 28
Slide 28 text
What are some basic
commands?
Slide 29
Slide 29 text
List files
$ ls [-a] [location]
-a for all files, including hidden
Slide 30
Slide 30 text
Change directory
$ cd
Use ~ for home.
../ to go up a directory.
Slide 31
Slide 31 text
Copy files
$ cp [-r]
-r copies recursively.
Slide 32
Slide 32 text
Remove files
$ rm [-r]
-r removes recursively.
Slide 33
Slide 33 text
Move files or directories
$ mv
Slide 34
Slide 34 text
Download files
$ wget
Slide 35
Slide 35 text
Unzip files
$ unzip
Slide 36
Slide 36 text
WordPress specific CLI
operations: WP-CLI
Slide 37
Slide 37 text
Super-cool Open Source tool
to manage WordPress
Slide 38
Slide 38 text
Headed up by
Cristi Burcă (scribu) and
Andreas Creten
Slide 39
Slide 39 text
Uses WordPress itself to
perform operations
Slide 40
Slide 40 text
Automation!
Slide 41
Slide 41 text
What can I do with it?
Slide 42
Slide 42 text
No content
Slide 43
Slide 43 text
No, Really.
Slide 44
Slide 44 text
Update WordPress
$ wp core update
Slide 45
Slide 45 text
Install a Theme
$ wp theme install
Slide 46
Slide 46 text
Change Theme
$ wp theme activate
Slide 47
Slide 47 text
Backup your Database
$ wp db export [filename]
Slide 48
Slide 48 text
Update Plugins
$ wp plugin update-all
Slide 49
Slide 49 text
Update Themes
$ wp theme update-all
Slide 50
Slide 50 text
What do I need to run it?
• SSH access to your WordPress install's directory
• PHP 5.3+
• WordPress 3.3+
• Enough RAM for shell processes to run WordPress
• Easiest on Linux & MacOS
Slide 51
Slide 51 text
Okay. Got that covered.
How can I get this
Awesomeness?
Slide 52
Slide 52 text
Install WP-CLI
Full Instructions at http://wp-cli.org
In short, from the root of your user:
curl http://wp-cli.org/installer.sh | bash
Slide 53
Slide 53 text
If you’re local and have sudo:
sudo utils/dev-build
Slide 54
Slide 54 text
Otherwise, add an alias
(.bashrc/.bash_profile)
alias wp='/home/user/wp-cli/src/bin/wp';
Slide 55
Slide 55 text
In ~/.bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
(http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html)
Slide 56
Slide 56 text
You’ve got it installed?
Let’s dig deeper.
Slide 57
Slide 57 text
WP-CLI is extensible.
Slide 58
Slide 58 text
Add your own directly
wp-cli/php/commands/community/cmd_name.php
Slide 59
Slide 59 text
Or, define in your plugins.
if ( defined('WP_CLI') && WP_CLI ) {
! include( PLUGIN_DIR . '/lib/wp-cli.php' );
}