save time by managing wordpress from the command line

31
Save Time by Managing WordPress from the Command Line WordCamp Toronto November 16, 2014 @shawnhooper

Upload: shawn-hooper

Post on 11-Jul-2015

1.857 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Save Time by Managing WordPress from the Command Line

Save Time by Managing WordPress from the Command

Line

WordCamp Toronto November 16, 2014

@shawnhooper

Page 2: Save Time by Managing WordPress from the Command Line

• 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!

Page 3: Save Time by Managing WordPress from the Command Line

Command Line?!

Page 4: Save Time by Managing WordPress from the Command Line

Command Line?!

Page 5: Save Time by Managing WordPress from the 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 ?

Page 6: Save Time by Managing WordPress from the Command Line

• Anyone really, but mostly:

• Developers

• Theme Designers

• Server Administrators

Who is this for?

Page 7: Save Time by Managing WordPress from the Command Line

Don’t Fear The Command Line

Page 8: Save Time by Managing WordPress from 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?

Page 9: Save Time by Managing WordPress from the Command Line

• 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

Page 10: Save Time by Managing WordPress from the Command Line

• 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

Page 11: Save Time by Managing WordPress from the Command Line

• Does it work? Type: wp

Installing WP-CLI

Page 12: Save Time by Managing WordPress from the Command Line

Installing WP-CLI

Page 13: Save Time by Managing WordPress from the Command Line

Congratulations! (that was the hard part)

Page 14: Save Time by Managing WordPress from the Command Line

Great… It’s installed. So now what….

Page 15: Save Time by Managing WordPress from the Command Line

wp <command> <sub-command> <params>

Running Commands:

Page 16: Save Time by Managing WordPress from the Command Line

<param> — required

[—param] — optional flag

[—param=<value>] — optional w/ value

Running Commands:

Page 17: Save Time by Managing WordPress from the Command Line

• 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

Page 18: Save Time by Managing WordPress from the Command Line

• 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

Page 19: Save Time by Managing WordPress from the Command Line

• Install, Delete Plugins

• Activate & Deactivate Plugins

• Update Plugins

• Search the repository for plugins

plugin

Page 20: Save Time by Managing WordPress from the Command Line

• Time savers! wp plugin update — all wp plugin deactivate — all

plugin

Page 21: Save Time by Managing WordPress from the Command Line

The “db” command interacts with

the MySQL database.

!

wp export backup.sql wp import backup.sql wp cli

db

Page 22: Save Time by Managing WordPress from the Command Line

• Safe Search & Replace, including serialized arrays!

• Supports —dry-run

search-replace

Page 23: Save Time by Managing WordPress from the Command Line

Generate Test Content !

!

wp post generate —count=500

post

Page 24: Save Time by Managing WordPress from the Command Line

Regenerate Thumbnails

!

wp media regenerate —yes

media

Page 25: Save Time by Managing WordPress from the Command Line

Start an underscores theme!

!

wp scaffold _s mytheme

scaffold

Page 26: Save Time by Managing WordPress from the Command Line

… or a child theme

!

wp scaffold child-theme mychild —parent_theme=twentyfourteen

scaffold

Page 27: Save Time by Managing WordPress from the Command Line

… or a custom post type

!

wp scaffold post-type mycpt —theme

scaffold

Page 28: Save Time by Managing WordPress from the Command Line

Download & Activate a Theme from WordPress.org

!

wp theme install simone —activate

theme

Page 29: Save Time by Managing WordPress from the Command Line

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

Page 30: Save Time by Managing WordPress from the Command Line

You can either write them as a plugin, or include it using the

—require parameter on the command line.

Community Commands

Page 31: Save Time by Managing WordPress from the Command Line

Thank you! !

E-Mail: [email protected] Twitter: @shawnhooper

!

http://5sen.se/wpcli/