Moderate WordPress comments with WP-CLI

I very much appreciate comments that bring new insights, corrects my errors, or leaves a thank you note. But even so, it is a bit tedious to moderate comments. Though logging into WordPress – even with two-factor authentication enabled – isn’t much of a hassle, it is still a nuisance when you just want to approve or trash a couple of comments.

Moderating comments with WP-CLI is possible but involves quite a bit of typing – which is better than navigating and clicking around with a mouse – but still is tedious.

Fortunately, WP-CLI can produce output that is easy to parse, which makes it easy to use in a bash script. So I put together a bash script which fetches all unmoderated comments, outputs info about the comment – including which post it is for – and prompts me to select an action. If I don’t know what to do with the comment yet, I can just skip to the next one. I trash a lot of support requests, but some comments are in the grey area between support and legit questions.

The script is not beautiful. It is crude, but it was quick to put together, and it works well for me. It requires you to SSH into the box where you have WordPress installed, but with WP-CLI’s SSH capabilities, it should be easy to extend to use from your local machine. I haven’t tried it, but I believe it can run without any modification with a proper WP-CLI config file.

I’m using this with a ~/.wp-cli/config.yml with path set. You might want to do that too, or adjust the script accordingly.

The WP-CLI comment moderation bash script

Here’s the script, licensed under an extremely relaxed license, so do what you want with it if you want to:

The script works well for me now, but if you use it with any modifications, I’d be very happy if you share it in the comments – and I’ll approve the comment as fast as I can ;-)

Oh, and by the way: If you have a WordPress multisite network, it will go through all your sites asking you what to do with every comment on every site.