SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Downloaden Sie, um offline zu lesen
Themer’s Guide
WordPress Command Line Interface
__ _______ _____ _ _____
  / / __  / ____| | |_ _|
  / / /| |__) |_____| | | | | |
 / / / | ___/______| | | | | |
 / / | | | |____| |____ _| |_
/ / |_| _____|______|_____|
1. Intro
2. WP-CLI Basics
3. Install WordPress
4. Plugin and Theme Automation
5. PHP7 Compatibility Checker
6. Advanced
Agenda
_____ _ _ _ _
|_ _| | | | | | | (_)
| | _ __ | |_ _ __ ___ __| |_ _ ___| |_ _ ___ _ __
| | | '_ | __| '__/ _  / _` | | | |/ __| __| |/ _ | '_ 
_| |_| | | | |_| | | (_) | (_| | |_| | (__| |_| | (_) | | | |
|_____|_| |_|__|_| ___/ __,_|__,_|___|__|_|___/|_| |_|
•Sales Engineer - WP Engine
•Developer, Freelancer
•CMS Specialist
•Open Source
•Speaker
Edmund Turbin
WordCamp Stockholm - Nov 2016
THERE ARE TWO TYPES OF PEOPLE IN THE WORLD
I ❤
WHY USE COMMANDS?
•Quickly execute a task
•Bundle many tasks together in scripts
•Avoid using the keyboard and mouse
•Simplify repetitive tasks
•and also…
WHY USE COMMANDS?SO WE CAN BE LAZY
____ _
| _  (_)
| |_) | __ _ ___ _ ___ ___
| _ < / _` | / __| | | / __| / __|
| |_) | | (_| | __  | | | (__ __ 
|____/ __,_| |___/ |_| ___| |___/
WHAT DO I NEED TO GET STARTED?
•Local Dev Environment with PHP - VVV, MAMP, WAMP
•Terminal - Terminal App, iTerm 2, PuTTY
•Text Editor - Sublime, Atom
PREREQUISITES
INSTALL WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/
builds/gh-pages/phar/wp-cli.phar
https://make.wordpress.org/cli/handbook/installing/
INSTALL WP-CLI
# Make file executable
chmod +x wp-cli.phar
# Move file to proper location
sudo mv wp-cli.phar /usr/local/bin/wp
https://make.wordpress.org/cli/handbook/installing/
INSTALL WP-CLI
•Composer
•Homebrew
•Manually
https://make.wordpress.org/cli/handbook/installing/
ALTERNATE INSTALL METHODS
INSTALL WP-CLI
• change into a WP directory
• run $wp cli info
https://make.wordpress.org/cli/handbook/installing/
TEST THE INSTALLATION
COMMAND STRUCTURE
$wp command subcommand value
$wp plugin install wp-smushit
_____ __ _ _ _
/ ____| / _(_) | | (_)
| | ___ _ __ | |_ _ __ _ _ _ _ __ __ _| |_ _ ___ _ __
| | / _ | '_ | _| |/ _` | | | | '__/ _` | __| |/ _ | '_ 
| |___| (_) | | | | | | | (_| | |_| | | | (_| | |_| | (_) | | | |
________/|_| |_|_| |_|__, |__,_|_| __,_|__|_|___/|_| |_|
__/ |
|___/
WHAT HAVE I DONE?
• Installed WP-CLI locally
• Configured a WP-CLI alias to SSH into remotes
• I can execute remote commands as if they were on my local
machine
• No need for local MySQL
• Alternate - use SSH directly into VVV
CONFIGURATION
•Alias called @dev allows me to run remote commands
• $wp @dev cli info is different than $wp cli info
• @dev connects via SSH and runs on Vagrant box
https://make.wordpress.org/cli/handbook/config/
wp-cli.yml - Aliases with Vagrant
CONFIGURATION
$ wp cli info
PHP binary: /usr/bin/php
PHP version: 5.5.38
php.ini used:
WP-CLI root dir: phar://wp-cli.phar
WP-CLI packages dir: /Users/edmund.turbin/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config: /Users/edmund.turbin/Development/vvv2/www/wpcli-test4/wp-cli.yml
WP-CLI version:1.1.0
wp-cli.yml - Aliases with Vagrant
CONFIGURATION
$wp @dev cli info
PHP binary: /usr/bin/php7.0
PHP version: 7.0.17-2+deb.sury.org~trusty+1
php.ini used: /etc/php/7.0/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config: /srv/www/wpcli-test4/wp-cli.yml
WP-CLI version:1.2.0-alpha-afe561b
wp-cli.yml - Aliases with Vagrant
CONFIGURATION
•Allows you to configure WP-CLI variables
•File can be at the Global, Project and Local levels
•e.g.: Local overrides Global
•Allows you to set up Aliases per site
https://make.wordpress.org/cli/handbook/config/
wp-cli.yml
CONFIGURATION
@dev:
ssh: vagrant@wpcli-test.dev/srv/www/wpcli-test
https://make.wordpress.org/cli/handbook/installing/
wp-cli.yml - Aliases with Vagrant
_____ _
/ ____| | |
| | ___ _ __ ___ _ __ ___ __ _ _ __ __| | ___
| | / _  | '_ ` _  | '_ ` _  / _` | | '_  / _` | / __|
| |____ | (_) | | | | | | | | | | | | | | (_| | | | | | | (_| | __ 
_____| ___/ |_| |_| |_| |_| |_| |_| __,_| |_| |_| __,_| |___/
CORE OPERATIONS
•Downloads the recent version of WordPress to the current directory
$wp core download
CORE OPERATIONS
•Creates WordPress configuration file.
•This file tells WP-CLI how connect to you’re site’s database
$wp core config
CORE OPERATIONS
•Completes the WordPress install process
$wp core install
DATABASE OPERATIONS
•Create a database for your WordPress install
•Depends on a wp-config.php file to work
$wp db create
INSTALL WORDPRESS
# Download WordPress
$wp core download
# Create WordPress configuration - wp-config.php
$wp core config
—-dbuser=root --dbpass=root —-dbname=wpcli-test
INSTALL WORDPRESS
# Create Database for install
$wp db create wpcli-test
# Run the install process
$wp core install
—url=wpcli-test.dev —-title=“wpcli test”
—admin_user=admin --admin_password=password
--admin_email=info@example.com
INSTALL WORDPRESS
•Not needed if you’re using VVV
•WP installs can be created and provisioned via Vagrant
Note for VVV Users
https://varyingvagrantvagrants.org/
_ _ _
/ | | | | (_)
/  _ _ | |_ ___ _ __ ___ __ _ | |_ _ ___ _ __
/ /  | | | | | __| / _  | '_ ` _  / _` | | __| | | / _  | '_ 
/ ____  | |_| | | |_ | (_) | | | | | | | | (_| | | |_ | | | (_) | | | | |
/_/ _ __,_| __| ___/ |_| |_| |_| __,_| __| |_| ___/ |_| |_|
SHELL SCRIPTING
•You can use WP CLI with like any other command
•e.g. tie commands together and run them as a list
INSTALL WORDPRESS PLUGINS, THEME
#!/bin/bash
# list of plugins
plugins=("user-switching" "debug-objects""wp-cfm")
# loop through plugin list and install
for plugin in ${plugins[*]};
do
wp plugin install $plugin
wp plugin activate $plugin
done
INSTALL UNDERSCORE_S THEME
echo "Enter site name:"
read theme_name
wp scaffold _s $theme_name
wp theme activate $theme_name
wp scaffold theme-tests $theme_name
GENERATE CONTENT
wp post generate --count=10
wp post generate --count=10 --post_type=page
wp comment generate --count=10
_____ _ _ _____ ______ _____ _ _
| __  | | | | | __  |____ | / ____| | | | |
| |__) | | |__| | | |__) | / / | | | |__ ___ ___ | | __
| ___/ | __ | | ___/ / / | | | '_  / _  / __| | |/ /
| | | | | | | | / / | |____ | | | | | __/ | (__ | <
|_| |_| |_| |_| /_/ _____| |_| |_| ___| ___| |_|_
PHP COMPATIBILITY COMMAND
•Run PHP7 Compatibility Checker
•Plugin needs to be installed
•Version supplied as an argument
wp phpcompat 7.0
RUN PHP COMPATIBILITY CHECK SCRIPT
#!/bin/bash
wp plugin install php-compatibility-checker
wp plugin activate php-compatibility-checker
wp phpcompat 7.0 > php-compat-results.txt
PLUGINS WITH COMMANDS
•ACF
•Elastic press
•Migrate, migrated
•caching plugins
•PHP Compatibility
•Regen thumbs
•widget import/export
•developer
•wp-cfm
•backupwordpress
https://make.wordpress.org/cli/handbook/tools/
_ _
/ | | | |
/  __| | __ __ __ _ _ __ ___ ___ __| |
/ /  / _` |   / / / _` | | '_  / __| / _  / _` |
/ ____  | (_| |  V / | (_| | | | | | | (__ | __/ | (_| |
/_/ _ __,_| _/ __,_| |_| |_| ___| ___| __,_|
NOTABLE COMMANDS
•Scaffold - create plugins, child themes, unit tests
•db, db-query
•transient
•wp-cfm - configuration management
•backupwordpress
https://make.wordpress.org/cli/handbook/tools/
SHELL ALIAS COMMAND
Create a shortcut command for things that are
frequently used to cut down on keystrokes.
alias - show all aliases
SHELL ALIASES
Create an alias
alias pu=“wp plugin update --all”
SHELL ALIASES
Remove an alias
unalias pu
SHELL ALIASES
Arguments
alias pi='wp plugin install’
pi wp-smushit
SHELL ALIASES
Aliases can be saved and managed from .bash_profile
CUSTOM SHELL COMMANDS
• functions can be created in your shell profile (.bash_profile) and
executed globaly
wp_info ()
{
wp cli info
}
Helpful Links
Command Cookbook
https://make.wordpress.org/cli/handbook/commands-cookbook/
Shell Friends
https://make.wordpress.org/cli/handbook/shell-friends/
Plugins that work with WP-CLI
https://make.wordpress.org/cli/handbook/tools/
WP-CLI Configuration
https://make.wordpress.org/cli/handbook/config/
Shell Scripting
https://www.shellscript.sh/
WP-CLI is a toolbox
Commands can be linked
together via scripts to
automate complex tasks
WP-CLI for Themeing
WP-CLI can be one of many tools
to get your development process
started quickly
Good, Better, Best
•Single Commands
•Shell Scripts
•Shell Commands
Thank you!
@spicecadet
edmund.turbin@wpengine.com

Weitere ähnliche Inhalte

Was ist angesagt?

Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021
Joe Ferguson
 

Was ist angesagt? (20)

TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source ToolsTYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
 
ColdFusion builder plugins
ColdFusion builder pluginsColdFusion builder plugins
ColdFusion builder plugins
 
Kickstart Jpa
Kickstart JpaKickstart Jpa
Kickstart Jpa
 
Coding with jetpack
Coding with jetpackCoding with jetpack
Coding with jetpack
 
Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021
 
Server Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.jsServer Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.js
 
CollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPagesCollabSphere 2018 - Java in Domino After XPages
CollabSphere 2018 - Java in Domino After XPages
 
Slim PHP when you don't need the kitchen sink
Slim PHP   when you don't need the kitchen sinkSlim PHP   when you don't need the kitchen sink
Slim PHP when you don't need the kitchen sink
 
Automated ui-testing
Automated ui-testingAutomated ui-testing
Automated ui-testing
 
Using CI for continuous delivery Part 1
Using CI for continuous delivery Part 1Using CI for continuous delivery Part 1
Using CI for continuous delivery Part 1
 
Automated testing with Drupal
Automated testing with DrupalAutomated testing with Drupal
Automated testing with Drupal
 
Short-Training asp.net vNext
Short-Training asp.net vNextShort-Training asp.net vNext
Short-Training asp.net vNext
 
Enterprise PHP
Enterprise PHPEnterprise PHP
Enterprise PHP
 
Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)
 
Developing better PHP projects
Developing better PHP projectsDeveloping better PHP projects
Developing better PHP projects
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git together
 
Bring api manager into your stack
Bring api manager into your stackBring api manager into your stack
Bring api manager into your stack
 
Cypress new old Selenium
Cypress new old SeleniumCypress new old Selenium
Cypress new old Selenium
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as Code
 
Performance testing with VSTs on- and off-premises
Performance testing with VSTs on-  and off-premisesPerformance testing with VSTs on-  and off-premises
Performance testing with VSTs on- and off-premises
 

Ähnlich wie The Themer's Guide to WP-CLI

Ähnlich wie The Themer's Guide to WP-CLI (20)

The Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIThe Themer's Guide to WP-CLI
The Themer's Guide to WP-CLI
 
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...
 
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
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
 
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
 
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)
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
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
 
WPDay Bologna 2013
WPDay Bologna 2013WPDay Bologna 2013
WPDay Bologna 2013
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
 
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
 
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
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
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
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
WooCommerce WP-CLI Basics
WooCommerce WP-CLI BasicsWooCommerce WP-CLI Basics
WooCommerce WP-CLI Basics
 
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
 

Mehr von Edmund Turbin

Mehr von Edmund Turbin (11)

Remote Control WordPress
Remote Control WordPressRemote Control WordPress
Remote Control WordPress
 
Production Ready WordPress #WPLDN
Production Ready WordPress #WPLDNProduction Ready WordPress #WPLDN
Production Ready WordPress #WPLDN
 
Production Ready WordPress - WC Utrecht 2017
Production Ready WordPress  - WC Utrecht 2017Production Ready WordPress  - WC Utrecht 2017
Production Ready WordPress - WC Utrecht 2017
 
Production ready word press
Production ready word pressProduction ready word press
Production ready word press
 
Configuration Management in WordPress
Configuration Management in WordPressConfiguration Management in WordPress
Configuration Management in WordPress
 
Customize it.
Customize it.Customize it.
Customize it.
 
Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?
 
Word press gets responsive 4x3
Word press gets responsive 4x3Word press gets responsive 4x3
Word press gets responsive 4x3
 
Scaling WooCommerce on WP Engine
Scaling WooCommerce on WP EngineScaling WooCommerce on WP Engine
Scaling WooCommerce on WP Engine
 
Woo commerce scalability notes
Woo commerce scalability   notesWoo commerce scalability   notes
Woo commerce scalability notes
 
Just For You - How to drive better engagement with localisation-based insights.
Just For You - How to drive better engagement with localisation-based insights.Just For You - How to drive better engagement with localisation-based insights.
Just For You - How to drive better engagement with localisation-based insights.
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

The Themer's Guide to WP-CLI

  • 1. Themer’s Guide WordPress Command Line Interface __ _______ _____ _ _____ / / __ / ____| | |_ _| / / /| |__) |_____| | | | | | / / / | ___/______| | | | | | / / | | | |____| |____ _| |_ / / |_| _____|______|_____|
  • 2. 1. Intro 2. WP-CLI Basics 3. Install WordPress 4. Plugin and Theme Automation 5. PHP7 Compatibility Checker 6. Advanced Agenda
  • 3. _____ _ _ _ _ |_ _| | | | | | | (_) | | _ __ | |_ _ __ ___ __| |_ _ ___| |_ _ ___ _ __ | | | '_ | __| '__/ _ / _` | | | |/ __| __| |/ _ | '_ _| |_| | | | |_| | | (_) | (_| | |_| | (__| |_| | (_) | | | | |_____|_| |_|__|_| ___/ __,_|__,_|___|__|_|___/|_| |_|
  • 4. •Sales Engineer - WP Engine •Developer, Freelancer •CMS Specialist •Open Source •Speaker Edmund Turbin WordCamp Stockholm - Nov 2016
  • 5. THERE ARE TWO TYPES OF PEOPLE IN THE WORLD
  • 6.
  • 8.
  • 9. WHY USE COMMANDS? •Quickly execute a task •Bundle many tasks together in scripts •Avoid using the keyboard and mouse •Simplify repetitive tasks •and also…
  • 10. WHY USE COMMANDS?SO WE CAN BE LAZY
  • 11. ____ _ | _ (_) | |_) | __ _ ___ _ ___ ___ | _ < / _` | / __| | | / __| / __| | |_) | | (_| | __ | | | (__ __ |____/ __,_| |___/ |_| ___| |___/
  • 12. WHAT DO I NEED TO GET STARTED? •Local Dev Environment with PHP - VVV, MAMP, WAMP •Terminal - Terminal App, iTerm 2, PuTTY •Text Editor - Sublime, Atom PREREQUISITES
  • 13. INSTALL WP-CLI curl -O https://raw.githubusercontent.com/wp-cli/ builds/gh-pages/phar/wp-cli.phar https://make.wordpress.org/cli/handbook/installing/
  • 14. INSTALL WP-CLI # Make file executable chmod +x wp-cli.phar # Move file to proper location sudo mv wp-cli.phar /usr/local/bin/wp https://make.wordpress.org/cli/handbook/installing/
  • 16. INSTALL WP-CLI • change into a WP directory • run $wp cli info https://make.wordpress.org/cli/handbook/installing/ TEST THE INSTALLATION
  • 17. COMMAND STRUCTURE $wp command subcommand value $wp plugin install wp-smushit
  • 18. _____ __ _ _ _ / ____| / _(_) | | (_) | | ___ _ __ | |_ _ __ _ _ _ _ __ __ _| |_ _ ___ _ __ | | / _ | '_ | _| |/ _` | | | | '__/ _` | __| |/ _ | '_ | |___| (_) | | | | | | | (_| | |_| | | | (_| | |_| | (_) | | | | ________/|_| |_|_| |_|__, |__,_|_| __,_|__|_|___/|_| |_| __/ | |___/
  • 19. WHAT HAVE I DONE? • Installed WP-CLI locally • Configured a WP-CLI alias to SSH into remotes • I can execute remote commands as if they were on my local machine • No need for local MySQL • Alternate - use SSH directly into VVV
  • 20. CONFIGURATION •Alias called @dev allows me to run remote commands • $wp @dev cli info is different than $wp cli info • @dev connects via SSH and runs on Vagrant box https://make.wordpress.org/cli/handbook/config/ wp-cli.yml - Aliases with Vagrant
  • 21. CONFIGURATION $ wp cli info PHP binary: /usr/bin/php PHP version: 5.5.38 php.ini used: WP-CLI root dir: phar://wp-cli.phar WP-CLI packages dir: /Users/edmund.turbin/.wp-cli/packages/ WP-CLI global config: WP-CLI project config: /Users/edmund.turbin/Development/vvv2/www/wpcli-test4/wp-cli.yml WP-CLI version:1.1.0 wp-cli.yml - Aliases with Vagrant
  • 22. CONFIGURATION $wp @dev cli info PHP binary: /usr/bin/php7.0 PHP version: 7.0.17-2+deb.sury.org~trusty+1 php.ini used: /etc/php/7.0/cli/php.ini WP-CLI root dir: phar://wp-cli.phar WP-CLI packages dir: WP-CLI global config: WP-CLI project config: /srv/www/wpcli-test4/wp-cli.yml WP-CLI version:1.2.0-alpha-afe561b wp-cli.yml - Aliases with Vagrant
  • 23. CONFIGURATION •Allows you to configure WP-CLI variables •File can be at the Global, Project and Local levels •e.g.: Local overrides Global •Allows you to set up Aliases per site https://make.wordpress.org/cli/handbook/config/ wp-cli.yml
  • 25. _____ _ / ____| | | | | ___ _ __ ___ _ __ ___ __ _ _ __ __| | ___ | | / _ | '_ ` _ | '_ ` _ / _` | | '_ / _` | / __| | |____ | (_) | | | | | | | | | | | | | | (_| | | | | | | (_| | __ _____| ___/ |_| |_| |_| |_| |_| |_| __,_| |_| |_| __,_| |___/
  • 26. CORE OPERATIONS •Downloads the recent version of WordPress to the current directory $wp core download
  • 27. CORE OPERATIONS •Creates WordPress configuration file. •This file tells WP-CLI how connect to you’re site’s database $wp core config
  • 28. CORE OPERATIONS •Completes the WordPress install process $wp core install
  • 29. DATABASE OPERATIONS •Create a database for your WordPress install •Depends on a wp-config.php file to work $wp db create
  • 30. INSTALL WORDPRESS # Download WordPress $wp core download # Create WordPress configuration - wp-config.php $wp core config —-dbuser=root --dbpass=root —-dbname=wpcli-test
  • 31. INSTALL WORDPRESS # Create Database for install $wp db create wpcli-test # Run the install process $wp core install —url=wpcli-test.dev —-title=“wpcli test” —admin_user=admin --admin_password=password --admin_email=info@example.com
  • 32. INSTALL WORDPRESS •Not needed if you’re using VVV •WP installs can be created and provisioned via Vagrant Note for VVV Users https://varyingvagrantvagrants.org/
  • 33. _ _ _ / | | | | (_) / _ _ | |_ ___ _ __ ___ __ _ | |_ _ ___ _ __ / / | | | | | __| / _ | '_ ` _ / _` | | __| | | / _ | '_ / ____ | |_| | | |_ | (_) | | | | | | | | (_| | | |_ | | | (_) | | | | | /_/ _ __,_| __| ___/ |_| |_| |_| __,_| __| |_| ___/ |_| |_|
  • 34. SHELL SCRIPTING •You can use WP CLI with like any other command •e.g. tie commands together and run them as a list
  • 35. INSTALL WORDPRESS PLUGINS, THEME #!/bin/bash # list of plugins plugins=("user-switching" "debug-objects""wp-cfm") # loop through plugin list and install for plugin in ${plugins[*]}; do wp plugin install $plugin wp plugin activate $plugin done
  • 36. INSTALL UNDERSCORE_S THEME echo "Enter site name:" read theme_name wp scaffold _s $theme_name wp theme activate $theme_name wp scaffold theme-tests $theme_name
  • 37. GENERATE CONTENT wp post generate --count=10 wp post generate --count=10 --post_type=page wp comment generate --count=10
  • 38.
  • 39. _____ _ _ _____ ______ _____ _ _ | __ | | | | | __ |____ | / ____| | | | | | |__) | | |__| | | |__) | / / | | | |__ ___ ___ | | __ | ___/ | __ | | ___/ / / | | | '_ / _ / __| | |/ / | | | | | | | | / / | |____ | | | | | __/ | (__ | < |_| |_| |_| |_| /_/ _____| |_| |_| ___| ___| |_|_
  • 40.
  • 41. PHP COMPATIBILITY COMMAND •Run PHP7 Compatibility Checker •Plugin needs to be installed •Version supplied as an argument wp phpcompat 7.0
  • 42. RUN PHP COMPATIBILITY CHECK SCRIPT #!/bin/bash wp plugin install php-compatibility-checker wp plugin activate php-compatibility-checker wp phpcompat 7.0 > php-compat-results.txt
  • 43. PLUGINS WITH COMMANDS •ACF •Elastic press •Migrate, migrated •caching plugins •PHP Compatibility •Regen thumbs •widget import/export •developer •wp-cfm •backupwordpress https://make.wordpress.org/cli/handbook/tools/
  • 44. _ _ / | | | | / __| | __ __ __ _ _ __ ___ ___ __| | / / / _` | / / / _` | | '_ / __| / _ / _` | / ____ | (_| | V / | (_| | | | | | | (__ | __/ | (_| | /_/ _ __,_| _/ __,_| |_| |_| ___| ___| __,_|
  • 45. NOTABLE COMMANDS •Scaffold - create plugins, child themes, unit tests •db, db-query •transient •wp-cfm - configuration management •backupwordpress https://make.wordpress.org/cli/handbook/tools/
  • 46. SHELL ALIAS COMMAND Create a shortcut command for things that are frequently used to cut down on keystrokes. alias - show all aliases
  • 47. SHELL ALIASES Create an alias alias pu=“wp plugin update --all”
  • 48. SHELL ALIASES Remove an alias unalias pu
  • 49. SHELL ALIASES Arguments alias pi='wp plugin install’ pi wp-smushit
  • 50. SHELL ALIASES Aliases can be saved and managed from .bash_profile
  • 51. CUSTOM SHELL COMMANDS • functions can be created in your shell profile (.bash_profile) and executed globaly wp_info () { wp cli info }
  • 52. Helpful Links Command Cookbook https://make.wordpress.org/cli/handbook/commands-cookbook/ Shell Friends https://make.wordpress.org/cli/handbook/shell-friends/ Plugins that work with WP-CLI https://make.wordpress.org/cli/handbook/tools/ WP-CLI Configuration https://make.wordpress.org/cli/handbook/config/ Shell Scripting https://www.shellscript.sh/
  • 53. WP-CLI is a toolbox Commands can be linked together via scripts to automate complex tasks
  • 54. WP-CLI for Themeing WP-CLI can be one of many tools to get your development process started quickly
  • 55. Good, Better, Best •Single Commands •Shell Scripts •Shell Commands