Recently I was looking for a way to install the latest version of WordPress plugins that I like to use on my client’s sites without having to FTP. Before I created the small script we’ll see later, I had a directory on my computer with the plugin folders that I would then FTP onto the server. This was a pain because I had to ensure I always updated the plugins on my local machine or else I would have to do it after installing them on the website. I would also have to either wait for them all to upload which could take a while, or upload them as ZIP files, but then I would have to go in, unzip them and then clean up afterwards.
Luckily for me creating a small shell script that gets the newest versions of plugins was actually extremely easy. Before I get into the code though I would like to point out that there is a tool already in existence that does this sort of thing. WP-CLI is a set of command line tools that will help you manage your WordPress install. I would highly install WP-CLI if at all possible – it’s a lot more robust and offers a huge variety of tools that I guarantee you will love if you work with WordPress often!
You can find the shell script I created below:
As you can see the majority of the script simply defines the plugins you want to have installed. After that I use a simple for loop that goes through each of the plugins, downloads it and unzips it. There are some extra
echo lines just so the user knows what’s going on since I decided to hide output from the
unzip command since it takes up a lot of space on the screen. Once this is done the script gets rid of the excess zip files by deleting them, leaving only the folders. This script is meant to be run from within your
plugins directory on a WordPress install.
Also if you’re work is anything like mine you might have a few plugins that you created yourselves that aren’t on the official repository. These are also easy to encoorporate into the script, just add the plugin folder to your base directory where you’re keeping the script and then use something like the following:
As you can see I’ve added code that gets the base directory where the script resides and also code to copy the
ve-branding-settings-plugin folder. Just add more copy commands if you have more plugins to copy.
To install the script simply put it in a folder somewhere accessible and add an alias to your
.bash_profile file. You may remember that this is the same procedure as install the DobsonDev Underscores script which allows you to quickly create a boilerplate theme. This script is actually a kind of extension of that script – I’ve been trying to automate as much as I can so I can spend more time coding and less time setting up installs.
That’s really all there is to it. It’s an extremely simple script that I came up with to solve my problem and it works for me. In the future I would like to add a feature to the script that allows installation of optional plugins for our clients. The way we do things is we will install extra plugins depending if a client wants more features (think of things like events calendars and arena schedulers). Some of these plugins we’ve created ourselves but some we use from the repository, and it’s client specific which ones we include. The plugins included in this script are the ones every client of ours gets no matter what – so it was simple to implement. On that note I also highly recommend all of the plugins I have listed in the plugin – I think they all work beautifully and add a lot to your WordPress installations.
If you are looking for something more robust than this script then I would still recommend picking up WP-CLI if you work with WordPress a lot though – I will most likely be using it rather than this script as well. It has a lot of cool features and is maintained by a really great team so check it out!
As always thank you for reading and please share it around as much as you can! Please feel free to put any suggestions or ideas for future tutorials in the comments section below.