How to use WP-CLI tools?
It is often very useful to manage your WordPress site with command line tools. WP-CLI is created just for that purpose. You first need to connect to the server via SSH to use WP-CLI tools. Read here more about how to connect to your site with SSH.
Commonly used WP-CLI commands::
$ wp plugin list # Prints all plugins...
You can deactivate any plugin like this:
$ wp plugin deactivate awesome-plugin Plugin 'awesome-plugin' deactivated. Success: Deactivated 1 of 1 plugins.
Activate another theme:
$ wp theme activate twentynineteen Success: Switched to 'Twenty Nineteen' theme.
Print all users on your site:
$ wp user list Prints all users...
Print all admin users on your site:
$ wp user list --role=administrator Prints all admin users...
Change password for user with user email address:
$ wp user update firstname.lastname@example.org --user_pass=NewPassword Success: Updated user 7.
Sometimes you might need to replace some changed info (email address for example) to new one to your sites database. You can use this search-replace command:
$ wp search-replace 'email@example.com' 'firstname.lastname@example.org' --all-tables # tip: you can test your command by adding this to the end --dry-run
Custom WP-CLI commands at Seravo
We have created some of our own WP-CLI commands for our servers. Here are some of the most commonly used ones:
We take backups of all our sites every night. But it is often very useful to take a backup when you start modifying your site. You can take a backup with this command:
$ wp-backup ... --> Backup completed Successfully backed up 323 MB of data.
Tests can be run from command line:
$ wp-test ... Time: 9.76 seconds, Memory: 12.00MB I: Finished running wp-test-ng
After modifying your site it might be necessary to empty cache. You can do it like this:
$ wp-purge-cache --> Purging Nginx page cache... Cache purged successfully for example_12345. --> Purging WordPress object cache... Success: The cache was flushed. --> Flush WordPress rewrites... Success: Rewrite rules flushed. --> Flush the entire Redis cache (includes Nginx PageSpeed cache etc)... --> Success
Read more about Seravo custom WP-CLI commands from our developer documentation. Other useful links: wp-cli.org and WordPress developer documentation.