Skip to content

CLI Generators

Lukman Nakib edited this page May 30, 2026 · 1 revision

CLI Generators

WP-CLI commands that scaffold features from stubs using the real conventions, plus the create-project Personalizer. All are registered under defined('WP_CLI') next to matrix:clean.

Generators

wp matrix:make:model Book          # app/Model/Book.php (static $table/$fillable/$rules/$sortable)
wp matrix:make:migration create_books_table   # database/migrations/<ts>_create_books_table.php
wp matrix:make:controller Book     # app/Http/Controllers/BookController.php (fill→validate→save→respond)
wp matrix:make:listpage Book       # app/Admin/BookListPage.php + registers in AdminServiceProvider::$pages
wp matrix:make:adminpage Reports   # app/Admin/ReportsPage.php + registers it
wp matrix:make:route --method=GET --path=books --controller=Book --action=index   # appends to app/routes.php
wp matrix:make:resource Book       # model + migration + controller + listpage + routes, in order
wp matrix:make:types               # app/Support/RouteNames.php + resources/js/admin/types/wppmRoutes.d.ts

Every generator:

  • presence-checks its target — refuses to overwrite an existing file unless --force,
  • injects registrations idempotently (re-running won't duplicate the use / $pages / Router:: lines),
  • supports --dry-run (writes nothing; shows what it would do).

Run wp help matrix:make:<thing> for per-command options. Stubs live in the root stubs/ directory — edit them to change what your team's generators produce.

make:types — editor-awareness

wp matrix:make:types reads the live Router registry and emits:

  • app/Support/RouteNames.php — PHP constants for every route name,
  • resources/js/admin/types/wppmRoutes.d.ts — TypeScript types for window.wppmRoutes,

so $rest('GET', 'books.index') autocompletes and type-checks. Regenerate it after adding routes.

Personalizer (create-project)

composer create-project wp-plugin-matrix/starter my-plugin runs rename-plugin.php via post-create-project-cmd. It prompts for the plugin name, namespace, and vendor, rewrites every identity token (longest-first so compound tokens like WP_PLUGIN_MATRIX_VERSION aren't clobbered), sets the <vendor>/<slug> composer name, skips vendor//node_modules//.git//dist/, writes only changed files, and deletes itself on success. Preview with php rename-plugin.php "My Plugin" --dry-run.

Clean

wp matrix:clean            # strip the Task demo → blank starter

See Demo & Reset.

Clone this wiki locally