SlideShare a Scribd company logo
1 of 29
Download to read offline
A better WordPress
workflow with WP-CLI
By Rikesh Ramlochund
WP-CLI
› WP-CLI is a set of command-line tools for managing
WordPress installations
› Install a WordPress website
› Update WordPress core, plugins, and themes
› Automate repetitive tasks
› Make your own commands
› ssh on your server and run the commands
WP-CLI Installation
› Installation and upgrade: https://wp-cli.org/
› Download the wp-cli.phar file

curl -O https://raw.githubusercontent.com/
wp-cli/builds/gh-pages/phar/wp-cli.phar
› Check if the file works

php wp-cli.phar —-info
WP-CLI Installation
› To be able to type just wp, instead of php wp-cli.phar, you
need to make the file executable and move it to
somewhere in your PATH.
› chmod +x wp-cli.phar
› sudo mv wp-cli.phar /usr/local/bin/wp
› wp —-info
WP-CLI Installation
› WP-CLI can also be installed via Composer or Homebrew
› Debian and Ubuntu users can install WP-CLI via a .deb
package
› WP-CLI can also be installed on Windows
› Read more about WP-CLI Installation: https://wp-cli.org/
docs/installing/
WP-CLI Command Anatomy
› wp plugin install jetpack
› wp: All WP-CLI commands start with wp
› plugin: command
› install: subcommand
› jetpack: options/parameters (here it is a plugin name)
Node.js Wrapper
› npm install wp-cli



Node wrapper for Wordpress CLI with functionality
matching the WP-CLI API.

Learn more: https://www.npmjs.com/package/wp-cli
Installing WordPress using WP-CLI
› Download the WordPress core:

wp core download

or

wp core download —-locale=fr_FR
Installing WordPress using WP-CLI
› Generate the wp-config.php file

wp core config --dbname=devconwp 

--dbuser=devcon --dbpass=somePassword
› Create the database file (dbname value from command
above)

wp db create
Installing WordPress using WP-CLI
› Run the WordPress installation process

wp core install —-prompt
› Installation done :)
› Note: ——prompt is a global parameter of WP-CLI, and it
prompts the user to enter values for all command
arguments
Installing WordPress using WP-CLI
› Recap:
› wp core download
› wp core config --dbname=devconwp 

--dbuser=devcon —-dbpass=somePassword
› wp db create
› wp core install —-prompt
WordPress Core commands
› Check for update via Version Check API

wp core check-update
› Update WordPress

wp core update and wp core update-db
› Verify WordPress files against wordpress.org checksums

wp core verify-checksums
› Display the WordPress version

wp core version
Plugin Management
› List all plugins

wp plugin list
› List plugins with pending updates

wp plugin list —-update=available
› Plugin Installation

wp plugin install advanced-custom-fields

wp plugin install jetpack —-version=“3.6”

wp plugin install my-plugin.zip
Plugin Management
› Install premium plugins via zip file.
› Advanced Custom Fields Pro allows you to download a zip
file using your private key
› wget -v -O acf-pro.zip “http://
connect.advancedcustomfields.com/index.php?
p=pro&a=download&k=YOUR_ACF_PRO_KEY”
› wp plugin install acf-pro.zip --activate
› rm acf-pro.zip
Plugin Management
› Some plugins like Jetpack also implement WP-CLI
commands.
› For example:

wp jetpack status

wp jetpack module list

wp jetpack module activate carousel
Plugin Management
› Activate a plugin

wp plugin activate jetpack
› Deactivate a plugin

wp plugin deactivate jetpack
› Update all plugins

wp plugin update --all
WordPress Maintenance
› Keeping WordPress up to date
› wp core update
› wp core update-db
› wp plugins update --all
› wp theme update --all
› Don’t forget to backup your files before doing updates!
WordPress Backups
› Export WordPress database via WP-CLI

wp db export
› Compress the WordPress directory

tar -vczf backup.gz .
Database Migration
› Moving a WordPress installation to another server (eg.
staging to production)
› Step 1: Export staging database

wp db export
› Step 2: Move database to production and import

wp db import
› Step 3: Update URLs from staging to production

wp search-replace “http://
staging.example.com” “http://example.com”
Managing Options
› Read option value

wp option get blogname
› Update option value

wp option update blogname “Awesome WP”
› Delete option

wp option delete optional
› List options

wp option list
Useful Commands
› Regenerate thumbnails

wp media regenerate
› Generate x posts, using some Lorem Ipsum text

curl http://loripsum.net/api/5 | wp post
generate --post_content --count=x
› Run a query saved in a file

wp db query < debug.sql
› Command helper

wp help plugin install
Useful Commands
› Import WXR file

wp import posts.xml
› Bulk importing images as attachments

Import all JPGs from the user’s Pictures directory

wp media import ~/Pictures/**/*.jpg
› Import a specific image and assign it as post thumbnail for
that post

wp media import ~/Downloads/image.png --
post_id=123 --title="A downloaded picture"
--featured_image
Useful Commands
› Delete all transients

wp transient delete-all
› Delete all expired transients

wp transient delete-expired
› List registered post types

wp post-type list
Useful Commands
› Update user password

wp user update 1 —-user_pass=newpass
› List all posts

wp post list
› List all users

wp user list
Scaffolding
› _s Theme scaffolding

wp scaffold _s devconmru --theme_name="The
Devconmru Theme" —-author=“Devconmru” 

—-sassify
› New post type

wp scaffold post-type books —-theme
› Create a child theme

wp scaffold child-theme devconmru-child --
parent_theme=devconmru —-theme_name=‘Child
Theme'
WP-CLI Internal API
› Extend WP-CLI with new command

WP_CLI::add_command()
› Execute callbacks for a specific hook

WP_CLI::do_hook()
› Displaying messages

WP_CLI::line()

WP_CLI::success() 

WP_CLI::error() //script exited after this one
Custom WP-CLI Commands
› Extend WP-CLI with your own commands
› No performance issues since the code is only loaded
when accessed through WP-CLI

if ( defined('WP_CLI') && WP_CLI ) {

require __DIR__ . '/wp-cli-command.php';

}
Custom WP-CLI Commands
› 

function post_count_callback(){

//Write code here

}



WP_CLI::add_command('post-count',
'post_count_callback');
› New command available! 

wp post-count

Demo code: https://github.com/rrikesh/wp-cli-
post-count

Thank you!
› Questions?
› If you have any questions after the presentation:

Tweet me at @rrikesh

Mail me on r@paperboat.io

More Related Content

What's hot

Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Žilvinas Kuusas
 
Automated Tasks for WordPress
Automated Tasks for WordPressAutomated Tasks for WordPress
Automated Tasks for WordPressJoe Cartonia
 
Ansible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaTetiana Saputo
 
Cf camp 2019 cfconfig - a new way to manage your cold-fusion engine config
Cf camp 2019   cfconfig - a new way to manage your cold-fusion engine configCf camp 2019   cfconfig - a new way to manage your cold-fusion engine config
Cf camp 2019 cfconfig - a new way to manage your cold-fusion engine configOrtus Solutions, Corp
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubEssam Salah
 
Sunil phani's take on windows powershell
Sunil phani's take on windows powershellSunil phani's take on windows powershell
Sunil phani's take on windows powershellSunil Phani
 
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Local Dev on Virtual Machines - Vagrant, VirtualBox and AnsibleLocal Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Local Dev on Virtual Machines - Vagrant, VirtualBox and AnsibleJeff Geerling
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = CodeGeorg Sorst
 
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu ServerForget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Serveraaroncouch
 
Securing Your WordPress Installation
Securing Your WordPress InstallationSecuring Your WordPress Installation
Securing Your WordPress InstallationLester Chan
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to AnsibleDan Vaida
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeSarah Z
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansiblejtyr
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPressAlan Lok
 

What's hot (20)

Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)
 
Automated Tasks for WordPress
Automated Tasks for WordPressAutomated Tasks for WordPress
Automated Tasks for WordPress
 
Ansible
AnsibleAnsible
Ansible
 
Ansible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy Mykhailiuta
 
Cialug August 2021
Cialug August 2021Cialug August 2021
Cialug August 2021
 
Cf camp 2019 cfconfig - a new way to manage your cold-fusion engine config
Cf camp 2019   cfconfig - a new way to manage your cold-fusion engine configCf camp 2019   cfconfig - a new way to manage your cold-fusion engine config
Cf camp 2019 cfconfig - a new way to manage your cold-fusion engine config
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
 
Sunil phani's take on windows powershell
Sunil phani's take on windows powershellSunil phani's take on windows powershell
Sunil phani's take on windows powershell
 
Powershell alias
Powershell aliasPowershell alias
Powershell alias
 
Curl Tutorial
Curl Tutorial Curl Tutorial
Curl Tutorial
 
Cold fusion is racecar fast
Cold fusion is racecar fastCold fusion is racecar fast
Cold fusion is racecar fast
 
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Local Dev on Virtual Machines - Vagrant, VirtualBox and AnsibleLocal Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
 
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu ServerForget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
 
Securing Your WordPress Installation
Securing Your WordPress InstallationSecuring Your WordPress Installation
Securing Your WordPress Installation
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to Ansible
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPress
 

Similar to A Better WordPress Workflow with WP-CLI

Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLISuwash Kunwar
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachDiana Thompson
 
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
 
Session: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from ScratchSession: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from ScratchRoald Umandal
 
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
 
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
 
Extending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIExtending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIryanduff
 
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
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineBehzod Saidov
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comInstaWP Inc
 
WordPress and The Command Line
WordPress and The Command LineWordPress and The Command Line
WordPress and The Command LineKelly Dwan
 
Getting Started with WP-CLI, a tool to automate your life
Getting Started with WP-CLI, a tool to automate your lifeGetting Started with WP-CLI, a tool to automate your life
Getting Started with WP-CLI, a tool to automate your lifeAJ Morris
 
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
 
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
 
WooCommerce WP-CLI Basics
WooCommerce WP-CLI BasicsWooCommerce WP-CLI Basics
WooCommerce WP-CLI Basicscorsonr
 
Dockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor BrownDockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor BrownDocker, Inc.
 
DockerCon 2016 - Dockerizing Windows Server Applications
DockerCon 2016 - Dockerizing Windows Server ApplicationsDockerCon 2016 - Dockerizing Windows Server Applications
DockerCon 2016 - Dockerizing Windows Server ApplicationsTaylor Brown
 
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliWordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliGetSource
 
WordPress Development Environments
WordPress Development Environments WordPress Development Environments
WordPress Development Environments Ohad Raz
 
WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperChandra Patel
 

Similar to A Better WordPress Workflow with WP-CLI (20)

Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLI
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long Beach
 
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
 
Session: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from ScratchSession: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from Scratch
 
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
 
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
 
Extending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIExtending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLI
 
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
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command line
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
 
WordPress and The Command Line
WordPress and The Command LineWordPress and The Command Line
WordPress and The Command Line
 
Getting Started with WP-CLI, a tool to automate your life
Getting Started with WP-CLI, a tool to automate your lifeGetting Started with WP-CLI, a tool to automate your life
Getting Started with WP-CLI, a tool to automate your life
 
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...
 
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)
 
WooCommerce WP-CLI Basics
WooCommerce WP-CLI BasicsWooCommerce WP-CLI Basics
WooCommerce WP-CLI Basics
 
Dockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor BrownDockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor Brown
 
DockerCon 2016 - Dockerizing Windows Server Applications
DockerCon 2016 - Dockerizing Windows Server ApplicationsDockerCon 2016 - Dockerizing Windows Server Applications
DockerCon 2016 - Dockerizing Windows Server Applications
 
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliWordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
 
WordPress Development Environments
WordPress Development Environments WordPress Development Environments
WordPress Development Environments
 
WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of Developer
 

Recently uploaded

定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxBipin Adhikari
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 

Recently uploaded (20)

定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptx
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 

A Better WordPress Workflow with WP-CLI

  • 1. A better WordPress workflow with WP-CLI By Rikesh Ramlochund
  • 2. WP-CLI › WP-CLI is a set of command-line tools for managing WordPress installations › Install a WordPress website › Update WordPress core, plugins, and themes › Automate repetitive tasks › Make your own commands › ssh on your server and run the commands
  • 3. WP-CLI Installation › Installation and upgrade: https://wp-cli.org/ › Download the wp-cli.phar file
 curl -O https://raw.githubusercontent.com/ wp-cli/builds/gh-pages/phar/wp-cli.phar › Check if the file works
 php wp-cli.phar —-info
  • 4. WP-CLI Installation › To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. › chmod +x wp-cli.phar › sudo mv wp-cli.phar /usr/local/bin/wp › wp —-info
  • 5. WP-CLI Installation › WP-CLI can also be installed via Composer or Homebrew › Debian and Ubuntu users can install WP-CLI via a .deb package › WP-CLI can also be installed on Windows › Read more about WP-CLI Installation: https://wp-cli.org/ docs/installing/
  • 6. WP-CLI Command Anatomy › wp plugin install jetpack › wp: All WP-CLI commands start with wp › plugin: command › install: subcommand › jetpack: options/parameters (here it is a plugin name)
  • 7. Node.js Wrapper › npm install wp-cli
 
 Node wrapper for Wordpress CLI with functionality matching the WP-CLI API.
 Learn more: https://www.npmjs.com/package/wp-cli
  • 8. Installing WordPress using WP-CLI › Download the WordPress core:
 wp core download
 or
 wp core download —-locale=fr_FR
  • 9. Installing WordPress using WP-CLI › Generate the wp-config.php file
 wp core config --dbname=devconwp 
 --dbuser=devcon --dbpass=somePassword › Create the database file (dbname value from command above)
 wp db create
  • 10. Installing WordPress using WP-CLI › Run the WordPress installation process
 wp core install —-prompt › Installation done :) › Note: ——prompt is a global parameter of WP-CLI, and it prompts the user to enter values for all command arguments
  • 11. Installing WordPress using WP-CLI › Recap: › wp core download › wp core config --dbname=devconwp 
 --dbuser=devcon —-dbpass=somePassword › wp db create › wp core install —-prompt
  • 12. WordPress Core commands › Check for update via Version Check API
 wp core check-update › Update WordPress
 wp core update and wp core update-db › Verify WordPress files against wordpress.org checksums
 wp core verify-checksums › Display the WordPress version
 wp core version
  • 13. Plugin Management › List all plugins
 wp plugin list › List plugins with pending updates
 wp plugin list —-update=available › Plugin Installation
 wp plugin install advanced-custom-fields
 wp plugin install jetpack —-version=“3.6”
 wp plugin install my-plugin.zip
  • 14. Plugin Management › Install premium plugins via zip file. › Advanced Custom Fields Pro allows you to download a zip file using your private key › wget -v -O acf-pro.zip “http:// connect.advancedcustomfields.com/index.php? p=pro&a=download&k=YOUR_ACF_PRO_KEY” › wp plugin install acf-pro.zip --activate › rm acf-pro.zip
  • 15. Plugin Management › Some plugins like Jetpack also implement WP-CLI commands. › For example:
 wp jetpack status
 wp jetpack module list
 wp jetpack module activate carousel
  • 16. Plugin Management › Activate a plugin
 wp plugin activate jetpack › Deactivate a plugin
 wp plugin deactivate jetpack › Update all plugins
 wp plugin update --all
  • 17. WordPress Maintenance › Keeping WordPress up to date › wp core update › wp core update-db › wp plugins update --all › wp theme update --all › Don’t forget to backup your files before doing updates!
  • 18. WordPress Backups › Export WordPress database via WP-CLI
 wp db export › Compress the WordPress directory
 tar -vczf backup.gz .
  • 19. Database Migration › Moving a WordPress installation to another server (eg. staging to production) › Step 1: Export staging database
 wp db export › Step 2: Move database to production and import
 wp db import › Step 3: Update URLs from staging to production
 wp search-replace “http:// staging.example.com” “http://example.com”
  • 20. Managing Options › Read option value
 wp option get blogname › Update option value
 wp option update blogname “Awesome WP” › Delete option
 wp option delete optional › List options
 wp option list
  • 21. Useful Commands › Regenerate thumbnails
 wp media regenerate › Generate x posts, using some Lorem Ipsum text
 curl http://loripsum.net/api/5 | wp post generate --post_content --count=x › Run a query saved in a file
 wp db query < debug.sql › Command helper
 wp help plugin install
  • 22. Useful Commands › Import WXR file
 wp import posts.xml › Bulk importing images as attachments
 Import all JPGs from the user’s Pictures directory
 wp media import ~/Pictures/**/*.jpg › Import a specific image and assign it as post thumbnail for that post
 wp media import ~/Downloads/image.png -- post_id=123 --title="A downloaded picture" --featured_image
  • 23. Useful Commands › Delete all transients
 wp transient delete-all › Delete all expired transients
 wp transient delete-expired › List registered post types
 wp post-type list
  • 24. Useful Commands › Update user password
 wp user update 1 —-user_pass=newpass › List all posts
 wp post list › List all users
 wp user list
  • 25. Scaffolding › _s Theme scaffolding
 wp scaffold _s devconmru --theme_name="The Devconmru Theme" —-author=“Devconmru” 
 —-sassify › New post type
 wp scaffold post-type books —-theme › Create a child theme
 wp scaffold child-theme devconmru-child -- parent_theme=devconmru —-theme_name=‘Child Theme'
  • 26. WP-CLI Internal API › Extend WP-CLI with new command
 WP_CLI::add_command() › Execute callbacks for a specific hook
 WP_CLI::do_hook() › Displaying messages
 WP_CLI::line()
 WP_CLI::success() 
 WP_CLI::error() //script exited after this one
  • 27. Custom WP-CLI Commands › Extend WP-CLI with your own commands › No performance issues since the code is only loaded when accessed through WP-CLI
 if ( defined('WP_CLI') && WP_CLI ) {
 require __DIR__ . '/wp-cli-command.php';
 }
  • 28. Custom WP-CLI Commands › 
 function post_count_callback(){
 //Write code here
 }
 
 WP_CLI::add_command('post-count', 'post_count_callback'); › New command available! 
 wp post-count
 Demo code: https://github.com/rrikesh/wp-cli- post-count

  • 29. Thank you! › Questions? › If you have any questions after the presentation:
 Tweet me at @rrikesh
 Mail me on r@paperboat.io