dev3 ·
I manage several WordPress sites over SSH and clicking through wp-admin is slow. What are the most useful WP-CLI commands, and how do I run them as the right user?
#wp-cli#wordpress#command-line
0
DEV3 Developer Forum
Every post is reviewed first. Usually reviewed within 24 hours.
I manage several WordPress sites over SSH and clicking through wp-admin is slow. What are the most useful WP-CLI commands, and how do I run them as the right user?
#wp-cli#wordpress#command-line
Run WP-CLI from the site root (or pass --path=) as the same user that owns the files, not root. If you must use root, add --allow-root, but that risks root-owned files.
sudo -u www-data wp --path=/var/www/example.com core version
Core and updates
wp core check-update
wp core update
wp plugin list --update=available
wp plugin update --all
wp theme update --all
wp core verify-checksums
Plugins and themes
wp plugin install woocommerce --activate
wp plugin deactivate --all
wp theme install twentytwentyfive --activate
Users
wp user list
wp user create editor1 editor@example.com --role=editor --user_pass='LongRandomPassword'
wp user update 1 --user_pass='NewPassword' # recover a lost admin
Database
wp db export backup.sql
wp db import backup.sql
wp db optimize
wp search-replace 'old.com' 'new.com' --all-tables --dry-run
Content and maintenance
wp post list --post_type=page --fields=ID,post_title,post_status
wp cache flush
wp rewrite flush
wp transient delete --expired
wp cron event list
wp cron event run --due-now
wp option get siteurl
wp eval 'echo get_bloginfo("version");'
Tips
--dry-run exists on search-replace (use it first); --format=json or csv makes output scriptable.wp help <command> prints the real flags for your installed version.wp shell for an interactive PHP prompt with WordPress loaded.for loop and --path, or use WP-CLI aliases in wp-cli.yml.