SlideShare a Scribd company logo
Take Command ofWordPressWith
WP-CLI
Diana Thompson
San Jose WordPress Meetup
September 3, 2019
https://diana.fyi/wp-cli-sjwp
About
Diana Thompson
Pronouns: she/her or they/them
Like the Goddess
likethegoddess.com
@likethegoddess
hi@diana.fyi
Agenda
1. WP-CLI: What and Why
2. Installation
3. Commands
a. Commands that mirror wp-admin functionality
b. “Behind the Scenes” commands
4. Configuration
5. Packages
6. Writing Commands
What isWP-CLI?
WP-CLI is the official command line
interface for WordPress.
What’s a command line interface?
A command-line interface…is a means of
program where the user issues commands to the
of successive lines of text. (Wikipedia)
WhyWP-CLI?
1. Execute tasks faster
2. Get more capabilities than the wp-admin
GETTING
STARTED
Let’s go!
Requirements
• UNIX-like server environment
• PHP 5.4 or later
• WordPress 3.7 or later
• Terminal app: native apps, PuTTY
• SSH access
WP-CLI Installation
1) Download wp-cli.phar
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-
cli.phar
2) Confirm it works
$ php wp-cli.phar --info
3) Enable use wp instead of php wp-cli.phar
$ chmod +x wp-cli.phar
$ sudo mv wp-cli.phar /usr/local/bin/wp
4) Confirm successful installation
$ wp --info
https://make.wordpress.org/cli/handbook/installing/
Navigation
pwd print working directory
ls list segments (non-OS
contents)
cd change directory
../ parent directory
/ system root
- last directory
~ home directory
Up arrow key to review and execute previous
commands
Tab to autocomplete options Requires
installation to work
in WP-CLI.
https://wp-cli.org/#tab-completions
WP-CLI Syntax
$ wp command subcommand [value] [--argument]
Examples:
$ wp core download
$ wp plugin update --all
$ wp theme install twentynineteen --activate
https://developer.wordpress.org/cli/commands/
Global Parameters
Perform operation against a remote server over SSH
--ssh=[<scheme>:][<user>@]<host|container>[:<port>][<path>]
Path to the WordPress files
--path=<path>
Suppress informational messages
--silent
Prompt the user to enter values for all arguments
--prompt
https://make.wordpress.org/cli/handbook/config/#global-parameters
COMMANDS Mirroring the GUI
Core
Download core
$ wp core download
Check for available core update
$ wp core check-update
Update WordPress
$ wp core update
https://developer.wordpress.org/cli/commands/core/
Themes
List themes
$ wp theme list
Install and activate a theme from wp theme repository
$ wp theme install twentynineteen --activate
Update themes
$ wp theme update twentynineteen
$ wp theme update twentynineteen twentyseventeen twentysixteen
$ wp theme update --all
https://developer.wordpress.org/cli/commands/theme/
Plugins
List plugins
$ wp plugin list
Install a plugin from wp plugin repository
$ wp plugin install akismet –-activate
Update plugins
$ wp plugin update akismet
$ wp plugin update akismet wp-super-cache woocommerce
$ wp plugin update --all
https://developer.wordpress.org/cli/commands/plugin/
Combine Commands with Pipes
Update core, all plugins, and all themes
$ wp core update | wp theme update --all | wp plugin
update --all
Users
List users
$ wp user list
Reset user password
$ wp user reset-password john
$ wp user reset-password
john@example.com
ann@example.com
$ wp user reset-password 1
2 3
Create user
$ wp user create ann
ann@example.com --porcelain
--send-email
Delete user
$ wp user delete john
--reassign=lynn
$ wp user delete john@example.com
ann@example.com
--reassign=lynn@example.com
$ wp user delete 1 2 3
--reassign=4
https://developer.wordpress.org/cli/commands/user/
Take Command of WordPress With WP-CLI
COMMANDS Behind the Scenes
WordPress Installation
1. wp db create –-dbuser=db-username --dbpass=db-password
2. wp core download
3. wp config create --dbname=database-name
--dbuser=dbuser --dbpass=db-password
--dbhost=hostname --dbprefix=prfx_
4. wp core install --url=example.com
--title="Site Title" --admin_user=username
--admin_email=admin@example.com
--prompt=admin_password < admin_password.txt
Users
Generate users
$ wp user generate --count=5 --role=editor
Mark user as spam
$ wp user spam 123
Unmark user as spam
$ wp user unspam 123
https://developer.wordpress.org/cli/commands/user/
User Capabilities
List a user’s capabilities
$ wp user list-caps 21
Add a capability to user
$ wp user add-cap johnsmith edit_product
Remove a capability to user
$ wp user remove-cap john@smith.com publish_newsletters
https://developer.wordpress.org/cli/commands/user/
Role Capabilities
List the capabilities of a role, sorted alphabetically
$ wp cap list 'author' | sort
Add a capability to a role
$ wp cap add author spectate
Remove a capability from a role
$ wp cap remove author spectate
https://developer.wordpress.org/cli/commands/cap/
Roles
Create a role
$ wp role create productadmin "Product Administrator"
Delete a role
$ wp role delete productadmin
Reset roles
$ wp role reset administrator
$ wp role reset administrator author contributor
$ wp role reset --all
https://developer.wordpress.org/cli/commands/role/
Posts and Pages
Generate posts
$ wp post generate --count=10
Generate posts
$ wp post generate --count=10 --post_type=page --
post_date=1999-01-04
Comments
Delete all spam comments
$ wp comment delete $(wp comment list --status=spam
--format=ids)
https://developer.wordpress.org/cli/commands/comment/
Media
Re-generate all thumbnails, without confirmation
$ wp media regenerate --yes
https://developer.wordpress.org/cli/commands/media/
SCAFFOLD
Themes
Plugins
Blocks
PostTypes
Taxonomies
Scaffold ChildTheme
Create child theme
$ wp scaffold child-theme my-child-theme-slug
--parent_theme=parent-theme-slug --theme_name="My Child Theme
Name" --author="My Name" --author_uri=myurl.com
--theme_uri=mythemeurl.com --activate
https://developer.wordpress.org/cli/commands/scaffold/child-theme/
Scaffold UnderscoresTheme
Create theme based on Underscores
$ wp scaffold _s my-theme-slug --theme_name="My Theme Name"
----author="My Name" --author_uri=myurl.com --sassify
--woocommerce --activate
https://developer.wordpress.org/cli/commands/scaffold/underscores
Scaffold Plugins
Generate starter code of a plugin
$ wp scaffold plugin my-plugin-slug --dir=path-to/plugins
--plugin_name="My Plugin Name" --plugin_description="My Plugin
Description" --plugin_author="My Name"
--plugin_author_uri=myurl.com --plugin_uri=mypluginurl.com
https://developer.wordpress.org/cli/commands/scaffold/plugin/
Scaffolded Plugin Contents
 bin
 tests
.distignore
.editorconfig
.gitignore
.phpcs.xml.dist
.travis.yml
Gruntfile.js
my-plugin-slug.php
package.json
phpunit.xml.dist
readme.txt
 bin
install-wp-tests.sh
 tests
bootstrap.php
test-sample.php
Scaffold Blocks
Generate a block for a theme
$ wp scaffold block my-block-slug --title=" My Block Title"
--theme=theme-slug
Generate a block for a plugin
$ wp scaffold block my-block-slug --title="My Block Title"
--plugin=plugin-slug
https://developer.wordpress.org/cli/commands/scaffold/block/
Scaffolded Block Contents
 my-block-slug
my-block-slug.php
 my-block-slug
editor.css
index.js
style.css
Scaffold PostTypes
Generate custom post type for a theme
$ wp scaffold post-type my-post-type-slug --label="My Post
Type" --theme=my-theme
Generate custom post type for a plugin
$ wp scaffold post-type my-post-type-slug --label="My Post
Type" --plugin=my-plugin
https://developer.wordpress.org/cli/commands/scaffold/post-type/
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
ScaffoldTaxonomies
Generate taxonomy for a theme
$ wp scaffold taxonomy taxonomy-slug --post_types=my-post-
type-slug > taxonomy.php --theme="twentynineteen"
Generate taxonomy for a plugin
$ wp scaffold taxonomy taxonomy-slug --post_types=my-post-
type-slug > taxonomy.php --plugin="akismet"
https://developer.wordpress.org/cli/commands/scaffold/taxonomy
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
DATABASE
Config
Search and Replace
and more
Database
Create database
$ wp db create
Reset current database
$ wp db reset --yes
Delete existing database
$ wp db drop --yes
Import database
$ wp db import wpdb.sql
Export database
$ wp db export
Open a MySQL console
$ wp db cli
https://developer.wordpress.org/cli/commands/db/
DatabaseWith mysqlcheck
Check database
$ wp db check
Optimize database
$ wp db optimize
Repair database
$ wp db repair
https://dev.mysql.com/doc/refman/8.0/en/mysqlcheck.html
Config
Create wp-config.php
$ wp config create --dbname=database-name --dbuser=db-user
--dbpass=db-password --dbhost=hostname --dbprefix=prfx_
Set constants and variables
$ wp config set WP_DEBUG true --raw
Change salt keys
$ wp config shuffle-salts
https://developer.wordpress.org/cli/commands/config/
Search and Replace
Search for staging URL and replace with production URL
$ wp search-replace 'http://example.dev' 'http://example.com'
--dry-run
Search/replace to a SQL file without transforming the database
$ wp search-replace 'http://example.dev' 'http://example.com'
--export=database.sql
Run case-insensitive regex search/replace operation
$ wp search-replace '[foo id="([0-9]+)"' '[bar id="1"' --
regex --regex-flags='i'
https://developer.wordpress.org/cli/commands/search-replace/
Rewrite
Flush rewrite rules
$ wp rewrite flush
https://developer.wordpress.org/cli/commands/rewrite/
Object Cache
Set cache
$ wp cache set my_key
my_value my_group 300
Increase cache value
$ wp cache incr my_key 2
my_group
Decrease cache value
$ wp cache decr my_key 2
my_group
Flush cache
$ wp cache flush
https://developer.wordpress.org/cli/commands/cache/
Transient Cache
Set transient
$ wp transient set my_key "test data" 3600
Delete transients
$ wp transient delete my_key
$ wp transient delete --expired
$ wp transient delete --all
https://developer.wordpress.org/cli/commands/transient/
WP-Cron
List scheduled cron events
$ wp cron event list
Schedule a new cron event
$ wp cron event schedule cron_test
Test that cron runs successfully
$ wp cron test
https://developer.wordpress.org/cli/commands/cron/
Take Command of WordPress With WP-CLI
CONFIGURATION for efficiency
and specificity
CLI Aliases
Add alias
$ wp cli alias add @staging --set-ssh=login@host --set-
path=/path/to/wp/install/ --set-user=wpcli
Create an alias group
$ wp cli alias add @ourservers --grouping=staging,production
https://developer.wordpress.org/cli/commands/cli/alias/
Executing CommandsWith Aliases
Update core on staging and production
$ wp core update @ourservers
Creating Aliases in Config Files
@staging:
ssh: username@hostname
user: username
path: /path/to/staging/install/
@production:
ssh: username@hostname
user: username
path: /path/to/production/install/
@ourservers:
- @staging
- @production
https://make.wordpress.org/cli/handbook/config/
Configuration Files
Arguments are interpreted in the following order:
1. Command-line arguments
2. wp-cli.local.yml file inside the current working directory (or upwards)
3. wp-cli.yml file inside the current working directory (or upwards)
4. ~/.wp-cli/config.yml file
5. WP-CLI defaults
https://make.wordpress.org/cli/handbook/config/
.wp-cli Folder
/home/usr/.wp-cli
 cache
 packages
config.yml
PACKAGES ExtendWP-CLI
Packages
List installed packages
$ wp package list
Install a package
$ wp package install
package-slug
Update a package
$ wp package update
package-slug
Uninstall a package
$ wp package uninstall
package-slug
https://developer.wordpress.org/cli/commands/package/
Doctor
Diagnoses problems within WordPress.
Install
$ wp package install git@github.com:wp-cli/doctor-command.git
Get list of checks wp doctor can perform
$ wp doctor list
Perform checks
$ wp doctor check core-verify-checksums
$ wp doctor check core-verify-checksums file-eval php-in-uploads
$ wp doctor check --all
https://github.com/wp-cli/doctor-command
Take Command of WordPress With WP-CLI
Profile
Helps identify where WordPress is slow.
Install
$ wp package install git@github.com:wp-cli/profile-command.git
Run command
$ wp profile stage
$ wp profile hook
$ wp profile eval
$ wp profile eval-file
https://github.com/wp-cli/profile-command
Profile Stage
Profile all stages
$ wp profile stage
Profile the bootstrap stage
$ wp profile stage bootstrap
Profile all stages with zero-ish values eliminated
$ wp profile stage --spotlight
https://developer.wordpress.org/cli/commands/profile/stage/
Profile Stage
Profile Hook
Profile all hooks
$ wp profile hook
Profile the wp_head hook
$ wp profile hook wp_head
Profile all hooks with zero-ish values eliminated
$ wp profile hook --spotlight
https://developer.wordpress.org/cli/commands/profile/hook/
Take Command of WordPress With WP-CLI
WRITING
COMMANDS
Make your own packages
Scaffold Package
1) Install Scaffold Package Command
$ wp package install git@github.com:wp-cli/scaffold-package-
command.git
2) Generate files for a basic WP-CLI command
$ wp scaffold package author/packagename
--description="My Description" --homepage=package-homepage.com
--dir=package-dir
https://github.com/wp-cli/scaffold-package-command
Scaffolded Package Content
 .github
 bin
 features
 utils
.distignore
.editorconfig
.gitignore
.travis.yml
command.php
composer.json
CONTRIBUTING.md
README.md
wp-cli.yml
command.php
HELP is available!
Resources
Within WP-CLI
$ wp help
$ wp help <command>
$ wp help <command> <subcommand>
On the Web
https://wp-cli.org/
THANKS!
Diana Thompson
hi@diana.fyi
@likethegoddess
https://diana.fyi/wp-cli-sjwp

More Related Content

What's hot (20)

PPTX
15.exemplu complet eloquent view add-edit-delete-search
Razvan Raducanu, PhD
 
PPTX
WordPress Plugin development
Mostafa Soufi
 
PDF
Cloud Automation with Opscode Chef
Sri Ram
 
KEY
Making WordPress Your CMS and Automatically Updating a Self Hosted WordPress ...
cehwitham
 
PPTX
Laravel - Website Development in Php Framework.
SWAAM Tech
 
PPTX
Powershell: Tu nuevo mejor amigo
Gonzalo Balladares Rivera
 
PDF
WPDay Bologna 2013
Danilo Ercoli
 
PDF
Object Oriented Programming for WordPress Plugin Development
mtoppa
 
PPTX
Laravel5 Introduction and essentials
Pramod Kadam
 
KEY
LvivPy - Flask in details
Max Klymyshyn
 
PDF
Quick flask an intro to flask
juzten
 
PDF
Intro to Laravel 4
Singapore PHP User Group
 
PPTX
Laravel Beginners Tutorial 1
Vikas Chauhan
 
PDF
Laravel 101
Commit University
 
PDF
Remote Control WordPress
Edmund Turbin
 
PPT
MySQL crash course by moshe kaplan
Moshe Kaplan
 
PPT
Migraine Drupal - syncing your staging and live sites
drupalindia
 
PDF
Build website in_django
swee meng ng
 
PPTX
Flask
Mamta Kumari
 
PPTX
Using WordPress as your application stack
Paul Bearne
 
15.exemplu complet eloquent view add-edit-delete-search
Razvan Raducanu, PhD
 
WordPress Plugin development
Mostafa Soufi
 
Cloud Automation with Opscode Chef
Sri Ram
 
Making WordPress Your CMS and Automatically Updating a Self Hosted WordPress ...
cehwitham
 
Laravel - Website Development in Php Framework.
SWAAM Tech
 
Powershell: Tu nuevo mejor amigo
Gonzalo Balladares Rivera
 
WPDay Bologna 2013
Danilo Ercoli
 
Object Oriented Programming for WordPress Plugin Development
mtoppa
 
Laravel5 Introduction and essentials
Pramod Kadam
 
LvivPy - Flask in details
Max Klymyshyn
 
Quick flask an intro to flask
juzten
 
Intro to Laravel 4
Singapore PHP User Group
 
Laravel Beginners Tutorial 1
Vikas Chauhan
 
Laravel 101
Commit University
 
Remote Control WordPress
Edmund Turbin
 
MySQL crash course by moshe kaplan
Moshe Kaplan
 
Migraine Drupal - syncing your staging and live sites
drupalindia
 
Build website in_django
swee meng ng
 
Using WordPress as your application stack
Paul Bearne
 

Similar to Take Command of WordPress With WP-CLI (20)

PDF
A Better WordPress Workflow with WP-CLI
Rikesh Ramlochund
 
PDF
Introduction to WP-CLI: Manage WordPress from the command line
Behzod Saidov
 
PPTX
Saving Time with WP-CLI
Taylor Lovett
 
PDF
The Themer's Guide to WP-CLI
Edmund Turbin
 
PDF
The Themer's Guide to WP-CLI
Edmund Turbin
 
PDF
WP-CLI - WordCamp Miami 2015
Shawn Hooper
 
PDF
Getting Started with WP-CLI, a tool to automate your life
AJ Morris
 
PPTX
WordPress CLI in-depth
Sanjay Willie
 
PDF
Command Line WordPress with WP-CLI
James Collins
 
PDF
WP-CLI Talk from WordCamp Montreal
Shawn Hooper
 
PPTX
Aditya Shah - WPCLI - WordCamp Asia
Aditya Shah
 
PDF
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Andrea Cardinali
 
PPTX
A quick preview of WP CLI - Chennai WordPress Meetup
Sudar Muthu
 
PDF
Save Time by Managing WordPress from the Command Line
Shawn Hooper
 
PDF
Make your life easy with WP-CLI
Michael Corkum
 
ODP
Administer WordPress with WP-CLI
Suwash Kunwar
 
PDF
Bending word press to your will
Tom Jenkins
 
PPTX
WP-CLI - A Good Friend of Developer
Chandra Patel
 
PDF
WP-CLI Presentation from WordCamp NYC 2015
Shawn Hooper
 
PPTX
Wordpress
samirlakhanistb
 
A Better WordPress Workflow with WP-CLI
Rikesh Ramlochund
 
Introduction to WP-CLI: Manage WordPress from the command line
Behzod Saidov
 
Saving Time with WP-CLI
Taylor Lovett
 
The Themer's Guide to WP-CLI
Edmund Turbin
 
The Themer's Guide to WP-CLI
Edmund Turbin
 
WP-CLI - WordCamp Miami 2015
Shawn Hooper
 
Getting Started with WP-CLI, a tool to automate your life
AJ Morris
 
WordPress CLI in-depth
Sanjay Willie
 
Command Line WordPress with WP-CLI
James Collins
 
WP-CLI Talk from WordCamp Montreal
Shawn Hooper
 
Aditya Shah - WPCLI - WordCamp Asia
Aditya Shah
 
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Andrea Cardinali
 
A quick preview of WP CLI - Chennai WordPress Meetup
Sudar Muthu
 
Save Time by Managing WordPress from the Command Line
Shawn Hooper
 
Make your life easy with WP-CLI
Michael Corkum
 
Administer WordPress with WP-CLI
Suwash Kunwar
 
Bending word press to your will
Tom Jenkins
 
WP-CLI - A Good Friend of Developer
Chandra Patel
 
WP-CLI Presentation from WordCamp NYC 2015
Shawn Hooper
 
Wordpress
samirlakhanistb
 
Ad

Recently uploaded (20)

PDF
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
PDF
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
PPTX
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PDF
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
Ad

Take Command of WordPress With WP-CLI

  • 1. Take Command ofWordPressWith WP-CLI Diana Thompson San Jose WordPress Meetup September 3, 2019 https://diana.fyi/wp-cli-sjwp
  • 2. About Diana Thompson Pronouns: she/her or they/them Like the Goddess likethegoddess.com @likethegoddess [email protected]
  • 3. Agenda 1. WP-CLI: What and Why 2. Installation 3. Commands a. Commands that mirror wp-admin functionality b. “Behind the Scenes” commands 4. Configuration 5. Packages 6. Writing Commands
  • 4. What isWP-CLI? WP-CLI is the official command line interface for WordPress. What’s a command line interface? A command-line interface…is a means of program where the user issues commands to the of successive lines of text. (Wikipedia)
  • 5. WhyWP-CLI? 1. Execute tasks faster 2. Get more capabilities than the wp-admin
  • 7. Requirements • UNIX-like server environment • PHP 5.4 or later • WordPress 3.7 or later • Terminal app: native apps, PuTTY • SSH access
  • 8. WP-CLI Installation 1) Download wp-cli.phar $ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp- cli.phar 2) Confirm it works $ php wp-cli.phar --info 3) Enable use wp instead of php wp-cli.phar $ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp 4) Confirm successful installation $ wp --info https://make.wordpress.org/cli/handbook/installing/
  • 9. Navigation pwd print working directory ls list segments (non-OS contents) cd change directory ../ parent directory / system root - last directory ~ home directory Up arrow key to review and execute previous commands Tab to autocomplete options Requires installation to work in WP-CLI. https://wp-cli.org/#tab-completions
  • 10. WP-CLI Syntax $ wp command subcommand [value] [--argument] Examples: $ wp core download $ wp plugin update --all $ wp theme install twentynineteen --activate https://developer.wordpress.org/cli/commands/
  • 11. Global Parameters Perform operation against a remote server over SSH --ssh=[<scheme>:][<user>@]<host|container>[:<port>][<path>] Path to the WordPress files --path=<path> Suppress informational messages --silent Prompt the user to enter values for all arguments --prompt https://make.wordpress.org/cli/handbook/config/#global-parameters
  • 13. Core Download core $ wp core download Check for available core update $ wp core check-update Update WordPress $ wp core update https://developer.wordpress.org/cli/commands/core/
  • 14. Themes List themes $ wp theme list Install and activate a theme from wp theme repository $ wp theme install twentynineteen --activate Update themes $ wp theme update twentynineteen $ wp theme update twentynineteen twentyseventeen twentysixteen $ wp theme update --all https://developer.wordpress.org/cli/commands/theme/
  • 15. Plugins List plugins $ wp plugin list Install a plugin from wp plugin repository $ wp plugin install akismet –-activate Update plugins $ wp plugin update akismet $ wp plugin update akismet wp-super-cache woocommerce $ wp plugin update --all https://developer.wordpress.org/cli/commands/plugin/
  • 16. Combine Commands with Pipes Update core, all plugins, and all themes $ wp core update | wp theme update --all | wp plugin update --all
  • 17. Users List users $ wp user list Reset user password $ wp user reset-password john $ wp user reset-password [email protected] [email protected] $ wp user reset-password 1 2 3 Create user $ wp user create ann [email protected] --porcelain --send-email Delete user $ wp user delete john --reassign=lynn $ wp user delete [email protected] [email protected] [email protected] $ wp user delete 1 2 3 --reassign=4 https://developer.wordpress.org/cli/commands/user/
  • 20. WordPress Installation 1. wp db create –-dbuser=db-username --dbpass=db-password 2. wp core download 3. wp config create --dbname=database-name --dbuser=dbuser --dbpass=db-password --dbhost=hostname --dbprefix=prfx_ 4. wp core install --url=example.com --title="Site Title" --admin_user=username [email protected] --prompt=admin_password < admin_password.txt
  • 21. Users Generate users $ wp user generate --count=5 --role=editor Mark user as spam $ wp user spam 123 Unmark user as spam $ wp user unspam 123 https://developer.wordpress.org/cli/commands/user/
  • 22. User Capabilities List a user’s capabilities $ wp user list-caps 21 Add a capability to user $ wp user add-cap johnsmith edit_product Remove a capability to user $ wp user remove-cap [email protected] publish_newsletters https://developer.wordpress.org/cli/commands/user/
  • 23. Role Capabilities List the capabilities of a role, sorted alphabetically $ wp cap list 'author' | sort Add a capability to a role $ wp cap add author spectate Remove a capability from a role $ wp cap remove author spectate https://developer.wordpress.org/cli/commands/cap/
  • 24. Roles Create a role $ wp role create productadmin "Product Administrator" Delete a role $ wp role delete productadmin Reset roles $ wp role reset administrator $ wp role reset administrator author contributor $ wp role reset --all https://developer.wordpress.org/cli/commands/role/
  • 25. Posts and Pages Generate posts $ wp post generate --count=10 Generate posts $ wp post generate --count=10 --post_type=page -- post_date=1999-01-04
  • 26. Comments Delete all spam comments $ wp comment delete $(wp comment list --status=spam --format=ids) https://developer.wordpress.org/cli/commands/comment/
  • 27. Media Re-generate all thumbnails, without confirmation $ wp media regenerate --yes https://developer.wordpress.org/cli/commands/media/
  • 29. Scaffold ChildTheme Create child theme $ wp scaffold child-theme my-child-theme-slug --parent_theme=parent-theme-slug --theme_name="My Child Theme Name" --author="My Name" --author_uri=myurl.com --theme_uri=mythemeurl.com --activate https://developer.wordpress.org/cli/commands/scaffold/child-theme/
  • 30. Scaffold UnderscoresTheme Create theme based on Underscores $ wp scaffold _s my-theme-slug --theme_name="My Theme Name" ----author="My Name" --author_uri=myurl.com --sassify --woocommerce --activate https://developer.wordpress.org/cli/commands/scaffold/underscores
  • 31. Scaffold Plugins Generate starter code of a plugin $ wp scaffold plugin my-plugin-slug --dir=path-to/plugins --plugin_name="My Plugin Name" --plugin_description="My Plugin Description" --plugin_author="My Name" --plugin_author_uri=myurl.com --plugin_uri=mypluginurl.com https://developer.wordpress.org/cli/commands/scaffold/plugin/
  • 32. Scaffolded Plugin Contents  bin  tests .distignore .editorconfig .gitignore .phpcs.xml.dist .travis.yml Gruntfile.js my-plugin-slug.php package.json phpunit.xml.dist readme.txt  bin install-wp-tests.sh  tests bootstrap.php test-sample.php
  • 33. Scaffold Blocks Generate a block for a theme $ wp scaffold block my-block-slug --title=" My Block Title" --theme=theme-slug Generate a block for a plugin $ wp scaffold block my-block-slug --title="My Block Title" --plugin=plugin-slug https://developer.wordpress.org/cli/commands/scaffold/block/
  • 34. Scaffolded Block Contents  my-block-slug my-block-slug.php  my-block-slug editor.css index.js style.css
  • 35. Scaffold PostTypes Generate custom post type for a theme $ wp scaffold post-type my-post-type-slug --label="My Post Type" --theme=my-theme Generate custom post type for a plugin $ wp scaffold post-type my-post-type-slug --label="My Post Type" --plugin=my-plugin https://developer.wordpress.org/cli/commands/scaffold/post-type/
  • 38. ScaffoldTaxonomies Generate taxonomy for a theme $ wp scaffold taxonomy taxonomy-slug --post_types=my-post- type-slug > taxonomy.php --theme="twentynineteen" Generate taxonomy for a plugin $ wp scaffold taxonomy taxonomy-slug --post_types=my-post- type-slug > taxonomy.php --plugin="akismet" https://developer.wordpress.org/cli/commands/scaffold/taxonomy
  • 42. Database Create database $ wp db create Reset current database $ wp db reset --yes Delete existing database $ wp db drop --yes Import database $ wp db import wpdb.sql Export database $ wp db export Open a MySQL console $ wp db cli https://developer.wordpress.org/cli/commands/db/
  • 43. DatabaseWith mysqlcheck Check database $ wp db check Optimize database $ wp db optimize Repair database $ wp db repair https://dev.mysql.com/doc/refman/8.0/en/mysqlcheck.html
  • 44. Config Create wp-config.php $ wp config create --dbname=database-name --dbuser=db-user --dbpass=db-password --dbhost=hostname --dbprefix=prfx_ Set constants and variables $ wp config set WP_DEBUG true --raw Change salt keys $ wp config shuffle-salts https://developer.wordpress.org/cli/commands/config/
  • 45. Search and Replace Search for staging URL and replace with production URL $ wp search-replace 'http://example.dev' 'http://example.com' --dry-run Search/replace to a SQL file without transforming the database $ wp search-replace 'http://example.dev' 'http://example.com' --export=database.sql Run case-insensitive regex search/replace operation $ wp search-replace '[foo id="([0-9]+)"' '[bar id="1"' -- regex --regex-flags='i' https://developer.wordpress.org/cli/commands/search-replace/
  • 46. Rewrite Flush rewrite rules $ wp rewrite flush https://developer.wordpress.org/cli/commands/rewrite/
  • 47. Object Cache Set cache $ wp cache set my_key my_value my_group 300 Increase cache value $ wp cache incr my_key 2 my_group Decrease cache value $ wp cache decr my_key 2 my_group Flush cache $ wp cache flush https://developer.wordpress.org/cli/commands/cache/
  • 48. Transient Cache Set transient $ wp transient set my_key "test data" 3600 Delete transients $ wp transient delete my_key $ wp transient delete --expired $ wp transient delete --all https://developer.wordpress.org/cli/commands/transient/
  • 49. WP-Cron List scheduled cron events $ wp cron event list Schedule a new cron event $ wp cron event schedule cron_test Test that cron runs successfully $ wp cron test https://developer.wordpress.org/cli/commands/cron/
  • 52. CLI Aliases Add alias $ wp cli alias add @staging --set-ssh=login@host --set- path=/path/to/wp/install/ --set-user=wpcli Create an alias group $ wp cli alias add @ourservers --grouping=staging,production https://developer.wordpress.org/cli/commands/cli/alias/
  • 53. Executing CommandsWith Aliases Update core on staging and production $ wp core update @ourservers
  • 54. Creating Aliases in Config Files @staging: ssh: username@hostname user: username path: /path/to/staging/install/ @production: ssh: username@hostname user: username path: /path/to/production/install/ @ourservers: - @staging - @production https://make.wordpress.org/cli/handbook/config/
  • 55. Configuration Files Arguments are interpreted in the following order: 1. Command-line arguments 2. wp-cli.local.yml file inside the current working directory (or upwards) 3. wp-cli.yml file inside the current working directory (or upwards) 4. ~/.wp-cli/config.yml file 5. WP-CLI defaults https://make.wordpress.org/cli/handbook/config/
  • 58. Packages List installed packages $ wp package list Install a package $ wp package install package-slug Update a package $ wp package update package-slug Uninstall a package $ wp package uninstall package-slug https://developer.wordpress.org/cli/commands/package/
  • 59. Doctor Diagnoses problems within WordPress. Install $ wp package install [email protected]:wp-cli/doctor-command.git Get list of checks wp doctor can perform $ wp doctor list Perform checks $ wp doctor check core-verify-checksums $ wp doctor check core-verify-checksums file-eval php-in-uploads $ wp doctor check --all https://github.com/wp-cli/doctor-command
  • 61. Profile Helps identify where WordPress is slow. Install $ wp package install [email protected]:wp-cli/profile-command.git Run command $ wp profile stage $ wp profile hook $ wp profile eval $ wp profile eval-file https://github.com/wp-cli/profile-command
  • 62. Profile Stage Profile all stages $ wp profile stage Profile the bootstrap stage $ wp profile stage bootstrap Profile all stages with zero-ish values eliminated $ wp profile stage --spotlight https://developer.wordpress.org/cli/commands/profile/stage/
  • 64. Profile Hook Profile all hooks $ wp profile hook Profile the wp_head hook $ wp profile hook wp_head Profile all hooks with zero-ish values eliminated $ wp profile hook --spotlight https://developer.wordpress.org/cli/commands/profile/hook/
  • 67. Scaffold Package 1) Install Scaffold Package Command $ wp package install [email protected]:wp-cli/scaffold-package- command.git 2) Generate files for a basic WP-CLI command $ wp scaffold package author/packagename --description="My Description" --homepage=package-homepage.com --dir=package-dir https://github.com/wp-cli/scaffold-package-command
  • 68. Scaffolded Package Content  .github  bin  features  utils .distignore .editorconfig .gitignore .travis.yml command.php composer.json CONTRIBUTING.md README.md wp-cli.yml
  • 71. Resources Within WP-CLI $ wp help $ wp help <command> $ wp help <command> <subcommand> On the Web https://wp-cli.org/

Editor's Notes

  • #2: Get slides Helicopter tour Scope, overall geography Show points of interest for further exploration Have your own adventure
  • #4: 1. Background 2. Basic Installation 3. Most of preso commands, not everything covered. No multisite 4. Configuration is not required by helpful 5. Combine commands or in some way extend WP-CLI. Go into two well-known
  • #5: Stand-alone replacement for the GUI
  • #6: We have this GUI… Replaces GUI interactions with no browser refresh Bundle tasks together Use packages Write your own commands 2. Not switching ! Do more in less time
  • #7: Requirements, Installation, Navigation, Syntax, Global parameters
  • #9: alternative installation methods (Git, Composer, Homebrew, Docker, Windows). Use URL for those
  • #10: Ask for who is using WP-CLI and command line If you’re new, good place to start. Won’t break anything.
  • #11: wp = tool, command = area, subcommand =what you’re doing Sometimes there’s a second subcommand EXAMPLES “If you know WP, you know what these do” Hierarchical structure Efficiency: Compare examples with GUI Parameters Lots of keystrokes. Opportunities to shorten that we’ll see later.
  • #12: --prompt, requires read times, cut the keystrokes in half
  • #15: List includes names, status (activated), update, version
  • #17: Go for coffee One command line to do them all
  • #18: 2. --porcelain suppressed password 3. Users by username, email, id. Reset user password sends email by default
  • #19: Add a post, edit a page, add and remove widgets
  • #20: Requirements, Installation, Navigation, Syntax, Global parameters
  • #21: 1. Last line to keep password from logging in bash history. Ctrl-C to close 2. May not be able to create db with shared hosting
  • #22: Add user list
  • #27: Format-ids not required, but with get multiple error messages
  • #28: --yes suppresses confirmation messages
  • #30: Child theme: includes style.css, function.php (enqueues scripts and styles), .editorconfig
  • #31: Same as underscores.me
  • #33: Supporting and testing files
  • #34: Adds blocks/block-name within theme/plugin
  • #36: > post-types/post-type-name.php
  • #37: Registering post type
  • #38: Creating custom messages
  • #39: > taxonomies/taxonomy-name.php
  • #40: Register post type
  • #41: Create custom messages
  • #42: What am I saying here? Scaffolding does what it does
  • #43: Reset removes all tables Drop deletes the db As before --yes surpresses confirmation messages
  • #44: Use mysqlcheck client performs table maintenance Outputs results per table Check checks for errors Optimize optimizes (incl. --optimize=true) Repair can fix almost anything except unique keys that aren't unique. (incl. --repair=true)
  • #46: Supports serialized data, but not inside a serialized object
  • #47: List, update and…
  • #50: List: shows hook, time (GMT and your time zone), and recurrence rate
  • #51: That’s the beginning As you work with WP-CLI, you may want more efficiency. Early point of verbose commands.
  • #52: You don’t have to config, but it helps
  • #53: >>>If I create an alias does it get stored in a config file? If so, which one? Does the placement of @ourservers matter? Aliases all the way down
  • #54: How does piping work?
  • #55: Is @all automatically created?
  • #57: .wp-cli is also where packages reside
  • #61: Security, performance, configuration, updates
  • #62: Look for target page for stage?? Look up hook for specifics Remind yourself #2
  • #64: Better interpretation
  • #66: Hook: also get PHP errors Export content?
  • #68: Default installs to .wp-cli/packages/local/author/
  • #72: Ctrl-C to exit help articles