Introduction
If you are a WordPress developer you need to be using WP-CLI. I honestly can't imagine not having WP-CLI in my arsenal. It simplifies a lot of common WordPress tasks, allowing you to perform them right from your terminal. Here is a list of some of the commands I use most frequently.
Download WordPress core files
This is something you'll usually run at the start of a project when you're getting WordPress all setup. It's also helpful when you're setting up an existing WordPress website on a new environment (staging, production, etc.).
bash
You can specify a certain version by adding the --version
flag.
bash
Update WordPress core files
This is really handy when performing any kind of maintenance. You can update WordPress to the latest version without having to leave your developer tools.
It can also be super helpful if you ever need to revert WordPress to a previous version for whatever reason. For example, maybe you updated WordPress to the latest version and something in the new update conflicts with a plugin or something in your code. This is a great way to quickly revert to a previous version while you figure out what's going on.
bash
You can specify a certain version by adding the --version
flag.
bash
If you are downgrading versions you will also need to add the --force
flag.
bash
Create a new user
Quickly create a new user from the command line. This is really handy when you're working on a site where you may have been given access to the server, but you haven't been given an account yet. Instead of having to contact someone and waiting for them to create you an account for you, you can easily create one from the command line.
Possible user roles include ‘administrator’, ‘editor’, ‘author’, ‘contributor’, ‘subscriber’.
bash
Update a user's password
If you've ever forgotten your password, or maybe you didn't write it down when you created your user, you can easily update your password with this command. In the command below you would replace 123
with the id of the user whose password you are updating.
bash
Change your active theme
This command allows you to quickly switch to a different theme. Maybe something is messed up on your website and you want to check if the issue is related to your theme or something else, like possibly a plugin. You can quickly switch to a different theme with this command and see if the issue is present on that theme as well. Then you can quickly switch back.
bash
Plugins
Install a plugin
The easiest way to install plugins you find on wordpress.org. Find the plugin you want, copy the name from the end of the url, and download it from the command line.
bash
You can add the --activate
flag to activate the plugin once it's installed.
bash
See a list of all installed plugins
This will show you all the plugins you have installed on your website. It will show you which plugins are active and inactive. It will also tell what version each plugin is on, and whether or not there are any updates available.
bash
Update plugins
Quickly update plugins from the command line.
You can update a specific plugin by running the following:
bash
You can update all plugins with available updates by running the following. Be aware that this may not update all plugins. Some premium plugins may still need to be updated manually.
bash
Generate a wp-config file
This one can be really helpful when you're automating stuff. I use Gitpod as part of my development workflow, and this is really handy to quickly spin up a fresh copy of any WordPress website I work on. This will create a fresh wp-config.php
file using the info you provide it.
bash
Setup a starter database
This is another one that's really useful when automating your workflow. It can also be really helpful when creating a new WordPress build. This allows you to quickly set up the database tables with information you provide.
bash
Was this post helpful?