Every well-built WordPress plugin starts with a solid foundation. A WordPress plugin boilerplate gives you that foundation – a pre-structured starting template with sensible folder organisation, class-based architecture, and hook registration already wired up. Instead of writing the same scaffolding code from scratch every time, you start with a proven structure and focus on the functionality that matters.
This guide covers what a boilerplate is, why it matters, the best options available right now, and how to set up a proper wordpress plugin structure from scratch using OOP patterns and WordPress coding standards. Whether you are building your first custom plugin or your fiftieth, the right starter template saves hours and prevents architectural mistakes that haunt you later.
What Is a WordPress Plugin Boilerplate?
A boilerplate is a reusable starter template that provides the foundational file structure, class organisation, and WordPress integration patterns for a new plugin. Think of it as the framing of a house before any interior work begins.
A good wordpress plugin starter template includes:
- Main plugin file with proper header comments and bootstrap logic
- Organised folder structure separating admin, public, and shared code
- Class-based architecture using autoloading and single-responsibility classes
- Hook registration centralised in a loader class
- Activation and deactivation handlers wired up and ready
- Internationalisation support with text domain loading
- Uninstall routine for clean removal
Without a boilerplate, developers often dump everything into a single file, mix concerns, and create plugins that become impossible to maintain. With one, you start with discipline baked in.
Why Boilerplates Matter for Plugin Development
Consistency across projects
When every plugin you build follows the same structure, onboarding new developers is faster, debugging is easier, and code reviews become straightforward. You know where to find the admin hooks, where the public-facing scripts live, and how activation logic runs.
WordPress coding standards compliance
The best boilerplates are built to follow WordPress Coding Standards from the start. Proper sanitisation helpers, escaping patterns, and nonce verification are either included or clearly marked for implementation.
Faster project kickoff
Instead of spending the first day of every project creating folders, writing the main plugin file, and wiring up hooks, you clone a template and start building features immediately. For agencies handling multiple client projects, this time saving compounds.
Reduced architectural debt
Starting without structure means adding structure later – which means refactoring. Boilerplates prevent the “it works but the code is a mess” problem that plagues plugins built without a plan.
The Best WordPress Plugin Boilerplates
WordPress Plugin Boilerplate by DevinVinson
The most well-known wordpress plugin boilerplate in the ecosystem. This is the community standard that thousands of plugins have been built on.
Repository: github.com/DevinVinson/WordPress-Plugin-Boilerplate
What it provides:
- Clean separation between admin and public code
- A loader class that centralises all hook registration
- Activation, deactivation, and internationalisation classes
- Proper file headers and plugin metadata
- README template following WordPress.org standards
Folder structure:
plugin-name/
plugin-name.php # Main bootstrap file
uninstall.php # Clean uninstall routine
includes/
class-plugin-name.php # Core plugin class
class-plugin-name-loader.php # Hook registration loader
class-plugin-name-i18n.php # Internationalisation
class-plugin-name-activator.php # Activation logic
class-plugin-name-deactivator.php # Deactivation logic
admin/
class-plugin-name-admin.php # Admin-specific hooks
css/
plugin-name-admin.css
js/
plugin-name-admin.js
partials/
plugin-name-admin-display.php # Admin view templates
public/
class-plugin-name-public.php # Public-facing hooks
css/
plugin-name-public.css
js/
plugin-name-public.js
partials/
plugin-name-public-display.php # Public view templates
languages/
plugin-name.pot # Translation template
Best for: Developers who want a battle-tested, community-supported starting point with clear separation of concerns.
Limitation: It has not seen frequent updates recently, and some patterns (like the loader class approach) can feel rigid for modern PHP development.
WP Starter Plugin
A more lightweight alternative that takes a less opinionated approach.
What it provides:
- Minimal folder structure you can extend
- Basic class scaffolding
- Composer support for dependency management
- Simpler hook registration
Best for: Developers who want a leaner starting point and prefer to build up structure as needed rather than stripping down an opinionated template.
Custom Boilerplate (Build Your Own)
Many experienced developers maintain their own boilerplate tailored to how they work. This is the approach I use at devash.pro for production plugins like Leadio and Arcflow.
Advantages of a custom boilerplate:
- Matches your exact workflow and coding style
- Includes your preferred tooling (Composer, build scripts, linting configs)
- Pre-configured for your deployment pipeline
- Can include patterns specific to your stack (REST API scaffolding, custom post type registration, WooCommerce integration hooks)
Best for: Teams and agencies building plugins regularly who need a template that reflects their specific wordpress plugin development best practices.
Setting Up a WordPress Plugin Structure From Scratch
Whether you use an existing boilerplate or build your own, understanding the ideal wordpress plugin structure is essential. Here is what a production-ready plugin looks like.
The Main Plugin File
This file bootstraps everything. It should be lean – define constants, check requirements, and hand off to the core class.
<?php
/**
* Plugin Name: My Custom Plugin
* Plugin URI: https://example.com/my-custom-plugin
* Description: A brief description of the plugin.
* Version: 1.0.0
* Author: Your Name
* Author URI: https://example.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: my-custom-plugin
* Domain Path: /languages
*/
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Plugin constants.
define( 'MCP_VERSION', '1.0.0' );
define( 'MCP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'MCP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
// Autoloader.
require_once MCP_PLUGIN_DIR . 'includes/class-autoloader.php';
// Boot the plugin.
function mcp_init() {
$plugin = new MCPCorePlugin();
$plugin->run();
}
add_action( 'plugins_loaded', 'mcp_init' );
// Activation hook.
register_activation_hook( __FILE__, array( 'MCPCoreActivator', 'activate' ) );
// Deactivation hook.
register_deactivation_hook( __FILE__, array( 'MCPCoreDeactivator', 'deactivate' ) );
Key points:
- Direct access check: every PHP file in your plugin should have this
- Constants: version, directory path, and URL defined once, used everywhere
- Autoloader: no manual
requirestatements scattered through the codebase - Late initialisation: hooking into
plugins_loadedensures WordPress core and other plugins are loaded first
Recommended Folder Structure
my-custom-plugin/
my-custom-plugin.php # Bootstrap file
uninstall.php # Cleanup on deletion
composer.json # Dependency management
includes/
class-autoloader.php # PSR-4 style autoloader
Core/
class-plugin.php # Main orchestrator class
class-activator.php # Activation logic
class-deactivator.php # Deactivation logic
class-i18n.php # Translations
Admin/
class-admin.php # Admin hooks and pages
class-settings.php # Settings API integration
views/
settings-page.php # Admin view templates
Frontend/
class-frontend.php # Public-facing hooks
class-shortcodes.php # Shortcode definitions
views/
shortcode-output.php # Frontend templates
API/
class-rest-controller.php # REST API endpoints
Models/
class-data-model.php # Data layer
assets/
css/
admin.css
frontend.css
js/
admin.js
frontend.js
languages/
my-custom-plugin.pot
This structure separates concerns cleanly. Admin code never touches frontend logic. API endpoints live in their own namespace. Views are isolated from business logic.
Class-Based Architecture
Modern wordpress plugin development best practices demand OOP. Here is how the core plugin class should look:
<?php
namespace MCPCore;
class Plugin {
private $version;
public function __construct() {
$this->version = MCP_VERSION;
}
public function run() {
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_frontend_hooks();
$this->define_api_routes();
}
private function load_dependencies() {
// Dependencies loaded via autoloader.
}
private function set_locale() {
$i18n = new I18n();
add_action( 'plugins_loaded', array( $i18n, 'load_textdomain' ) );
}
private function define_admin_hooks() {
$admin = new MCPAdminAdmin( $this->version );
add_action( 'admin_enqueue_scripts', array( $admin, 'enqueue_styles' ) );
add_action( 'admin_enqueue_scripts', array( $admin, 'enqueue_scripts' ) );
add_action( 'admin_menu', array( $admin, 'add_menu_pages' ) );
}
private function define_frontend_hooks() {
$frontend = new MCPFrontendFrontend( $this->version );
add_action( 'wp_enqueue_scripts', array( $frontend, 'enqueue_styles' ) );
add_action( 'wp_enqueue_scripts', array( $frontend, 'enqueue_scripts' ) );
}
private function define_api_routes() {
$api = new MCPAPIREST_Controller();
add_action( 'rest_api_init', array( $api, 'register_routes' ) );
}
}
This pattern gives you:
- Single entry point: one class orchestrates everything
- Namespacing: no global function pollution
- Dependency injection ready: easy to swap implementations
- Testable: each component can be tested independently
Hook Architecture
How you register hooks defines your plugin’s relationship with WordPress. Here are the patterns that work at scale:
Centralised registration:
Register all hooks in the core plugin class (as shown above) or in a dedicated loader. This means you can see every hook your plugin uses in one place.
Conditional loading:
private function define_admin_hooks() {
if ( ! is_admin() ) {
return;
}
// Admin hooks only loaded in admin context.
}
Priority management:
// Run after most plugins have registered their hooks.
add_action( 'init', array( $this, 'register_post_types' ), 20 );
// Run before output to capture early.
add_action( 'template_redirect', array( $this, 'handle_redirect' ), 5 );
Filter chains for extensibility:
$settings = apply_filters( 'mcp_default_settings', array(
'enabled' => true,
'cache_ttl' => 3600,
'api_limit' => 100,
) );
This lets other developers (or your future self) modify behaviour without editing core plugin files.
Naming Conventions That Prevent Conflicts
WordPress runs in a global environment. Every function, class, and hook name must be unique across all active plugins and themes.
Prefixing rules
- Functions:
mcp_get_user_data()notget_user_data() - Classes:
MCP_Admin_Pageor namespacedMCPAdminPage - Hooks:
mcp_before_savenotbefore_save - Options:
mcp_settingsnotsettings - Database tables:
{$wpdb->prefix}mcp_recordsnot{$wpdb->prefix}records - Script/style handles:
mcp-admin-scriptsnotadmin-scripts - REST routes:
/mcp/v1/datanot/data
Use namespaces over prefixes
PHP namespaces are cleaner than string prefixes for classes:
// Instead of this:
class My_Custom_Plugin_Admin_Settings_Page {}
// Use this:
namespace MCPAdmin;
class Settings_Page {}
Namespaces prevent collisions, reduce class name length, and make autoloading straightforward.
Security Patterns Every Boilerplate Should Include
No boilerplate is complete without security fundamentals baked in.
- Nonce verification on every form submission and AJAX request
- Capability checks before any privileged operation (
current_user_can()) - Input sanitisation on all user input (
sanitize_text_field(),absint(),wp_kses_post()) - Output escaping on all rendered data (
esc_html(),esc_attr(),esc_url(),wp_kses()) - Direct access prevention at the top of every PHP file
- Prepared statements for all database queries (
$wpdb->prepare())
These are not optional extras. They are baseline requirements for any plugin that will run on a production site.
How Production Plugins Use These Patterns
The principles above are not academic. They are how plugins that handle real traffic and real data are built.
At devash.pro, every plugin I ship – from Leadio (lead management with CRM automation) to Arcflow (interactive workflow canvas) to AI2WP (AI-powered page creation) – follows these exact patterns. Namespaced classes, centralised hook registration, separated admin and frontend logic, REST API controllers in their own directory, and security checks on every endpoint.
A multivendor marketplace plugin that handles multi-currency transactions and vendor commission calculations is the kind of functionality where sloppy architecture means lost revenue and broken user experiences. It works because the underlying structure was right from day one.
For agencies building client solutions, this matters even more. When a client comes back six months later needing a feature added, a well-structured plugin means you can find the right file, understand the hook flow, and add functionality without breaking existing behaviour. A single-file plugin with no structure means a rewrite.
Integrating Your Boilerplate With Modern Tooling
A good wordpress plugin starter template should play well with modern development tools:
- Composer for PHP dependency management and autoloading
- npm/Webpack for JavaScript bundling and CSS preprocessing
- PHPStan or Psalm for static analysis
- PHPCS with WordPress coding standards for linting
- GitHub Actions or similar CI for automated testing on push
If you are building plugins that interact with the WordPress REST API, your boilerplate should include a base REST controller class that handles permission checks, schema validation, and response formatting consistently.
Getting Started: Your First Plugin From a Boilerplate
Here is the practical workflow:
- Clone the boilerplate: pick one of the options above or fork and customise
- Search and replace: swap all placeholder names (plugin-name, Plugin_Name, PLUGIN_NAME) with your actual plugin identifiers
- Define your hook strategy: list every WordPress action and filter your plugin needs before writing feature code
- Build feature by feature: add one capability at a time, keeping each in its appropriate directory
- Test continuously: activate on a staging site early and test after each feature addition
- Document as you go: inline comments and a README that explains the plugin’s purpose and configuration
If you want to go deeper into the full plugin development process, my guide on how to build a WordPress plugin covers the end-to-end workflow from concept to deployment.
For agencies considering whether to build in-house or partner with a specialist, my breakdown of custom WordPress plugin development for agencies explains the scoping, budgeting, and outsourcing process.
Need a plugin built on a solid foundation? Whether you need a custom WordPress plugin for a client project or a production-ready product, devash.pro builds plugins that are structured, secure, and maintainable from day one. Get in touch to discuss your project.