β‘ Manage WordPress from Terminal
Clicking through admin for every site update? Slow. WP-CLI lets you install plugins, update core, manage usersβall from command line. 10x faster.
Install WP-CLI
# Download curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # Make executable chmod +x wp-cli.phar # Move to PATH sudo mv wp-cli.phar /usr/local/bin/wp # Test wp --info
π Essential Commands
# Update WordPress core wp core update # Install plugin wp plugin install contact-form-7 --activate # Update all plugins wp plugin update --all # Install theme wp theme install twentytwentyfour --activate # Create user wp user create john john@example.com --role=editor # Search & replace in database wp search-replace 'http://oldsite.com' 'https://newsite.com' # Export database wp db export backup.sql # Import database wp db import backup.sql # Clear cache wp cache flush # Generate posts for testing wp post generate --count=100
Real-World: Bulk Site Management
π¦ Update 50 Sites Script
#!/bin/bash
sites=(
"/var/www/site1"
"/var/www/site2"
"/var/www/site3"
# ... 47 more
)
for site in "${sites[@]}"; do
echo "Updating $site"
cd "$site"
# Backup first
wp db export "backup-$(date +%Y%m%d).sql"
# Update everything
wp core update
wp plugin update --all
wp theme update --all
echo "β $site updated"
done
# 50 sites updated in 10 minutes instead of 5 hours
Migration Made Easy
# On old server wp db export oldsite.sql wp media regenerate --yes # Regenerate thumbnails # Transfer files + database to new server scp -r wp-content/ user@newserver:/var/www/html/ scp oldsite.sql user@newserver:/tmp/ # On new server wp db import /tmp/oldsite.sql wp search-replace 'http://oldsite.com' 'https://newsite.com' wp search-replace '/old/path' '/new/path' wp cache flush # Done! Site migrated
β Power User Commands
- wp post list: List all posts with filters
- wp media regenerate: Regenerate all image sizes
- wp user list: Show all users with roles
- wp option get siteurl: Get any option value
- wp plugin list –status=inactive: Find unused plugins
- wp transient delete –all: Clear all transients
π‘ Cheat Sheet
| Task | Command |
|---|---|
| Update core | wp core update |
| Install plugin | wp plugin install [name] --activate |
| Backup DB | wp db export backup.sql |
| Search/Replace | wp search-replace 'old' 'new' |
| Clear cache | wp cache flush |
“Manage 30 client sites. Before WP-CLI: 2 hours to update everything. After: Created bash script with WP-CLI. 10 minutes, all sites updated, backed up, tested. Game changer.”
