wpdiggerstudio / wpzylos-scaffold
Template repository for creating production-ready WPZylos-based WordPress plugins with MVC architecture, dependency injection, and PHP-Scoper namespace isolation
Fund package maintenance!
Paypal
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:PowerShell
Type:wordpress-plugin
pkg:composer/wpdiggerstudio/wpzylos-scaffold
Requires
- php: ^8.0
- wpdiggerstudio/wpzylos-config: ^1.0
- wpdiggerstudio/wpzylos-container: ^1.0
- wpdiggerstudio/wpzylos-core: ^1.0
- wpdiggerstudio/wpzylos-database: ^1.0
- wpdiggerstudio/wpzylos-hooks: ^1.0
- wpdiggerstudio/wpzylos-http: ^1.0
- wpdiggerstudio/wpzylos-i18n: ^1.0
- wpdiggerstudio/wpzylos-migrations: ^1.0
- wpdiggerstudio/wpzylos-routing: ^1.0
- wpdiggerstudio/wpzylos-security: ^1.0
- wpdiggerstudio/wpzylos-validation: ^1.0
- wpdiggerstudio/wpzylos-views: ^1.0
Requires (Dev)
- humbug/php-scoper: ^0.18
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.6 || ^10.0
- squizlabs/php_codesniffer: ^3.7
- szepeviktor/phpstan-wordpress: ^1.3
- wpdiggerstudio/wpzylos-wp-cli: ^1.0
README
Template repository for creating production-ready WordPress plugins with MVC architecture and PHP-Scoper namespace isolation.
๐ Full Documentation | ๐ Report Issues
โจ Features
- Complete MVC Structure โ Controllers, Services, Views, Routes
- PSR-4 Autoloading โ Modern PHP namespace organization
- PHP-Scoper Ready โ Pre-configured namespace isolation for multi-plugin compatibility
- Service Providers โ Modular dependency injection
- Database Migrations โ Version-controlled schema changes
- WordPress Compliant โ Proper headers, MIT license, readme.txt
- Intelligent CLI โ Version prompting, smart file discovery, auto-versioning
- Build Pipeline โ Scaffold CLI with QA checks and ZIP creation
- Security First โ Nonce verification, capability checks, input sanitization
๐ Requirements
| Requirement | Version |
|---|---|
| PHP | ^8.0 |
| WordPress | 6.0+ |
| Composer | 2.0+ |
| WP-CLI | Optional |
๐ Quick Start
Option 1: Use as GitHub Template
Click "Use this template" on GitHub to create a new repository.
Option 2: Composer Create Project
cd /path/to/wordpress/wp-content/plugins composer create-project wpdiggerstudio/wpzylos-scaffold your-plugin-name cd your-plugin-name
Option 3: Clone and Customize
git clone https://github.com/WPDiggerStudio/wpzylos-scaffold.git your-plugin-name
cd your-plugin-name
rm -rf .git
composer install
Initialize Your Plugin (Recommended)
After creating your project, run the Scaffold CLI to customize and manage your plugin.
Option 1: PowerShell (Windows 10/11)
Open Windows PowerShell (search "PowerShell" in Start menu):
.\scaffold.ps1 # Interactive menu .\scaffold.ps1 init # Initialize plugin directly .\scaffold.ps1 build # Build for production directly
Option 2: Command Prompt (Windows)
Open Command Prompt (cmd.exe). Since .ps1 files don't run directly in cmd, use:
powershell -ExecutionPolicy Bypass -File scaffold.ps1 powershell -ExecutionPolicy Bypass -File scaffold.ps1 init powershell -ExecutionPolicy Bypass -File scaffold.ps1 build
Option 3: Bash (Linux/Mac/Git Bash)
For Linux, macOS, or Git Bash on Windows (install Git for Windows):
chmod +x scaffold.sh # Make executable (first time only) ./scaffold.sh # Interactive menu ./scaffold.sh init # Initialize plugin directly ./scaffold.sh build # Build for production directly
Git Bash alternative: If
./scaffold.shdoesn't work, trybash scaffold.sh
The intelligent init script handles all scenarios:
| Scenario | Behavior |
|---|---|
| Fresh install | Detects my-plugin.php, uses scaffold defaults |
| Re-configure | Loads .plugin-config.json, shows current values as defaults |
| Config deleted | Auto-detects plugin from *.php with "Plugin Name:" header |
| Partial update | Only changes modified values, shows "Skipped" for unchanged |
Features:
- Version Prompting: Sets initial version and updates plugin header + PluginContext
- Namespace support: Supports nested namespaces like
WPDigger\WPBraCalculator
๐ Project Structure
your-plugin/
โโโ app/ # Application code (PSR-4: YourPlugin\)
โ โโโ Core/
โ โ โโโ PluginContext.php # Plugin identity (slug, prefix, text domain)
โ โโโ Lifecycle/
โ โ โโโ Activator.php # Activation logic
โ โ โโโ Deactivator.php # Deactivation logic
โ โ โโโ Uninstaller.php # Uninstall cleanup
โ โโโ Support/
โ โโโ helpers.php # Global helper functions
โโโ bootstrap/
โ โโโ app.php # Application bootstrap & service providers
โโโ config/
โ โโโ app.php # Application configuration
โโโ database/
โ โโโ migrations/ # Database migrations
โโโ resources/
โ โโโ lang/ # Translation files
โ โโโ views/ # PHP view templates
โโโ routes/
โ โโโ web.php # Route definitions
โโโ tests/
โ โโโ Unit/ # PHPUnit tests
โโโ scaffold.ps1 # Scaffold CLI (Windows)
โโโ scaffold.sh # Scaffold CLI (Linux/Mac)
โโโ .scripts/ # CLI scripts
โ โโโ init-plugin.ps1/.sh # Initialization logic
โ โโโ build.ps1/.sh # Build pipeline logic
โโโ your-plugin.php # Main plugin entry point
โโโ uninstall.php # WordPress uninstall handler
โโโ scoper.inc.php # PHP-Scoper configuration
โโโ composer.json # Dependencies
โโโ readme.txt # WordPress.org readme
๐ง Customization
Automated (Recommended)
Run the Scaffold CLI for automated setup:
PowerShell:
.\scaffold.ps1 init
Command Prompt:
powershell -ExecutionPolicy Bypass -File scaffold.ps1 init
Linux/Mac/Git Bash:
./scaffold.sh init
Manual
If you prefer manual customization, perform search and replace:
| Find | Replace With | Description |
|---|---|---|
my-plugin |
your-plugin |
Plugin slug (lowercase, hyphenated) |
my_plugin |
your_plugin |
Scoper prefix (lowercase, underscored) |
MyPlugin |
YourPlugin |
PHP namespace (PascalCase) |
myplugin_ |
yourplugin_ |
Database/option prefix |
My Plugin |
Your Plugin |
Display name |
Files to Update
your-plugin.phpโ Plugin headers, PluginContext configurationcomposer.jsonโ Package name, namespace in autoloadscoper.inc.phpโ Scoper prefix variable.plugin-config.jsonโ Created by init, used by builduninstall.phpโ Context configuration
๐๏ธ Core Components
PluginContext
The PluginContext class (app/Core/PluginContext.php) is the single source of truth for plugin identity. All framework components use this for prefixing.
$context = PluginContext::create([ 'file' => __FILE__, 'slug' => 'your-plugin', 'prefix' => 'yourplugin_', 'textDomain' => 'your-plugin', 'version' => '1.0.0', ]);
Available Methods:
| Method | Returns | Example |
|---|---|---|
slug() |
Plugin slug | your-plugin |
prefix() |
Database prefix | yourplugin_ |
textDomain() |
Translation domain | your-plugin |
version() |
Plugin version | 1.0.0 |
file() |
Main plugin file path | /path/to/your-plugin.php |
path($relative) |
Absolute path | /path/to/your-plugin/config/ |
url($relative) |
Plugin URL | https://site.com/wp-content/plugins/your-plugin/ |
hook($name) |
Prefixed hook name | yourplugin_custom_hook |
optionKey($key) |
Prefixed option key | yourplugin_settings |
transientKey($key) |
Prefixed transient key | yourplugin_cache |
cronHook($name) |
Prefixed cron hook | yourplugin_daily_task |
tableName($name) |
Full table name | wp_yourplugin_orders |
metaKey($key) |
Prefixed meta key | _yourplugin_data |
assetHandle($handle) |
Asset handle | your-plugin-main |
Helper Functions
Global helpers available after bootstrap (app/Support/helpers.php):
// Escaping zylos_e($text); // esc_html() zylos_ea($text); // esc_attr() zylos_eu($url); // esc_url() zylos_ej($text); // esc_js() zylos_kses($html); // wp_kses_post() // Application zylos_app(); // Get application instance zylos_app('service'); // Resolve service from container context(); // Get PluginContext // Translation zylos_m($text); // __($text, $textDomain) zylos_em($text); // echo translated text
โ๏ธ Configuration
config/app.php
return [ 'name' => 'Your Plugin', 'debug' => defined('WP_DEBUG') && WP_DEBUG, 'providers' => [ // \YourPlugin\Providers\CustomServiceProvider::class, ], 'capability' => 'manage_options', ];
Service Providers
The bootstrap (bootstrap/app.php) registers framework service providers in dependency order:
- ConfigServiceProvider โ Configuration and .env loading
- I18nServiceProvider โ Internationalization
- HookServiceProvider โ WordPress hook management
- SecurityServiceProvider โ Nonce, Gate, Sanitizer
- HttpServiceProvider โ Request, Response, Pipeline
- ValidationServiceProvider โ Input validation
- ViewsServiceProvider โ Template rendering
- DatabaseServiceProvider โ Database connection
- MigrationsServiceProvider โ Schema migrations
- RoutingServiceProvider โ URL routing
- WpCliServiceProvider โ WP-CLI commands (when available)
๐ค๏ธ Routing
Define routes in routes/web.php:
use WPZylos\Framework\Routing\Router; return static function (Router $router): void { // Frontend routes $router->get('/products', [ProductController::class, 'index'])->name('products.index'); $router->get('/products/{id}', [ProductController::class, 'show'])->name('products.show'); $router->post('/cart/add', [CartController::class, 'add'])->name('cart.add'); // Route groups with middleware $router->group(['prefix' => '/account', 'middleware' => AuthMiddleware::class], function (Router $router) { $router->get('/dashboard', [AccountController::class, 'dashboard']); $router->post('/update', [AccountController::class, 'update']); }); };
๐จ Build & Release
Development
composer install # Install all dependencies composer test # Run PHPUnit tests composer analyze # Run PHPStan analysis
Production Build
Use the Scaffold CLI for production builds:
Windows (PowerShell):
.\scaffold.ps1 build # Full build (QA + Scoper + ZIP) .\scaffold.ps1 build -SkipQA # Skip code style/analysis checks .\scaffold.ps1 build -SkipScoper # Dev build (skip PHP-Scoper)
Windows (Command Prompt):
powershell -ExecutionPolicy Bypass -File scaffold.ps1 build powershell -ExecutionPolicy Bypass -File scaffold.ps1 build -SkipQA powershell -ExecutionPolicy Bypass -File scaffold.ps1 build -SkipScoper
Linux/Mac (or Git Bash):
./scaffold.sh build # Full build (QA + Scoper + ZIP) ./scaffold.sh build --skip-qa # Skip code style/analysis checks ./scaffold.sh build --skip-scoper # Dev build (skip PHP-Scoper)
The build script will:
- Clean previous build artifacts
- Run
phpcbf --standard=PSR12(code style fix) - Run
phpstan analyze(static analysis) - Install production dependencies
- Run PHP-Scoper for namespace isolation
- Copy required files & rebuild autoloader
- Remove development files
- Create versioned ZIP in
dist/
Note: The build script reads configuration from
.plugin-config.json(created byscaffold init).
Intelligent Features:
- Smart File Discovery: Automatically detects project files/folders and prompts for unknown items
- Preference Persistence: Saves your include/exclude choices for future builds
- Auto-Versioning: Suggests next patch version based on existing ZIP files in
dist/ - Artifact Preservation: Preserves the
dist/directory with previous builds
The production build creates a zip file at dist/your-plugin-1.0.0.zip ready for deployment.
PHP-Scoper
The scaffold includes pre-configured PHP-Scoper (scoper.inc.php) that:
- Prefixes all vendor namespaces for multi-plugin isolation
- Excludes WordPress core functions, classes, and constants
- Excludes your plugin's namespace
- Generates unique build prefixes using git hash
๐งช Testing
# Run all tests composer test # Or ./vendor/bin/phpunit # Run specific test ./vendor/bin/phpunit --filter TestClassName
Tests are located in tests/Unit/. The test bootstrap is at tests/bootstrap.php.
๐ Security
The scaffold implements WordPress security best practices:
- Nonce verification in form submissions
- Capability checks for user permissions
- Prepared statements for database queries
- Output escaping with proper functions
- Input sanitization before processing
See the Security Package for detailed security utilities.
๐ Troubleshooting
Composer create-project fails
php -v # Verify PHP 8.0+ php -m | grep json # Verify json extension
Namespace/autoloader issues
composer dump-autoload
Verify composer.json PSR-4 namespace matches your class namespace.
PHP-Scoper errors
Check scoper.inc.php and ensure WordPress functions are excluded.
Built plugin crashes
Verify WordPress symbols are excluded in scoper configuration.
๐ฆ Related Packages
| Package | Description |
|---|---|
| wpzylos-core | Application foundation |
| wpzylos-container | PSR-11 dependency injection container |
| wpzylos-config | Configuration management |
| wpzylos-routing | URL routing system |
| wpzylos-database | Database abstraction |
| wpzylos-migrations | Database migrations |
| wpzylos-hooks | WordPress hook management |
| wpzylos-security | Security utilities |
| wpzylos-validation | Input validation |
| wpzylos-views | Template rendering |
| wpzylos-http | HTTP request/response |
| wpzylos-i18n | Internationalization |
| wpzylos-wp-cli | WP-CLI integration |
๐ Documentation
For comprehensive documentation, tutorials, and API reference, visit wpzylos.com.
โ Support the Project
If you find this scaffold helpful, consider buying me a coffee! Your support helps maintain and improve the WPZylos ecosystem.
๐ License
This project is licensed under the MIT License. See LICENSE for details.
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Made with โค๏ธ by WPDiggerStudio