DEV3 Technologies home

DEV3 Developer Forum

Which WP-CLI commands should I know for managing plugins, users and the database?

WordPress helpSolved0 views
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

1 reply

dev3 · Accepted answer

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.
  • Use wp shell for an interactive PHP prompt with WordPress loaded.
  • Loop over sites with a shell for loop and --path, or use WP-CLI aliases in wp-cli.yml.
0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.