Use a WP CLI command to prepare your plugins for release
Last updated • October 29th, 2019
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Excludes files and directories that aren’t needed in the release (configurable).
Zips up the copy into an archive with a filename matching your plugin.
Extracts the plugin version from the plugin headers and appends that to the filename.
Adds a custom suffix to archive if you need it.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I just include this in my wp-config.php file and register it with WP CLI using the following:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters