Spinning up a new WordPress project is a pain. From the tooling around it to finding a consistent development environment can often feel like an exercise in futility. It doesn’t have to be this way.
This past weekend I refactored and relaunched a project I started working with during my days at the University of Florida. Generator-wp is a Yeoman generator that will create either a basic WordPress site or a starter plugin to get a new project running in the shortest amount of time for teams with any level of WordPress experience.
What makes a good WordPress project generator?
The needs of everyone may differ but, from my experience on numerous teams across the WordPress spectrum there are a few things that can really make all the difference when getting started with a new WordPress project.
A stable development environment
First and, in my experience, most important is a stable development environment. I’ve worked with many teams that have limited WordPress experience where even the simplest plugin or theme can quickly get derailed while the team tries to figure out how to work on it.
While there are a number of tool choices to build your development environment on I’ve settled, for now, on Lando. It is essentially a Docker wrapper that makes running multiple sites very and, most importantly, portable. Simply checking a project out, installing minimal dependencies (Lando and Docker) and running a start command is enough to get a project running.
Once a project is running locally it should provide a basic and standardized set of tooling to perform common tasks including starting, stopping, step-debugging and other basic functionality.
Generator-wp addresses basic tooling with a few features. First, it uses a Makefile to handle the project itself. Start, stop, destroy, open and more are self-contained and can get a project going fast.
Next is Xdebug, a debugging tool for PHP that is packaged and configured with your new project so that stopping on a line of code is as easy as setting your breakpoint and pressing run within VSCode.
Speaking of VSCode, I’ve even included a set of recommended extensions so that everyone working on the project will have a standardized set of extensions to make development in VSCode that much easier.
Static analysis is also included and configured to the WordPress Coding Standards so that your IDE will automatically help you find and fix issues that could lead to bugs and other problems later. There’s even a GitHub Actions configuration to make sure no errors escape your notice once you push to GitHub.
Enough code to get started
Once we get code running and our tooling setup it’s time to actually start writing code. WordPress plugins can differ in their approach here in many ways but there are a few things that can make getting started easier.
Generator-wp creates the main plugin file and populates it with an auto-loader to make adding more PHP code easier. It also initializes internationalization, adds the proper plugin headers and gives you an uninstall.php file to make sure you remember to clean up after yourself if someone uninstalls your plugin.
A base to start testing
Finally, WordPress testing can be daunting for many. As a result I’ve added basic PHPUnit tests for the autoloader which will make extending your test suite easy as you build your plugin. These can run in a make command and will run automatically when you push to GitHub via GitHub actions.
Where is this project going?
So where is this project going? For that matter, why this over many of the other starter plugins already available?
There’s a few answers to both of this questions but let’s start with the why this question. Most plugin scaffolds are opinionated well beyond the “getting started” stage while not including much in the way of basic tooling, especially around the development environment. I’ve built this project up to address all of that with a consistent set of tooling so switching projects won’t require re-learning a whole new set of commands to make things work.
To put it simply this solves my own need of building numerous small plugins for various applications. Generator-wp simply makes doing so much easier by ensuring I can focus on the code and not on the development environment and other tooling around it.
As to where it’s going, I have a few ideas there too. I’m currently working on adding proper acceptance testing with Codeception. This will address the long-time need for actually testing plugins in a reproducible way and the way users experience them. After that I plan to expand to plugin components such as blocks, custom post types and more as the need and time arises.
Try it today
Are you looking for a way to build a plugin without the hassle? Checkout generator-wp and give it a shot. It might just make your development experience that much easier.