I’ve been recently trying to get back to blogging. In fact, I’ve beeen recently trying to do what I set out to do more than one year ago, when I created and launched this blog. For a number of reasons, which I may or may not cover in a future post, that intent has been replaced or delayed for quite some time, but it seems that I’m finally taking action to solve that.
One of the reasons that made me become a bit lazy on the matter, was the “hassle” to maintain the platform that I chose for blogging: wordpress. I’m not complaining about wordpress itself, which is a great blogging tool. However, having been a drupal developer for a few years now, I’m rather used to Drush. In the unlikely event you, the reader, don’t know what Drush is, I suggest you go and read the first paragraph of its readme, but to keep it quick, let’s just say that drush is “a command-line utility for drupal that let’s you tackle all maintenance and deployment aspects of a drupal project during its entire lifecycle.”. That’s the simplest definition I’ve come up with in a few seconds. If you don’t like it, I have others, too.
Having to download wordpress plugins manually, put them on the right folder in my local environment, test them, push to my remote gitlab instance, then deploy the repository to the blog server, and then enable and configure the thing again… no thanks. I just found it way too cumbersome. And, as it happens, the good guys of the wordpress community too. And they created a solution for that: the WP-CLI. What is it? Well, as per the project page:
WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, set up multisite installs and much more, without using a web browser.
I’m not going over the basics to get the tool installed, as it’s dead simple and very well explained in the project page, but just to give you a broad idea of what you can accomplish with this little tool, I’m pasting a picture of the options I get in my command-line after installing wp-cli, and typing “wp”.
In fairness, all commands are pretty useful, but I’ve just highlighted the ones more appealing to me. For example, with eval-file, I can keep a simple script in my project repo to do some database clean up (e.g: updating site-urls to point to my local instance) every time I synchronise my local DB with the one from the server where this blog lives.
As I’ll try to show over time in other posts, I’ve a big crush for automation / code-generation, so the scaffold command seems to me another little pearl that all wordpress developers will love. Needless to say that for the moment, updating plugins, themes and wordpress itself with a few very simple commands, is all I needed, and it just works like a charm.
The best part of the tool, is that it’s not feature-closed. The community can contribute custom commands to deal with the usual tasks of a wordpress project. Documentation to download and use those custom commands is available, too, and there’s, of course, a simple cookbook that goes through the anatomy and creation of a custom command.
Yes, I know, WP-CLI has been around for more than 1 year now. But, as mentioned, my thing all this time has been mostly Drupal, and while I’ve recently spent some time getting off the island, I didn’t really come across the thing until a few weeks ago. So, with this small utility in my belt, one of the reasons why I got lazy about blogging has been removed, and I’ll finally be a bit more active on the keyboard.
To wrap up, I’d like to point out this blog post, in case you’re interested in extending wp-cli. Definitely good learning material.