WP-CLI is WordPress' standard command line tool today. In this presentation we will see why wp-cli is a very strong tool in our toolstack and how using it can make our life easier.
We are presenting several features that are useful in our every day workflow and we have a look at a world of new automation opportunities wp-cli can provide.
Presented at WordCamp Athens 2019.
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
WP-CLI: Unleash the power
1. > WP-CLI
H O S T I N G D O N E R I G H T
www.trustservers.gr
(+30) 211 800 33 70
UNLEASH
THE
POWER
Giannis Economou
Founder / Sr. Software Engineer
gecon@antithesis.gr
3. c
CLI: COMMAND LINE INTERFACE
OVERVIEW
8 Y [
Terminal
Console
Shell
( SSH )
Developers
DevOps
SysAdmins
Engineers
Advanced Users
Several Tools
Script
Repeat
Automate
Save
A LOT of Time!
6. MS WINDOWS … THE WINDOWS TERMINAL!
MAY-2019
https://www.youtube.com/watch?v=KMudkRcwjCw
Open Source
MIT License
LICENSE
GITHUB:
Microsoft/Terminal
PUBLIC REPO
7. MS WINDOWS … SOON WITH A LINUX KERNEL!
MAY-2019
Beginning with Windows Insiders builds this Summer, we will
include an in-house custom-built Linux kernel to underpin the
newest version of the Windows Subsystem for Linux (WSL)
Jack Hammons
Program Manager, Linux Systems Group - Microsoft.com
8. YOUR *UNIX-LIKE*
TERMINAL
EVERYWHERE
Native
LINUX / UNIX/ MACOS
WSL: Windows Subsystem For
Linux
WSL 2: Native Linux Kernel!
The “Windows Terminal” !
MICROSOFT WINDOWS
SSH
YOUR HOSTING!
(view animated gif: https://fournos.antithesis.gr/f/4abad885df7d46e3936e/)
13. INSTALL: A THEME AND A PLUGIN
EVERYDAY TASKS
Search
Install
Activate
Many plugins in
one command:
wp plugin install p1 p2 p3
(view animated gif: https://fournos.antithesis.gr/f/3fcfe66c859c4109b69f/)
14. PACKAGES PROVIDE FUNCTIONALITY
EXAMPLE: ADD SAMPLE CONTENT
wp package install
Many 3rd party packages
You can write your own
packages
(view animated gif: https://fournos.antithesis.gr/f/b0f83fe984904fca8233/)
16. UPDATES: CORE, PLUGINS AND THEMES
IN SECONDS
View plugins status
(Backup database)
Perform all the updates
(view animated gif: https://fournos.antithesis.gr/f/5cd896f264b7449c827f/)
17. ALIASES
MANAGE SEVERAL WP
Grouping
Logical groups of WP
instances
Remote execution
Instances can be
remote, commands are
executed on remote
host
An alias is
a shorthand reference to
a WordPress install
Manage several WP
Execute wp-cli
commands on many
WordPress installations
at once
19. EXECUTE
ON SELECTED ALIASES
wp @ALIAS command
wp @all verify-checksums
wp @live updatedraftplus backup
wp @all core update
wp @staging plugin update —all
wp @all cache flush
wp @all super-cache flush
wp @live cron event run --due-now
Useful examples:
check for altered core files
everywhere
backup live sites
update core and plugins on all
staging installations
flush object cache and super
cache everywhere
run due cron events on live sites
20. DEPLOY YOUR DB
FROM PRODUCTION
TO STAGING
wp @siteone-live db export - | wp @siteone-stage db import -
wp @siteone-stage search-replace “www.example.org” “staging.example.org”
Export database from production and import on staging
Search and replace base URL
READY!
22. SOME EXAMPLES
DO TRY THIS AT HOME
#create your child theme fast
wp scaffold child-theme myTheme --parent_theme=‘Sydney’ --theme_name='Sweet child of mine'
#downgrade: test your plugin on older WP versions
wp core update --force --version=5.1
#import content from wordpress.com
wp import example.wordpress.2019-05-18.xml --authors=create
#Re-generate all thumbnails, without confirmation.
wp media regenerate --yes
Found 3 images to regenerate.
1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760).
2/3 Regenerated thumbnails for "Boardwalk" (ID 757).
3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756).
Success: Regenerated 3 of 3 images.
23. MORE ADVANCED EXAMPLES
THE SKY IS THE LIMIT
#delete all posts, but leave pages.
wp post delete --force $(wp post list --post_type=post --format=ids)
#!/bin/bash
#reset all user passwords (also see ‘wp user reset-password’)
for uid in $(wp user list --field=id)
do
pass=`openssl rand 15 -base64`
wp user update $uid --user_pass="$pass"
done
Use your shell
Write a script
24. Thank you!
Giannis Economou - gecon@antithesis.gr - www.trustservers.gr (+30) 211 800 33 70
H O S T I N G D O N E R I G H T