This is a modern approach (I think) for building Enterprise WordPress plugins. I have consolidated all necessary tech stack that I know off that makes building scalable, enterprise-level plugins that will power your WordPress application.
✅ MVC Architecture: Separation of Models, Views, and Controllers for maintainability and clean code.
✅ Dependency Injection: This promotes loose coupling, testability, and reusability.
✅ React Frontend: Use modern JavaScript (React) for dynamic UI parts.
✅ Autoloading via PSR-4 standards (Composer).
✅ Hook Management: Organized action and filter registration.
✅ WP REST API: Build robust, scalable RESTful endpoints using the native WordPress REST API framework.
✅ Scalable Structure: Designed with scalability in mind — easy to extend without being limited by rigid architecture.
✅ Unit testing: Built-in PHPUnit setup for testing use cases — helps catch regressions early and ensures code reliability.
✅ PHP Code Sniffers: Enforces WordPress Coding Standards using phpcs to maintain code consistency and improve readability.
wp-plugin-boilerplate/
├── dist/ # Compiled frontend assets (JS, CSS, images from React build)
├── includes/ # Core backend architecture (MVC, routing, DI)
│ ├── Blocks/ # Registers Gutenberg blocks
│ ├── Controllers/ # Handles requests, connects models, returns responses or views
│ ├── Interfaces/ # PHP interfaces for loose coupling and consistent structure
│ ├── Models/ # Business logic and data representations
│ │ ├── Data/ # Data transfer objects (DTOs) and simple data structures
│ │ └── DB/ # Establish database connections and query logic
│ ├── RewriteRules/ # Custom WordPress rewrite rules
│ ├── Roles/ # Custom WordPress roles
│ ├── Routes/ # Registers REST API routes
│ ├── Shortcodes/ # Custom WordPress shortcodes
│ └── PluginLoader.php # Initializes and loads all components from `includes/`
├── Pages/ # View layer / page entry points (React or PHP-based)
├── src/ # React source code (uncompiled)
│ ├── blocks/ # Gutenberg blocks
│ └── pages/ # React-based views/pages
├── tests/ # PHPUnit tests (unit/integration tests for Models, Controllers, Routes, etc.)
├── vendor/ # Composer-managed PHP dependencies
├── scripts/ # Scripts for bundling Gutenburg blocks
├── index.php # WordPress fallback/index entry
├── wp-plugin-boilerplate.php # Main plugin bootstrap file
├── vite.config.js # Vite configuration file for bundling
├── .gitignore # List of ignored files and folders
├── package.json # JavaScript package manifest (npm/yarn)
├── phpcs.xml # PHP_CodeSniffer configuration (defines coding standard, e.g. WordPress)
├── phpunit.xml # PHPUnit configuration file (bootstrap file, coverage, test suites)
└── composer.json # PHP dependencies and autoloader config
- PHP 7.4+
- WordPress 5.8+
- Node.js + npm (for React build)
- Composer
- Clone the repository:
git clone https://github.com/itumulak/wp-plugin-biolerplate.git- Install PHP Dependencies
composer install- Install frontend dependencies and build React:
npm install- Activate the plugin in the WordPress admin dashboard.
Ensure that your blocks are registered in Includes\Blocks\BlockLoader.php:
<?php
namespace Itumulak\Includes\Blocks;
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
class BlockLoader {
public function init(): void {
add_action( 'init', array( $this, 'blocks' ) );
}
public function blocks(): void {
// Register your blocks here...
// new Block( 'blocks/newsletter-sample' );
}
}To build and compile:
npm run buildTo build React components (non-Gutenburg blocks), ensure they are registered in vite.config.js.
...
v4wp({
input: {
samplenotes: 'src/pages/SampleNotes/main.jsx', // Add your react components.
},
outDir: 'dist'
}),
],
...To build and compile:
npm run build:vitecomposer zipFor checking for formatting issues:
composer phpcs <REPLACE_WITH_PHP_PATH_FILES>
To fix formats and coding violation. For simple formats/violation only:
composer phpcbf <REPLACE_WITH_PHP_PATH_FILES>By default we are using WordPress coding standard for sniffing out code violation. I have filter out a few rule here. Feel free modify phpcs.xml if you want modify the sniffer rules to meet your objectives.
To unit test:
composer testFeel free to include your own unit test to meet your objectives.
This project includes a Github Workflow. It simply run unit testing and PHPCS for code violation. Feel free to add more steps.
Docker setup
- Install Docker.
Clone wp-docker-server:
git clone https://github.com/itumulak/wp-docker-server[!TIP] Modify values in
.envsuch as ports, DB name, DB password, etc. to your preference.
Run docker-compose.yml.
docker compose up -dGo to https://localhost:8080 (or what port you have define in .env) and complete the wordpress installation.
Copy the whole WP Plugin Boilerplate folder into your working wordpress docker instance.
cp -r <PATH_OF_WP_PLUGIN_BOILERPLATE> /var/www/html/<PROJECT_NAME_PATH>/wordpress_data/wp-content/plugins/- Switch to Preact?
- Improve handling of database table changes.
Add GitHub workflows.Refactor and refine codebase for registering hooks.Utilize PHP Code Sniffer to the project. Go away with PSR-4?Add PHP unit test.Provide Gutenburg support.