PHIL KURTH

Email

Use a WP CLI command to prepare your plugins for release

If you’ve built plugins you’ve undoubtedly spent a whole lot of time and energy finishing up on sweet new feature X only to then face the hurdle of having to prep the whole shebang for release.

I was tired of hitting that final hurdle whilst working on the ACF Custom Database Tables plugin so I decided to do something clever – I automated stuff.

At first, I had a bash script that was doing all the goods for me. It was basically just a command that had the plugin’s directory and various details hard-coded into it. It was decent and saved me time but kinda fell on its face when I moved the dev installation to another directory and forgot about the command…

At that point, I was like “Dafuq am I doing? Why aren’t I using WP CLI?!”

So that’s where I took it next and I’m so glad I did! It’s been super-duper handy and the release process is now super-duper dandy as I no longer have to think hard or work through a checklist in order to make a release-ready archive of a plugin. All I need to do is run wp makerelease on the command line and an archive will be prepared in the wp-content/releases directory with the plugin version in the filename.

Let’s take a quick look at the command options

There isn’t a lot. You either define a custom suffix or you don’t.

What does the command actually do?

  1. Uses rsync to create a copy of the plugin dir.
  2. Excludes files and directories that aren’t needed in the release (configurable).
  3. Zips up the copy into an archive with a filename matching your plugin.
  4. Extracts the plugin version from the plugin headers and appends that to the filename.
  5. Adds a custom suffix to archive if you need it.
  6. Opens up the directory containing your new release.

The command class

The following class is an invokable class the represents one command. You can customise the command along with the file exclusions and a few other bits by modifying the class constants.

FYI, this particular example is namespaced to a project I’m working on so you should change that to suit your own plugin.

How to set it up

I just include this in my wp-config.php file and register it with WP CLI using the following:

One last thing…

If you liked this article, I'd be incredibly grateful if you tweeted about it.

Also, I don't send emails often but when I do, I try to fill them full of useful goodies. If you like code snippets & dev tips, join my mailing list. There's no catch but I'll probably want to tell you about any new plugins & tools I build.