WordPress Plugin
WordPress Plugin Template
Josh's WordPress plugin starter
| Name |
|---|
| Getting Started |
| PHP |
| JavaScript |
| Local Development |
| CI/ CD |
This is my – Josh Pollock – opinionated boilerplate and template for WordPress plugin with PSR-4 autoloader, TypeScript, Docker, Github actions, and other fun stuff.
Creating A Plugin
This plugin is a template. You can create a new Github project from this repo using the “Use This Template” button, or by downloading the plugin from Github.
There is a CLI for renaming things, or you can rename things manually.
Notes:
- When you first install with Yarn, many packages will prompted for what version to install, choose the latest.
Rename With ClI
You can create two different versions of the plugin, using the CLI
Everything
This option includes everything: local dev, Typescript, composer autoloader, PHP tests, JavaScript tests, etc.
- Create a new git repo based on this template.
- Clone that repo locally
- Install
yarn
- Rename plugin and update translation domain, fucnction prefix, namespace, etc.
yarn rename
Basic
This version has less things, it does not use Yarn workspace or Typescript or composer. It generates one PHP file that can load JS/CSS and a WordPress-friendly webpack that can have any number of entry points.
- Copy or clone this repo locally.
git clone git@github.com:Shelob9/wordpress-plugin.git
- Install
yarn
- Rename plugin and update translation domain, function’s prefix, namespace, etc.
yarn rename:basic
- This will create a directory named for your plugin slug.
- Copy that somewhere else.
- Delete everything else.
- Switch to directory with the new plugin in it
- Install
yarn
- Build
yarn build
Manual Renaming
After making your own version, I recommend you follow these steps, before running composer install:
- Choose a slug, and root namespace for your plugin.
- Change main plugin file’s name from
wordpress-plugin.phpto match your plugin slug. - Find and replace, with case sensitivity, “wordpress-plugin” with your plugin’s slug in all files.
- Text domain
- Plugin name in package.json and composer.json
tests/bootstrap.phpincludes main plugin file.
- In composer.json change
Josh\\WordPressPlugin\\in both autoloader to match your new root namespace. - Find and replace
WordPressPluginin php files with your root namespace. - Fine and replace
shelob9.gihub.iowith your Github pages site URL. - Enable Github pages for your repo.
- Now you have a documentation site!
Suggestions
- Customize wp-env configuration.
- Change port
- Add additional plugins or themes.
- See: Local dev documentation
Plugin Quickstart
- Git clone:
git clone https://github.com/Shelob9/wordpress-plugin
- Composer install
composer install
- Yarn install.
- Ensure unit tests pass
composer test
- Start WordPress
npx wp-env start