Plugin Generator – Advanced Plugin Structure
Complete file structure for creating new plugins with the “Plugin Generator” system.
plugin-generator
README.md
LICENSE
CHANGELOG.md
package.json
composer.json
webpack.config.js
.gitignore
.babelrc
.eslintrc
.stylelintrc
src
Core
PluginGenerator.php
TemplateManager.php
DependencyChecker.php
FileSystem.php
Validator.php
Templates
WordPress
basic-plugin.php
advanced-plugin.php
woocommerce-extension.php
JavaScript
vanilla-js-module.js
react-component.js
vue-component.js
UI
AdminInterface.php
CLIInterface.php
Wizard.php
Utilities
Logger.php
ErrorHandler.php
Notification.php
assets
css
admin.css
frontend.css
js
admin.js
frontend.js
wizard.js
images
icon-128×128.png
icon-256×256.png
banner-772×250.png
languages
plugin-generator.pot
en_US.po
en_US.mo
tests
Unit
PluginGeneratorTest.php
TemplateManagerTest.php
Integration
AdminInterfaceTest.php
FileSystemTest.php
vendor
(Composer dependencies)
dist
(Built assets for production)
docs
API.md
CONTRIBUTING.md
TEMPLATE_GUIDE.md
Key Files Explained
1. PluginGenerator.php (Core Class)
<?php
/**
* Main plugin generator class
*/
class PluginGenerator {
private $templateManager;
private $fileSystem;
private $validator;
public function __construct() {
$this->templateManager = new TemplateManager();
$this->fileSystem = new FileSystem();
$this->validator = new Validator();
}
/**
* Generate a new plugin
*/
public function generate($pluginData) {
// Validate input
if (!$this->validator->validate($pluginData)) {
throw new Exception('Invalid plugin data');
}
// Get templates based on type
$templates = $this->templateManager->getTemplates($pluginData['type']);
// Process each template
foreach ($templates as $template) {
$content = $this->templateManager->render($template, $pluginData);
$this->fileSystem->createFile(
$pluginData['slug'] . '/' . $template['destination'],
$content
);
}
return true;
}
}
2. package.json (Build Configuration)
{
"name": "plugin-generator",
"version": "1.0.0",
"description": "Advanced plugin generator for WordPress and JavaScript projects",
"scripts": {
"build": "webpack --mode production",
"dev": "webpack --mode development --watch",
"test": "phpunit",
"lint": "eslint ./src/js && stylelint ./src/css"
},
"devDependencies": {
"webpack": "^5.0.0",
"webpack-cli": "^4.0.0",
"babel-loader": "^8.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"eslint": "^7.0.0",
"stylelint": "^13.0.0",
"sass-loader": "^10.0.0",
"css-loader": "^5.0.0",
"file-loader": "^6.0.0"
}
}
3. Template Example (basic-plugin.php)
<?php
/**
* Plugin Name: {plugin_name}
* Plugin URI: {plugin_uri}
* Description: {description}
* Version: {version}
* Author: {author}
* Author URI: {author_uri}
* License: {license}
* Text Domain: {text_domain}
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
class {class_name} {
private static $instance = null;
public static function get_instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
$this->define_constants();
$this->init_hooks();
}
private function define_constants() {
define('{constant_prefix}_VERSION', '{version}');
define('{constant_prefix}_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('{constant_prefix}_PLUGIN_URL', plugin_dir_url(__FILE__));
}
private function init_hooks() {
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
add_action('plugins_loaded', array($this, 'load_textdomain'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets'));
}
public function activate() {
// Activation code here
}
public function deactivate() {
// Deactivation code here
}
public function load_textdomain() {
load_plugin_textdomain(
'{text_domain}',
false,
dirname(plugin_basename(__FILE__)) . '/languages/'
);
}
public function enqueue_admin_assets() {
wp_enqueue_style(
'{text_domain}-admin',
{constant_prefix}_PLUGIN_URL . 'assets/css/admin.css',
array(),
{constant_prefix}_VERSION
);
wp_enqueue_script(
'{text_domain}-admin',
{constant_prefix}_PLUGIN_URL . 'assets/js/admin.js',
array('jquery'),
{constant_prefix}_VERSION,
true
);
}
}
{class_name}::get_instance();
Features
- Multi-platform Support: Generate plugins for WordPress, vanilla JS, React, Vue, etc.
- Template System: Customizable templates for different plugin types
- Validation: Input validation for plugin metadata
- Dependency Management: Composer and npm for PHP and JS dependencies
- Build System: Webpack for modern JavaScript bundling
- Testing: PHPUnit for unit and integration tests
- Internationalization: Ready for translation with .pot file
- UI Options: Admin interface and CLI for different workflows