5 Common uses for WP CLI to save time
WP-CLI gives you direct access to WordPress capabilities using the command line. This is helpful during regular development and also makes server automation possible. This is great for easily changing user credentials, deactivating plugins and more.
Logging into Server
ssh username@ip-address
You might be prompted with some additional questions, depending on server settings, then asked for the password.
Next you will want to get into the public_html directory of your WordPress install.
cd folder/public_html
Getting Users and Changing Credentials
Before changing any credentials you should verify the user ID and confirm that user exist. To view all users use the user list
command
wp user list
After confirming the user ID and that the user exists you can now change credentials.
wp user update ID --user_pass=newPassWord
wp user update ID --display_name=John
wp user update ID --role=ROLE_SLUG
// ROLE SLUGS
// administrator , editor, author, contributor, subscriber
You can also do it all at once as well
wp user update ID --user_pass=newPassWord --display_name=John
Creating a new user
If you need to create a new user it is nice to be able to just do it via the WP CLI... saves you from having to login to the site.
wp user create bob bob@example.com --role=author
Deleting a user
To delete a user is similar to updating a user, as you use the ID to reference the user... it is also good to reassign any posts/pages to another when deleting.
wp user delete ID --reassign=EXISTING_ID
Disabling a plugin
Before disabling a plugin you want to get a list of all the current plugins.
ls wp-content/plugins
This gives you a list of all the plugin directory names.
To disable a plugin simply use the deactivate
command.
wp plugin deactivate plugin-folder-name