Scaffolding a WordPress Plugin in an Afternoon
I've been developing WordPress plugins for a lot of years now, and over that time the one boilerplate I used was the WordPress Plugin Boilerplate. It's good. I've built a fair number of plugins on it and I'm grateful it exists. But there was always one thing that bugged me: I was shoehorning my thinking into somebody else's. I had to use their methodology, their way of laying things out, their way of naming things. It worked, but it was never quite mine.
And I've always been a big believer that with AI, I can do things the way I want to do them. So when I sat down to build the first plugin I actually wanted to register on WordPress.org, with a few more lined up behind it, I decided to stop borrowing and work out my own way.
I've always been a bit like that. When we started Clear Purple, our office was above a hardware store, and I built a huge desk from two doors with a frame underneath, so my partners could sit at each end. The scaffold came from the same place: build the thing you need from what's there.
Going down the rabbit hole on plugin one
I went quite deep on that first plugin. Deeper than I probably needed to. I worked out how I wanted the classes structured, how I wanted the naming to work, how the text domains should be set up, how languages and translations should be handled, where the CSS and JS should live. Basically everything.
Once I had it the way I liked it, I back-engineered it. I took what I'd built and turned it into a generator. That's the WP Plugin Scaffold. Nothing fancy. It's a PHP script, a set of templates, and a JSON config file. I've used it to build my free and pro plugins ever since.
Why consistency matters when AI writes the code
The real reason I did it this way: the AI is writing most of the code now. That's just how I work. Which means I need a way to check that code, quickly and confidently, across every plugin I maintain.
The easiest way I know to check something is to already know what it should look like. So I wanted:
- Very similar class naming across every plugin, so I know where to look before I even open a file.
- Very similar documentation, so the PHPDoc and readmes read the same way every time.
- Very similar text domains, set up the same way, so i18n is never a guess.
- CSS and JS always in the same place, no hunting.
- Admin pages that are properly WordPress-centric: WordPress styling, the WordPress way of building admin screens. No custom UI framework bolted on top.
That last point matters to me because most of what I build are back-end plugins. I've done very few front-end ones. So the admin screen is the product, and I want it to feel like it belongs in WordPress.
When every plugin has the same shape, reviewing AI-written code stops being a treasure hunt. If something is in the wrong place or named oddly, it sticks out straight away.
Why the scaffold isn't AI-generated
This is the part I feel quite strongly about. I didn't want to rely on the AI to create the plugin scaffold itself. If I asked an agent to "set up a new plugin" every time, I'd get something slightly different every time, and the whole point of consistency goes out the window.
So the requirement was simple: I want to run a PHP script, point it at a config file I've written, and have it build the plugin for me. Same input, same output, every time. Then I bring the AI in to do the actual work inside that frame.
An AI will always give you a slightly different result. An AI that uses a tool gives you the same, or very, very similar, result every time. So the scaffold does the structure, and the AI does the work inside it.
I also tried to keep it as simple as possible. Let me show you how it works.
Generating a plugin, step by step
You'll need PHP 7.4 or newer on the command line, plus Composer and WP-CLI for the lint and translation scripts inside the generated plugin.
1. Clone the scaffold
git clone https://github.com/djm56/wp-plugin-scaffold.git
cd wp-plugin-scaffold
2. Start from an example config
There are three worked examples in config/examples/: a free and pro pair, a free-only plugin, and a pro-only plugin that never goes near WordPress.org. Copy whichever is closest to what you're building:
cp config/examples/free-only.json config/acme-maintenance-mode.json
Your own configs in config/ are gitignored on purpose. A config names an unreleased product, its tier split and its tags, and that's not something I want sitting in a public repo before launch.
3. Edit the config
This is where you actually describe your plugin. Here's a free-only example for a simple maintenance-mode plugin:
{
"_comment": "EXAMPLE — free-only plugin. No \"pro\" key, so there is no pro variant to generate. allow_free_upsell is false because there is nothing to upsell; leaving it true would emit an Upgrade page that goes nowhere.",
"family": "maintenance-mode",
"brand": {
"vendor": "Acme Web Co",
"vendor_slug": "acme-web",
"author_uri": "https://example.com",
"css_prefix": "acme",
"menu_parent_label": "Acme Tools"
},
"license": "GPL-2.0-or-later",
"license_uri": "https://www.gnu.org/licenses/gpl-2.0.html",
"contributor_usernames": "acmeweb",
"plugin_tags": "maintenance,coming-soon",
"allow_free_upsell": false,
"requires_at_least": "6.0",
"tested_up_to": "6.8",
"requires_php": "7.4",
"free": {
"name": "Acme Maintenance Mode",
"slug": "acme-maintenance-mode",
"text_domain": "acme-maintenance-mode",
"description": "Show a maintenance page to visitors while you work on the site.",
"plugin_uri": "https://example.com/acme-maintenance-mode",
"version": "1.0.0",
"constant_prefix": "ACMEMM",
"option_key": "acmemm_options",
"namespace": "Acme_Maintenance_Mode",
"main_class": "Plugin",
"module_class": "Module",
"settings_class": "Settings",
"plugin_file": "acme-maintenance-mode.php",
"features": {
"analytics": false,
"admin_analytics": false,
"cron": false,
"meta_registration": false,
"bulk_actions": false,
"shortcode": false,
"ajax": false,
"has_css": true,
"has_js": false,
"frontend": true
}
}
}
A few things worth pointing out:
The brand block is mandatory. All five fields are validated and none of them have defaults. That's deliberate. A generator that quietly drops its own author's name into someone else's plugin is the kind of bug you only find out about after it ships.
slug has to match text_domain. The generator checks this. It's a small thing, but it's exactly the kind of small thing that causes translation headaches later.
Feature flags decide what gets emitted at all. If a feature is false, its code simply isn't generated. I learned this one the hard way. An earlier version generated the upsell code into every plugin and switched it off with a condition, and I ended up with an "Upgrade to Pro" screen inside a premium plugin that had no pro tier. Dead code has a way of coming back to life, so now it's just not there.
frontend defaults to false. Most of my plugins are admin tools, and an admin tool has no business hooking into every post on the front end. A maintenance-mode plugin really does need to show something to visitors, so in this example it's switched on.
4. Generate the plugin
php generator/generate.php --config config/acme-maintenance-mode.json --type free --output ./_generated
If something in the config is wrong (a missing brand field, a bad slug, too many tags for WordPress.org), it stops with a clear error instead of generating half a plugin.
If you're building a free and pro pair, you just run it twice, once per type:
php generator/generate.php --config config/my-plugin.json --type free --output ./_generated
php generator/generate.php --config config/my-plugin.json --type pro --output ./_generated
5. Look at what you got
_generated/acme-maintenance-mode/
├── acme-maintenance-mode.php entry file, headers, bootstrap
├── uninstall.php cleanup on deletion
├── composer.json PHP deps + lint and i18n scripts
├── package.json npm wrappers
├── phpcs.xml.dist WordPress coding standards
├── README.md / readme.txt developer + WordPress.org docs
├── CHANGELOG.md release history
├── includes/
│ ├── class-acme-maintenance-mode.php
│ ├── class-acme-maintenance-mode-module.php
│ └── class-acme-maintenance-mode-settings.php
├── languages/
│ └── acme-maintenance-mode.pot
└── assets/
└── css/admin.css
That's the shape every one of my plugins has. Main class, module, settings. Same files, same places, every time.
The admin screens are built from core WordPress admin markup (.wrap, .form-table, .notice, submit_button()), so they look native out of the box.
6. Lint it, build the translation file, check versions
cd _generated/acme-maintenance-mode
composer install
composer lint
composer i18n:pot
A freshly generated plugin comes out clean against the WordPress coding standards: zero errors, zero warnings. My rule is to keep it that way. One tip: always run composer lint from the plugin root. PHPCS looks for its config in the folder you're standing in, and if you run it from somewhere else it silently falls back to the wrong standard.
Then, back in the scaffold folder, check that the version number matches everywhere it needs to:
cd ../..
bash scripts/verify-version-sync.sh ./_generated/acme-maintenance-mode
That checks the plugin header, the readme.txt stable tag and the changelog all agree. It's boring, and it's exactly the kind of boring thing that gets a WordPress.org submission bounced.
And that's it. That's a compliant, lint-clean plugin ready for real work, before the AI has written a single line.
Where the AI comes in
Once the scaffold exists, that's when I hand over to the agents. And this is where the consistency pays off. The AI isn't deciding where files go or how classes are named, because that's already been decided. It's working inside a frame it can't really get wrong.
What the scaffold doesn't decide, and shouldn't, is the stuff that's actually the point of the plugin:
- Scope. What the plugin does, and just as importantly, what it won't do.
- Hooks. Which WordPress hooks it registers and what each one is allowed to touch.
- Option keys and data. How settings are named and stored. Get this sloppy and it bites you later.
- Uninstall behaviour. What gets cleaned up when someone removes the plugin. WordPress.org cares about this, and users definitely do.
Those are judgement calls, not blanks in a form. That's my job. The scaffold just clears everything else out of the way so I can spend the afternoon on them.
Find what works for you
Coming back to what I really think about all of this: to work well with AI, you need to work out the way that works best for you. Use the tools you're comfortable with. Build around how you already think.
I didn't want to shoehorn my ideas into what everyone else was doing. I wanted the AI to be an extension of how I work, not a replacement for it. This scaffold is one small piece of that. It's my way of building plugins, written down once, so that every plugin after it starts from the same place and every line the AI writes lands somewhere I recognise.
If it's useful to you, take it and change it. Better yet, build your own.
More in this series
- Up: How I Build WordPress Plugins With AI
- Category: Building Plugins With AI
- Related: Working With AI, the bigger picture on shaping AI around how you already work.
Next: Free on WordPress.org, Pro Direct: Structuring a Plugin for Both, on Tuesday 22 December: what the free and pro split looks like in practice, and what I'd do differently.