SlideShare a Scribd company logo
1 of 30
Download to read offline
INTRODUCTION TO WP-CLI:
MANAGE WORDPRESS FROM
THE COMMAND LINE
BEHZOD SAIDOV
WordCamp Riverside, 2017
https://slides.com/behzod/wprs-2017/
1
, , ,
@Behzod
Twitter Facebook WordPress.org GitHub
2xDaddy, Tech Lead, Web Developer, Geek.
Former Linux enthusiast.
2
COMMAND-LINE INTERFACE (CLI)
is a means of interacting with a computer program where the
user (or client) issues commandsto the program in the form of
successive lines of text (command lines).
~ Wikipedia
3
COMMAND PROMPT
A sequence of (one or more)
characters used in a
command-line interface to
indicate readiness to accept
commands.
It literally prompts the user to
take action.
A prompt usually ends with
one of the characters:
$, %, #, :, >
4
DEMO
Launching an application
cal
ls
date
5
ARGUMENTS
ls [OPTION]... [FILE]...
Syntax
-a, --all show hidden entries
-l use a long listing format
Options
Short & Long Options
Combined Short Options
--all -a
-a -l -al
=
=
~ Credit: Alain Schlesser6
DEMO
ls with arguments
ls -a
ls --all
ls -l
ls -la
ls -l <file_name>
7
NAVIGATION
cd [DIR]
print working directorypwd
change directory
SPECIAL DIRECTORIES
..
current directory.
parent directory
~
previous directory-
current user's home directory
8
DEMO
Navigation Commands
9
MORE COMMANDS
copy filescp
move (rename files)mv
make new directorymkdir
remove (delete) directoryrmdir
concatenate and print filecat
print first part (head) of filehead
print last part (tail) of filetail
paginate through fileless
remove (delete) filesrm
prins the string(s) to standard output.echo
displays manual pages
10
man
locate a program file in the user's pathwhich
DEMO
More Commands
cp
mv
mkdir
rmdir
cat
head
tail
less
rm
echo
man
which
11
WP-CLI
the command-line interface for WordPress
12
WHAT IS WP-CLI?
Official command line tool for interacting with and managing
your WordPress sites.
Allows you manage WordPress without going through the
browser.
Open source project backed by WordPress.org, and
collaborated on in Github.
Has an easy to use API for extending it with your own
commands.
Available from:
wp-cli.org
make.wordpress.org/cli/handbook
13
INSTALLATION
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Download
php wp-cli.phar --info
Then, check if it works:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Make the file executable and move it to somewhere in your PATH
PHP binary: /usr/bin/php5
PHP version: 5.5.9-1ubuntu4.14
php.ini used: /etc/php5/cli/php.ini
WP-CLI root dir: /home/wp-cli/.wp-cli
WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/
WP-CLI global config: /home/wp-cli/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 0.23.0
Try running wp --info. If WP-CLI is installed successfully, you’ll see
output like this:
More installation
options can be
found in the
handbook
14
WHAT CAN I DO WITH THIS?
15
MANAGE WP CORE,
THEMES, PLUGINS
# Download the latst vesrion of WordPress core
wp core download
# Download the specific version of WordPress core
wp core download --version=4.7.7
# Configure database settings
wp config create --dbname=example_website_dev --dbuser=root --dbpass=root
# Create the database
wp db create
# Install WP core
wp core install --url='http://example-website.dev' --title='Example Website' --admin_user=admin --adm
# Update WordPress Core
wp core update
# List plugins
wp plugin list
# Install a theme
wp theme install sydney --activate
16
MANAGE THE DATA
# Create a term
wp term create category News
# Get information on a user
wp user get 1
# Update information about the user
wp user update admin --user_pass=admin
# Update an option
wp option update blogdescription 'Just another Example Website'
# Create a post
wp post create --post_type=page --post_title='About us' --post_status='publish'
# Delete post ID 1
wp post delete 1
17
SEARCH & REPLACE YOUR DB
# Search and replace
$ wp search-replace 'www.example.dev' 'stage.example.dev'
# Run search/replace operation but dont save in database
$ wp search-replace 'www.example.dev' 'stage.example.dev' --dry-run
# Search and replace but skip one column
$ wp search-replace 'www.example.dev' 'stage.example.dev' --skip-columns=guid
# Search/replace to a SQL file without transforming the database
$ wp search-replace foo bar --export=database.sql
18
AUTOMATING DEPLOYMENTS OR
MAINTENANCE
# Re-generate all thumbnails, without confirmation.
wp media regenerate --yes
# Replace HTTP URLs with HTTPS URLs
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid
# Flush the object cache
wp cache flush
# Delete all transients
wp transient delete --all
19
TROUBLESHOOT WP INTERNALS
(CRON, CACHE, TRANSIENTS)
# List all registered image sizes
wp media image-size
# List of scheduled cron events
wp cron event list
# Run all cron events in queue
wp cron event run --due-now
# Flush rewrite rules
wp rewrite flush
# List of rewrites
wp rewrite list
# Flush the object cache
wp cache flush
# Delete all transients
wp transient delete --all
# Interactive PHP console for running and testing PHP code.
wp shell
20
SCAFFOLDING THEMES & PLUGINS
# Generate a new plugin with unit tests
wp scaffold plugin sample-plugin
# Generate a 'sample-theme' child theme based on TwentySixteen
wp scaffold child-theme sample-theme --parent_theme=twentysixteen
# Generate code for post type registration in given theme
wp scaffold post-type movie --label=Movie --theme=sample-theme
21
GLOBAL PARAMETERS
Argument Description
--path=<path> Path to the WordPress files.
--url=<url> Pretend request came from given URL. In multisite, this argument is how the
target site is specified.
--ssh=[<scheme>:]
[<user>@]
<host|container>[:
<port>][<path>]
Perform operation against a remote server over SSH (or a container using
scheme of “docker”, “docker-compose”, “vagrant”).
--http=<http> Perform operation against a remote WordPress install over HTTP.
--user=<id|login|email> Set the WordPress user.
--skip-plugins[=
<plugin>]
Skip loading all or some plugins. Note: mu-plugins are still loaded.
--skip-themes[=
<theme>]
Skip loading all or some themes.
--skip-packages Skip loading all installed packages.
--require=<path> Load PHP file before running the command (may be used more than once).
--[no-]color Whether to colorize the output.
--debug[=<group>] Show all PHP errors; add verbosity to WP-CLI bootstrap.
--prompt[=<assoc>] Prompt the user to enter values for all command arguments, or a subset
specified as comma-separated values.
--quiet Suppress informational messages.
22
GETTING HELP
General help screen with a list of commands *wp help
Help screen for a specific commandwp help <cmd>
* Hit q to exit the output of the help command
23
AUTOMATION
24
SETTING UP A NEW WEBSITE
FOR DEVELOPEMENT
1. Download the WP core
2. Create the database
3. Configure database settings
4. Install WP
5. Change the website's description
6. Set the time zone
7. Delete Akismet and Hello plugins
8. Install a theme from
wordpress.org theme directory
9. Create a child theme
10. Activate the child theme
11. Install required plugins for the
theme
12. Trash the 'Hello world!' post
13. Trash the 'Sample page'
14. Create some pages
15. Generate some posts with
fetched content from loripsum.net.
16. Create a menu
17. Assign a location to the menu.
18. Add all pages to the main menu
25
YOU CAN WRITE
A SCRIPT FOR THIS!
26
DEMO
Sample Script
See/Download @ GitHub
27
THERE IS MORE YOU CAN DO
Configuration files (wp-cli.yml)
aliases for all of your environments
parameter and command defaults
Extend WP-CLI:
WP-CLI packages
Create your own commands
And this is not all
28
LEARN MORE
WP-CLI Handbook
https://make.wordpress.org/cli/handbook/
29
THANK YOU!
Behzod Saidov
behzodsaidov@gmail.com
@Behzod
https://slides.com/behzod/wprs-2017/
30

More Related Content

What's hot

Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient waySylvain Rayé
 
Create your own composer package
Create your own composer packageCreate your own composer package
Create your own composer packageLattapon Yodsuwan
 
PM : code faster
PM : code fasterPM : code faster
PM : code fasterPHPPRO
 
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Japheth Thomson
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake TutorialFu Haiping
 
Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersChang W. Doh
 
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerWordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerJeremy Ward
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Combell NV
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with ComposerJason Grimes
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019Karthik Sekhar
 
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Acquia
 
Playing with WP-CLI (WordPress Command Line Interface)
Playing with WP-CLI (WordPress Command Line Interface)Playing with WP-CLI (WordPress Command Line Interface)
Playing with WP-CLI (WordPress Command Line Interface)Anam Ahmed
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPANbrian d foy
 
How to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of DevelopmentHow to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of DevelopmentAcquia
 
Composer is the new Drush - Drupal Developer Training (internal)
Composer is the new Drush - Drupal Developer Training (internal)Composer is the new Drush - Drupal Developer Training (internal)
Composer is the new Drush - Drupal Developer Training (internal)Exove
 

What's hot (20)

Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
Create your own composer package
Create your own composer packageCreate your own composer package
Create your own composer package
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 
Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
 
Creating custom themes in AtoM
Creating custom themes in AtoMCreating custom themes in AtoM
Creating custom themes in AtoM
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake Tutorial
 
Composer
ComposerComposer
Composer
 
Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for Beginners
 
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerWordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
 
Effective CMake
Effective CMakeEffective CMake
Effective CMake
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
 
Installing AtoM with Ansible
Installing AtoM with AnsibleInstalling AtoM with Ansible
Installing AtoM with Ansible
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019
 
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
 
Playing with WP-CLI (WordPress Command Line Interface)
Playing with WP-CLI (WordPress Command Line Interface)Playing with WP-CLI (WordPress Command Line Interface)
Playing with WP-CLI (WordPress Command Line Interface)
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
 
How to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of DevelopmentHow to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of Development
 
Composer is the new Drush - Drupal Developer Training (internal)
Composer is the new Drush - Drupal Developer Training (internal)Composer is the new Drush - Drupal Developer Training (internal)
Composer is the new Drush - Drupal Developer Training (internal)
 

Similar to Introduction to WP-CLI: Manage WordPress from the command line

Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLIDiana Thompson
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)LumoSpark
 
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Andrea Cardinali
 
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Alan Pinstein
 
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-NapocaWP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-Napoca4nd4p0p
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLIDiana Thompson
 
Remote Control WordPress
Remote Control WordPressRemote Control WordPress
Remote Control WordPressEdmund Turbin
 
Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLISuwash Kunwar
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressJeroen van Dijk
 
Command line for the beginner - Using the command line in developing for the...
Command line for the beginner -  Using the command line in developing for the...Command line for the beginner -  Using the command line in developing for the...
Command line for the beginner - Using the command line in developing for the...Jim Birch
 
Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Ben Hall
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIWP Engine
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slidesDocker, Inc.
 
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google CloudDrupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google CloudDropsolid
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...Puppet
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configurationlutter
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comInstaWP Inc
 
Do more, faster, by extending WP-CLI
Do more, faster, by extending WP-CLIDo more, faster, by extending WP-CLI
Do more, faster, by extending WP-CLIdrywallbmb
 

Similar to Introduction to WP-CLI: Manage WordPress from the command line (20)

Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)
 
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
 
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
 
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-NapocaWP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Remote Control WordPress
Remote Control WordPressRemote Control WordPress
Remote Control WordPress
 
Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLI
 
WP-CLI: Unleash the power
WP-CLI: Unleash the powerWP-CLI: Unleash the power
WP-CLI: Unleash the power
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 
Command line for the beginner - Using the command line in developing for the...
Command line for the beginner -  Using the command line in developing for the...Command line for the beginner -  Using the command line in developing for the...
Command line for the beginner - Using the command line in developing for the...
 
Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLI
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google CloudDrupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
 
Do more, faster, by extending WP-CLI
Do more, faster, by extending WP-CLIDo more, faster, by extending WP-CLI
Do more, faster, by extending WP-CLI
 

Recently uploaded

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 

Recently uploaded (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 

Introduction to WP-CLI: Manage WordPress from the command line

  • 1. INTRODUCTION TO WP-CLI: MANAGE WORDPRESS FROM THE COMMAND LINE BEHZOD SAIDOV WordCamp Riverside, 2017 https://slides.com/behzod/wprs-2017/ 1
  • 2. , , , @Behzod Twitter Facebook WordPress.org GitHub 2xDaddy, Tech Lead, Web Developer, Geek. Former Linux enthusiast. 2
  • 3. COMMAND-LINE INTERFACE (CLI) is a means of interacting with a computer program where the user (or client) issues commandsto the program in the form of successive lines of text (command lines). ~ Wikipedia 3
  • 4. COMMAND PROMPT A sequence of (one or more) characters used in a command-line interface to indicate readiness to accept commands. It literally prompts the user to take action. A prompt usually ends with one of the characters: $, %, #, :, > 4
  • 6. ARGUMENTS ls [OPTION]... [FILE]... Syntax -a, --all show hidden entries -l use a long listing format Options Short & Long Options Combined Short Options --all -a -a -l -al = = ~ Credit: Alain Schlesser6
  • 7. DEMO ls with arguments ls -a ls --all ls -l ls -la ls -l <file_name> 7
  • 8. NAVIGATION cd [DIR] print working directorypwd change directory SPECIAL DIRECTORIES .. current directory. parent directory ~ previous directory- current user's home directory 8
  • 10. MORE COMMANDS copy filescp move (rename files)mv make new directorymkdir remove (delete) directoryrmdir concatenate and print filecat print first part (head) of filehead print last part (tail) of filetail paginate through fileless remove (delete) filesrm prins the string(s) to standard output.echo displays manual pages 10 man locate a program file in the user's pathwhich
  • 13. WHAT IS WP-CLI? Official command line tool for interacting with and managing your WordPress sites. Allows you manage WordPress without going through the browser. Open source project backed by WordPress.org, and collaborated on in Github. Has an easy to use API for extending it with your own commands. Available from: wp-cli.org make.wordpress.org/cli/handbook 13
  • 14. INSTALLATION curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar Download php wp-cli.phar --info Then, check if it works: chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp Make the file executable and move it to somewhere in your PATH PHP binary: /usr/bin/php5 PHP version: 5.5.9-1ubuntu4.14 php.ini used: /etc/php5/cli/php.ini WP-CLI root dir: /home/wp-cli/.wp-cli WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/ WP-CLI global config: /home/wp-cli/.wp-cli/config.yml WP-CLI project config: WP-CLI version: 0.23.0 Try running wp --info. If WP-CLI is installed successfully, you’ll see output like this: More installation options can be found in the handbook 14
  • 15. WHAT CAN I DO WITH THIS? 15
  • 16. MANAGE WP CORE, THEMES, PLUGINS # Download the latst vesrion of WordPress core wp core download # Download the specific version of WordPress core wp core download --version=4.7.7 # Configure database settings wp config create --dbname=example_website_dev --dbuser=root --dbpass=root # Create the database wp db create # Install WP core wp core install --url='http://example-website.dev' --title='Example Website' --admin_user=admin --adm # Update WordPress Core wp core update # List plugins wp plugin list # Install a theme wp theme install sydney --activate 16
  • 17. MANAGE THE DATA # Create a term wp term create category News # Get information on a user wp user get 1 # Update information about the user wp user update admin --user_pass=admin # Update an option wp option update blogdescription 'Just another Example Website' # Create a post wp post create --post_type=page --post_title='About us' --post_status='publish' # Delete post ID 1 wp post delete 1 17
  • 18. SEARCH & REPLACE YOUR DB # Search and replace $ wp search-replace 'www.example.dev' 'stage.example.dev' # Run search/replace operation but dont save in database $ wp search-replace 'www.example.dev' 'stage.example.dev' --dry-run # Search and replace but skip one column $ wp search-replace 'www.example.dev' 'stage.example.dev' --skip-columns=guid # Search/replace to a SQL file without transforming the database $ wp search-replace foo bar --export=database.sql 18
  • 19. AUTOMATING DEPLOYMENTS OR MAINTENANCE # Re-generate all thumbnails, without confirmation. wp media regenerate --yes # Replace HTTP URLs with HTTPS URLs wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid # Flush the object cache wp cache flush # Delete all transients wp transient delete --all 19
  • 20. TROUBLESHOOT WP INTERNALS (CRON, CACHE, TRANSIENTS) # List all registered image sizes wp media image-size # List of scheduled cron events wp cron event list # Run all cron events in queue wp cron event run --due-now # Flush rewrite rules wp rewrite flush # List of rewrites wp rewrite list # Flush the object cache wp cache flush # Delete all transients wp transient delete --all # Interactive PHP console for running and testing PHP code. wp shell 20
  • 21. SCAFFOLDING THEMES & PLUGINS # Generate a new plugin with unit tests wp scaffold plugin sample-plugin # Generate a 'sample-theme' child theme based on TwentySixteen wp scaffold child-theme sample-theme --parent_theme=twentysixteen # Generate code for post type registration in given theme wp scaffold post-type movie --label=Movie --theme=sample-theme 21
  • 22. GLOBAL PARAMETERS Argument Description --path=<path> Path to the WordPress files. --url=<url> Pretend request came from given URL. In multisite, this argument is how the target site is specified. --ssh=[<scheme>:] [<user>@] <host|container>[: <port>][<path>] Perform operation against a remote server over SSH (or a container using scheme of “docker”, “docker-compose”, “vagrant”). --http=<http> Perform operation against a remote WordPress install over HTTP. --user=<id|login|email> Set the WordPress user. --skip-plugins[= <plugin>] Skip loading all or some plugins. Note: mu-plugins are still loaded. --skip-themes[= <theme>] Skip loading all or some themes. --skip-packages Skip loading all installed packages. --require=<path> Load PHP file before running the command (may be used more than once). --[no-]color Whether to colorize the output. --debug[=<group>] Show all PHP errors; add verbosity to WP-CLI bootstrap. --prompt[=<assoc>] Prompt the user to enter values for all command arguments, or a subset specified as comma-separated values. --quiet Suppress informational messages. 22
  • 23. GETTING HELP General help screen with a list of commands *wp help Help screen for a specific commandwp help <cmd> * Hit q to exit the output of the help command 23
  • 25. SETTING UP A NEW WEBSITE FOR DEVELOPEMENT 1. Download the WP core 2. Create the database 3. Configure database settings 4. Install WP 5. Change the website's description 6. Set the time zone 7. Delete Akismet and Hello plugins 8. Install a theme from wordpress.org theme directory 9. Create a child theme 10. Activate the child theme 11. Install required plugins for the theme 12. Trash the 'Hello world!' post 13. Trash the 'Sample page' 14. Create some pages 15. Generate some posts with fetched content from loripsum.net. 16. Create a menu 17. Assign a location to the menu. 18. Add all pages to the main menu 25
  • 26. YOU CAN WRITE A SCRIPT FOR THIS! 26
  • 28. THERE IS MORE YOU CAN DO Configuration files (wp-cli.yml) aliases for all of your environments parameter and command defaults Extend WP-CLI: WP-CLI packages Create your own commands And this is not all 28