WP-CLI Talk from WordCamp Montreal
-
Upload
shawn-hooper -
Category
Documents
-
view
165 -
download
0
Transcript of WP-CLI Talk from WordCamp Montreal
![Page 1: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/1.jpg)
WP-CLI: Save Time by Managing WordPress
from the Command Line
WordCamp Montreal, July 4, 2015 !
Shawn Hooper, CTO, Actionable Books @shawnhooper - [email protected]
![Page 2: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/2.jpg)
• 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: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/3.jpg)
Command Line?!
![Page 4: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/4.jpg)
• 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 5: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/5.jpg)
• Anyone really, but mostly:
• Developers
• Theme Designers
• Server Administrators
Who is this for?
![Page 6: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/6.jpg)
Don’t Fear The Command Line
![Page 7: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/7.jpg)
• http://www.wp-cli.org/
• Requires PHP 5.3.2 or later
• Requires WordPress 3.5.2 or later
• A “UNIX-like” environment:
• OSX (Macintosh)
• Linux
• Cygwin (Windows)
What do you need?
![Page 8: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/8.jpg)
• You need to have SSH access to use WP-CLI. Some shared hosting packages do not allow SSH access
• PlanetHoster, SiteGround, Pantheon, BlueHost, GoDaddy, Media Temple, Windows Azure and more now have CLI support.
• VPS services like Digital Ocean and Linode are ideal.
Hosts
![Page 9: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/9.jpg)
• Download it: curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
• Set permissions: chmod +x wp-cli.phar
• Move it somewhere useful: sudo mv wp-cli.phar /usr/local/bin/wp
Installing WP-CLI
![Page 10: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/10.jpg)
• Does it work? Type: wp
Installing WP-CLI
![Page 11: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/11.jpg)
Installing WP-CLI
![Page 12: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/12.jpg)
Congratulations! (that was the hard part)
![Page 13: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/13.jpg)
Great… It’s installed. So now what….
![Page 14: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/14.jpg)
wp <command> <sub-command> <params>
Running Commands:
![Page 15: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/15.jpg)
<param> — required
[—param] — optional flag
[—param=<value>] — optional w/ value
Running Commands:
![Page 16: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/16.jpg)
• 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 17: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/17.jpg)
• 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 --prompt
core
![Page 18: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/18.jpg)
• Install, Delete Plugins
• Activate & Deactivate Plugins
• Update Plugins
• Search the repository for plugins
plugin
![Page 19: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/19.jpg)
• Time savers! wp plugin update — all wp plugin deactivate — all
plugin
![Page 20: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/20.jpg)
The “db” command interacts with
the MySQL database.
!
wp db export backup.sql wp db import backup.sql wp db cli
db
![Page 21: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/21.jpg)
• Safe Search & Replace, including serialized arrays!
• Supports --dry-run
search-replace
![Page 22: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/22.jpg)
Generate Test Content !
wp post generate --count=500
post
![Page 23: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/23.jpg)
Regenerate Thumbnails
!
wp media regenerate —yes
media
![Page 24: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/24.jpg)
Start an underscores theme!
!
wp scaffold _s mytheme
scaffold
![Page 25: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/25.jpg)
… or a child theme
!
wp scaffold child-theme mychild —parent_theme=twentyfourteen
scaffold
![Page 26: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/26.jpg)
… or a custom post type
!
wp scaffold post-type mycpt —theme
scaffold
![Page 27: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/27.jpg)
Download & Activate a Theme from WordPress.org
!
wp theme install simone —activate
theme
![Page 28: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/28.jpg)
wp user generate
wp user import-csv
Create Users
![Page 29: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/29.jpg)
wp term list
wp term create
wp term generate
Taxonomies
![Page 30: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/30.jpg)
Executes PHP code * after loading the WordPress Core *
eval & eval-file
![Page 31: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/31.jpg)
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 32: WP-CLI Talk from WordCamp Montreal](https://reader034.fdocuments.us/reader034/viewer/2022042602/55c239cbbb61ebdf098b47b4/html5/thumbnails/32.jpg)
You can either write them as a plugin, or include it using the
—require parameter on the command line.
Community Commands