wp-plugin-init
Version:
CLI to scaffold a PHP plugin boilerplate structure
93 lines (72 loc) • 3.4 kB
Markdown
# wp-plugin-init
**Modern WordPress Plugin Framework Generator**
Scaffold a production-ready WordPress plugin built on the **WPSuitePress framework** — dependency injection, an `$wpdb` model/query builder, schema migrations, a REST router with controllers, WP-CLI commands, and a Vue 3 + Vite frontend — with a single command.
## What it does
`wp-plugin-init` generates a plugin that is a thin *application* on top of the reusable [`wpsuitepress/framework`](https://github.com/Suite-Press/wpsuitepress-framework) Composer package. The framework is bundled into the plugin's `vendor/` and **namespace-scoped per plugin** at install time, so multiple SuitePress-based plugins can run side by side without class collisions.
### Generated architecture
```
my-plugin/
├── my-plugin.php # constants + returns boot/app.php
├── boot/
│ ├── app.php # bootstrap: container, lifecycle, plugins_loaded → init
│ ├── bindings.php # your service container bindings
│ └── helpers.php # my_plugin_app() / _config() / _view()
├── config/
│ ├── app.php # slug, text_domain, hook_prefix, rest_namespace, versions
│ └── menu.php # admin menu definition
├── app/
│ ├── App.php # plugin facade (extends framework App)
│ ├── Dev/ComposerScript.php # namespace-scoping script
│ ├── Hooks/
│ │ ├── Handlers/ # Activation, Deactivation, AdminMenu, Asset, RestRoute
│ │ ├── CLI/Commands.php # wp my-plugin migrate | info
│ │ ├── actions.php
│ │ └── filters.php
│ ├── Http/
│ │ ├── Controllers/ # DashboardController (REST)
│ │ └── Routes/api.php # Route::get('/stats', ...)->auth('manage_options')
│ ├── Models/Example.php # Example::query()->where(...)->get()
│ └── Views/admin-dashboard.php
├── database/
│ ├── DBMigrator.php # runs + version-tracks migrations
│ └── Migrations/ExampleMigrator.php
├── resources/js/ # Vue 3 + Vite (HMR)
├── language/ # i18n target
└── composer.json # requires + scopes the framework
```
## Requirements
- Node.js 16+
- Composer 2+
- PHP 7.4+
- The `wpsuitepress/framework` repository must be reachable (configured as a VCS repo in the generated `composer.json`).
## Usage
```bash
npx wp-plugin-init my-plugin
# or: npm i -g wp-plugin-init && wp-plugin-init my-plugin
```
This generates `my-plugin/`, replaces all identifiers, runs `composer install`
(pulling and namespace-scoping the framework), then installs and builds the
frontend assets.
### Generated identifiers (for `suite-one`)
| Concern | Value |
|---|---|
| Namespace | `SuiteOne\` |
| Framework namespace | `SuiteOne\Framework\` |
| Constants | `SUITE_ONE_VERSION`, `SUITE_ONE_PATH`, … |
| Hook prefix | `suite_one/` |
| REST base | `/wp-json/suite-one/v1` |
| WP-CLI | `wp suite-one <command>` |
| JS global | `SuiteOneSettings` |
## After generation
```bash
cd my-plugin
npm run dev # Vite dev server with HMR
npm run build # Production assets
composer install # Re-run if the framework repo was offline
```
## License
MIT © Ruman Ahmed