Save Time by
Managing WordPress
from the Command
Line
WordCamp Toronto	

November 16, 2014	

@shawnhooper
• I’m Shawn Hooper, a web application
developer from Ottawa.
• I’ve been working in WordPress since
2009.
• I love the working from the command
prompt, reminds me of my days running
a BBS (in the days before the Internet)
Hi!
Command Line?!
Command Line?!
• A set of command line tools that allows
you to manage WordPress from the
command line.

• http://www.wp-cli.org/
What is WP-CLI ?
• Anyone really, but mostly:
• Developers
• Theme Designers
• Server Administrators
Who is this for?
Don’t Fear The
Command Line
• http://www.wp-cli.org/
• Requires PHP 3.5.2 or later
• Requires WordPress 3.5.2 or later
• A “UNIX-like” environment:
• OSX (Macintosh)
• Linux
• Cygwin (Windows)
What do you need?
• Most shared hosts won’t allow you to
use WP-CLI - you need to have SSH
access to your server.
• SiteGround includes WP-CLI in their
hosting plans, as does GoDaddy
Managed Hosting.
• Perfect on VPS services like
DigitalOcean, Linode, terminal.com
.hosts
• Download it:

curl -O https://raw.githubusercontent.com/
wp-cli/builds/gh-pages/phar/wp-cli.phar

• Set permissions: 

chmod a+x wp-cli.phar

• Move it somewhere useful:

sudo mv wp-cli.phar /usr/local/bin/wp 

Installing WP-CLI
• Does it work? Type:



wp

Installing WP-CLI
Installing WP-CLI
Congratulations!
(that was the hard part)
Great… It’s installed.
So now what….
wp <command> <sub-command> <params>
Running Commands:
<param> — required
[—param] — optional flag
[—param=<value>] — optional w/ value
Running Commands:
• Check current WordPress version, or
see if there are updates available.
• Do the update!
• Install a brand new site
• Convert an existing site to Multisite!
• Verify core checksums
core
• Let’s try setting up a brand new site on
a development server using:



wp core download

wp core config

wp db create

wp core install
core
• Install, Delete Plugins
• Activate & Deactivate Plugins
• Update Plugins
• Search the repository for plugins
plugin
• Time savers!



wp plugin update — all



wp plugin deactivate — all
plugin
The “db” command interacts with
the MySQL database.
!
wp export backup.sql



wp import backup.sql



wp cli
db
• Safe Search & Replace, including
serialized arrays!

• Supports —dry-run
search-replace
Generate Test Content !
!
wp post generate —count=500
post
Regenerate Thumbnails
!
wp media regenerate —yes
media
Start an underscores theme!
!
wp scaffold _s mytheme
scaffold
… or a child theme
!
wp scaffold child-theme mychild
—parent_theme=twentyfourteen
scaffold
… or a custom post type
!
wp scaffold post-type mycpt —
theme
scaffold
Download & Activate a Theme
from WordPress.org
!
wp theme install simone —activate
theme
Add any functionality you want
that isn’t already included in the
WP-CLI core.
https://github.com/wp-cli/wp-cli/
wiki/List-of-community-commands
Community
Commands
You can either write them as a
plugin, or include it using the

—require parameter

on the command line.
Community
Commands
Thank you!
!
E-Mail: shawn@fivesense.ca
Twitter: @shawnhooper
!
http://5sen.se/wpcli/

Save Time by Managing WordPress from the Command Line

  • 1.
    Save Time by ManagingWordPress from the Command Line WordCamp Toronto November 16, 2014 @shawnhooper
  • 2.
    • I’m ShawnHooper, a web application developer from Ottawa. • I’ve been working in WordPress since 2009. • I love the working from the command prompt, reminds me of my days running a BBS (in the days before the Internet) Hi!
  • 3.
  • 4.
  • 5.
    • A setof command line tools that allows you to manage WordPress from the command line.
 • http://www.wp-cli.org/ What is WP-CLI ?
  • 6.
    • Anyone really,but mostly: • Developers • Theme Designers • Server Administrators Who is this for?
  • 7.
  • 8.
    • http://www.wp-cli.org/ • RequiresPHP 3.5.2 or later • Requires WordPress 3.5.2 or later • A “UNIX-like” environment: • OSX (Macintosh) • Linux • Cygwin (Windows) What do you need?
  • 9.
    • Most sharedhosts won’t allow you to use WP-CLI - you need to have SSH access to your server. • SiteGround includes WP-CLI in their hosting plans, as does GoDaddy Managed Hosting. • Perfect on VPS services like DigitalOcean, Linode, terminal.com .hosts
  • 10.
    • Download it:
 curl-O https://raw.githubusercontent.com/ wp-cli/builds/gh-pages/phar/wp-cli.phar
 • Set permissions: 
 chmod a+x wp-cli.phar
 • Move it somewhere useful:
 sudo mv wp-cli.phar /usr/local/bin/wp 
 Installing WP-CLI
  • 11.
    • Does itwork? Type:
 
 wp
 Installing WP-CLI
  • 12.
  • 13.
  • 14.
  • 15.
    wp <command> <sub-command><params> Running Commands:
  • 16.
    <param> — required [—param]— optional flag [—param=<value>] — optional w/ value Running Commands:
  • 17.
    • Check currentWordPress version, or see if there are updates available. • Do the update! • Install a brand new site • Convert an existing site to Multisite! • Verify core checksums core
  • 18.
    • Let’s trysetting up a brand new site on a development server using:
 
 wp core download
 wp core config
 wp db create
 wp core install core
  • 19.
    • Install, DeletePlugins • Activate & Deactivate Plugins • Update Plugins • Search the repository for plugins plugin
  • 20.
    • Time savers!
 
 wpplugin update — all
 
 wp plugin deactivate — all plugin
  • 21.
    The “db” commandinteracts with the MySQL database. ! wp export backup.sql
 
 wp import backup.sql
 
 wp cli db
  • 22.
    • Safe Search& Replace, including serialized arrays!
 • Supports —dry-run search-replace
  • 23.
    Generate Test Content! ! wp post generate —count=500 post
  • 24.
    Regenerate Thumbnails ! wp mediaregenerate —yes media
  • 25.
    Start an underscorestheme! ! wp scaffold _s mytheme scaffold
  • 26.
    … or achild theme ! wp scaffold child-theme mychild —parent_theme=twentyfourteen scaffold
  • 27.
    … or acustom post type ! wp scaffold post-type mycpt — theme scaffold
  • 28.
    Download & Activatea Theme from WordPress.org ! wp theme install simone —activate theme
  • 29.
    Add any functionalityyou want that isn’t already included in the WP-CLI core. https://github.com/wp-cli/wp-cli/ wiki/List-of-community-commands Community Commands
  • 30.
    You can eitherwrite them as a plugin, or include it using the
 —require parameter
 on the command line. Community Commands
  • 31.
    Thank you! ! E-Mail: shawn@fivesense.ca Twitter:@shawnhooper ! http://5sen.se/wpcli/