A modern, well-structured WordPress plugin boilerplate built with best practices, following PSR-12 standards and WordPress coding guidelines.
- Modern Architecture: Built with PHP 8.2+ and modern WordPress practices
- PSR-12 Compliant: Follows PHP coding standards
- WordPress Standards: Adheres to WordPress coding guidelines
- Modular Design: Clean separation of concerns with providers pattern
- Security First: Built-in security features and validation
- Performance Optimized: Caching system and performance optimizations
- REST API Ready: Built-in REST API support
- Internationalization: Full i18n support with text domain
- Testing Ready: PHPUnit configuration and test structure
- Code Quality: PHPCS, PHPStan, and automated testing setup
- Documentation: Comprehensive documentation and examples
- WordPress: 5.0 or higher
- PHP: 8.2 or higher
- MySQL: 5.7 or higher
- Composer: For dependency management
your-plugin-name/
βββ admin/ # Admin-specific functionality
β βββ assets/ # Admin CSS, JS, and images
β βββ class-admin.php # Main admin class
β βββ templates/ # Admin page templates
β βββ index.php # Security file
βββ includes/ # Core plugin classes
β βββ class-activator.php # Plugin activation handler
β βββ class-deactivator.php # Plugin deactivation handler
β βββ class-i18n.php # Internationalization
β βββ class-include.php # Main plugin class
β βββ class-loader.php # Hook loader
β βββ class-security.php # Security utilities
β βββ index.php # Security file
βββ providers/ # Feature providers (modular)
β βββ core/ # Core functionality provider
β βββ api/ # REST API provider
β βββ cache/ # Caching provider
β βββ index.php # Provider loader
βββ public/ # Public-facing functionality
β βββ assets/ # Public CSS, JS, and images
β βββ class-public.php # Public class
β βββ index.php # Security file
βββ languages/ # Translation files
βββ tests/ # Test files
β βββ Unit/ # Unit tests
β βββ Integration/ # Integration tests
β βββ Feature/ # Feature tests
β βββ bootstrap.php # Test bootstrap
βββ vendor/ # Composer dependencies
βββ .env.example # Environment variables example
βββ config.php # Plugin configuration
βββ plugin-core.php # Main plugin file
βββ composer.json # Composer configuration
βββ phpunit.xml # PHPUnit configuration
βββ phpcs.xml # PHPCS configuration
βββ README.md # This file
βββ LICENSE # License file
git clone https://github.com/your-username/wordpress-plugin-boilerplate.git your-plugin-name
cd your-plugin-namecomposer install- Update
config.php: Modify all constants to match your plugin - Update
plugin-core.php: Change plugin name, description, and author - Update
composer.json: Change package name and author information - Copy environment file:
cp env.example .envand configure variables
- Update class names: Change
Your_Pluginto your actual class name - Modify providers: Add/remove providers based on your needs
- Update text domain: Change
your-plugin-nameto your actual text domain - Customize admin pages: Modify admin templates and functionality
Upload to your WordPress plugins directory and activate through the admin panel.
The plugin uses environment variables for configuration. Copy env.example to .env and configure:
# Plugin Basic Settings
PLUGIN_NAME="Your Plugin Name"
PLUGIN_SLUG="your-plugin-name"
PLUGIN_VERSION="1.0.0"
PLUGIN_DEBUG_MODE=false
# Database Settings
DB_HOST="localhost"
DB_NAME="wordpress"
DB_USER="wp_user"
DB_PASSWORD="wp_password"
# Security Settings
SECURITY_RATE_LIMITING=true
SECURITY_RATE_LIMIT_REQUESTS=100The config.php file contains all plugin constants and settings:
// Plugin Information
define('Plugin_Core', 'Your Plugin Name');
define('YOUR_PLUGIN_SLUG', 'your-plugin-name');
define('YOUR_PLUGIN_VERSION', '1.0.0');
// Plugin Paths
define('YOUR_PLUGIN_PATH', plugin_dir_path(__FILE__));
define('YOUR_PLUGIN_URL', plugin_dir_url(__FILE__));# Install dependencies
composer install
# Run tests
composer test
# Run specific test suites
composer test:unit
composer test:integration
composer test:feature
# Code quality checks
composer lint
composer lint:fix
composer analyze
# Generate documentation
composer docs
# Build for production
composer build
# Clean development files
composer cleanThe plugin includes a comprehensive testing setup:
# Run all tests
composer test
# Run with coverage
composer test:coverage
# Run specific test suite
composer test:unit# Check coding standards
composer lint
# Fix coding standards automatically
composer lint:fix
# Static analysis
composer analyzeThe plugin uses a provider pattern for modular functionality:
// providers/core/ServiceProvider.php
class Core_ServiceProvider {
public function register() {
// Register services
}
public function boot() {
// Boot services
}
}The plugin includes a robust hook management system:
// Register hooks
$this->loader->add_action('init', $this, 'init');
$this->loader->add_filter('the_content', $this, 'filter_content');Built-in security features include:
- Input validation and sanitization
- Nonce verification
- Rate limiting
- SQL injection protection
- XSS protection
- CSRF protection
The plugin automatically registers REST API endpoints:
// Example endpoint registration
add_action('rest_api_init', function() {
register_rest_route('your-plugin/v1', '/example', [
'methods' => 'GET',
'callback' => 'your_callback_function',
'permission_callback' => 'your_permission_function'
]);
});// Register AJAX actions
add_action('wp_ajax_your_plugin_action', 'your_ajax_callback');
add_action('wp_ajax_nopriv_your_plugin_action', 'your_ajax_callback');// Register shortcodes
add_shortcode('your_shortcode', 'your_shortcode_callback');The plugin includes full i18n support:
// Load text domain
load_plugin_textdomain('your-plugin-name', false, dirname(plugin_basename(__FILE__)) . '/languages');
// Use translation functions
__('Hello World', 'your-plugin-name');
_e('Hello World', 'your-plugin-name');
esc_html__('Hello World', 'your-plugin-name');- Input Validation: All inputs are validated and sanitized
- Nonce Verification: Security tokens for forms and AJAX
- Rate Limiting: Protection against brute force attacks
- SQL Injection Protection: Prepared statements and escaping
- XSS Protection: Output escaping and sanitization
- CSRF Protection: Cross-site request forgery protection
// Validate and sanitize input
$input = sanitize_text_field($_POST['input_field']);
// Verify nonces
if (!wp_verify_nonce($_POST['nonce'], 'action_name')) {
wp_die('Security check failed');
}
// Escape output
echo esc_html($data);
echo esc_url($url);
echo wp_kses_post($html);// Cache data
wp_cache_set('cache_key', $data, 'your_plugin_cache', 3600);
// Retrieve cached data
$cached_data = wp_cache_get('cache_key', 'your_plugin_cache');- Query Optimization: Efficient database queries
- Asset Minification: Minified CSS and JS in production
- Lazy Loading: Deferred loading of resources
- Compression: Automatic response compression
tests/
βββ Unit/ # Unit tests
βββ Integration/ # Integration tests
βββ Feature/ # Feature tests
βββ bootstrap.php # Test bootstrap
βββ TestCase.php # Base test case
// tests/Unit/ExampleTest.php
class ExampleTest extends TestCase {
public function test_example_function() {
$result = example_function();
$this->assertEquals('expected', $result);
}
}# Run all tests
composer test
# Run specific test file
./vendor/bin/phpunit tests/Unit/ExampleTest.php
# Run with coverage
composer test:coverageThe plugin follows PHPDoc standards:
/**
* Example function
*
* @param string $param Parameter description
* @return string Return description
* @since 1.0.0
*/
function example_function($param) {
return $param;
}Generate API documentation:
composer docs- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PSR-12 coding standards
- Include tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting
This project is licensed under the GPL v2 or later - see the LICENSE file for details.
- Documentation: docs.your-plugin.com
- Issues: GitHub Issues
- Email: support@your-plugin.com
- β Initial boilerplate implementation
- β Modern WordPress plugin architecture
- β PSR-12 compliant code structure
- β Comprehensive testing setup
- β Security features and best practices
- β Performance optimizations
- β Full documentation
Developed with β€οΈ by Your Name
- Clone the boilerplate
- Install dependencies with
composer install - Update
config.phpwith your plugin details - Update
plugin-core.phpwith your plugin information - Update
composer.jsonwith your details - Copy
env.exampleto.envand configure - Customize class names and text domains
- Add your custom providers and functionality
- Test the plugin with
composer test - Deploy and activate in WordPress
- Customize the Plugin: Modify the boilerplate to match your needs
- Add Features: Implement your specific functionality
- Write Tests: Add comprehensive tests for your features
- Document: Update documentation for your specific use case
- Deploy: Test in a staging environment before production