WordPress CLI

Posted on 2017/07/29 at 8:27 pm

Neon Green Text of WordPress CLI

As a person who is more comfortable in a terminal environment than GUI, I love finding tools that make my life easier and more comfortable. When I started using WordPress I was often aggravated by the fact that I had to move around an interface rather than just typing up some html or a command to get a task done. Obviously, that method works well for small scale projects but less so when one is managing a lot of content and pages. WordPress just makes life easier in that respect. But I still like having lower level access and this is where WordPress CLI comes in. WordPress CLI is a command line interface for managing Wordpress sites. Things like updating the core, plugins, or themes is made faster since I SSH often into my site's box and can type up some commands quickly to do those tasks and much more. As such, I wanted to make a simple collection of commands that everyone will find useful. But first, we need to install the plugin....

Installing WordPress CLI

As per the sites instructions, it is extremely easy to get up and running. All one simply needs to do is download the file, chmod it, and move it to the proper location. To download:

wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
OR
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Next, let us make it runnable. Simply type:

chmod +x wp-cli.phar

Let's make sure the file is working properly.

php wp-cli.phar --info

From there, we are ready to move it to its new home. Simply type:
*Note: You might need to use sudo depending on your level of access to the server.

mv wp-cli.phar /usr/local/bin/wp

Using WordPress CLI

OK, now that WordPress CLI is installed we are set to use it. The first thing to do though is cd to the WordPress directory. This is usually somewhere in /var. Once there, it's time to play with some of the commands. First things first, one should know what plugins and themes are installed. To do that, simply type:

wp plugin list && wp theme list

This will list all the slugs associated with the plugins themes. One needs them in order to do things like disable, remove, and install them. Now, let us say that we got from the above commands:

Plugins:
+--------------------------------+----------+--------+---------+
| name                           | status   | update | version |
+--------------------------------+----------+--------+---------+
| add-from-server                | active   | none   | 3.3.3   |
| akismet                        | active   | none   | 3.3.3   |
| backup                         | inactive | none   | 1.1.46  |
| maintenance-mode-free          | active   | none   | 1.2     |
+--------------------------------+----------+--------+---------+

Themes
+-----------------+----------+--------+---------+
| name            | status   | update | version |
+-----------------+----------+--------+---------+
| twentyfifteen   | active   | none   | 1.8     |
| twentyseventeen | inactive | none   | 1.3     |
| twentysixteen   | inactive | none   | 1.3     |
+-----------------+----------+--------+---------+

We notice that Akismet is installed and know too that we are transitioning to use a different plugin to handle spam fighting. To uninstall it we do the following:

wp plugin deactivate akismet && wp plugin delete akismet

If we want it back, we can do the following:

wp plugin install akismet && wp plugin activate akismet

Now, we should update or at least check to see if there is an update needed.

wp plugin update akismet

The same principles are used with themes as well. Replace akismet with the theme name from the list and you get the same results but for themes. The only differences are that instead of plugin we use theme in the command and to disable a theme one needs to use the term disable rather than deactivate. Like so:

wp theme disable twentyfifteen

Final Thoughts

As a final thought or two, it is worth noting how to find the slug for a plugin or theme. To do that, go to either https://wordpress.org/plugins/ or https://wordpress.org/themes/. From there, after finding something worth while, look at the end of the url to find what we need. For this example, use the plugin bbpress and look at the end of its URL: https://wordpress.org/plugins/bbpress/. Supplant that information like so:

wp plugin install bbpress && wp plugin activate bbpress

This will then install the plugin and activate it. Welp, this covers the basics and gets one started but there are other commands that are available. Simply go to their site to find them.


To Top

To Bottom