-
Notifications
You must be signed in to change notification settings - Fork 0
Routing
Lukman Nakib edited this page May 30, 2026
·
1 revision
All HTTP-shaped entry points are declared in app/routes.php through the Router — one line each.
Names are the contract; URLs and admin-ajax action slugs are implementation details.
use WPPluginMatrix\Core\Router;
use WPPluginMatrix\Http\Controllers\BookController;
// REST — wp-json/wp-plugin-matrix/v1/...
Router::rest('books.index', 'GET', '/books', [BookController::class, 'index']);
Router::rest('books.update', 'POST', '/books/(?P<id>\d+)', [BookController::class, 'update']);
// AJAX — wp-admin/admin-ajax.php
Router::ajax('books.stats', 'GET', [BookController::class, 'stats']);- Signature:
Router::rest($name, $method, $path, $handler)andRouter::ajax($name, $method, $handler). - Handlers are first-class callables
[Controller::class, 'method']— your editor can resolve and rename them. (Closures and'Controller@method'strings also work.) - Default capability is
manage_options; pass a 5th/4th arg to change it.
The framework emits every registered route's URL + a nonce as window.wppmRoutes. The Vue side reads it
through resources/js/admin/Bits/AppMixins.js — never hand-build an admin-ajax.php?action=… URL:
this.$get('books.stats') // AJAX GET
this.$post('books.store', { title: 'Dune' }) // AJAX POST
this.$rest('GET', 'books.index', { page: 1 }) // REST GET
this.$rest('PUT', 'books.update', body, { id })// REST with path paramTwo nonce contexts, handled for you:
-
AJAX routes verify
_wpnonceagainst thewp_plugin_matrixaction (sent asnonce). -
REST routes use WordPress cookie auth, which validates
X-WP-Nonceagainst thewp_restaction — so Localized Routes also expose a separaterestNonce, and the JS sends it for REST calls.
Requests are rebased to the current origin (window.location.origin) so they stay same-origin and
authenticated even when the admin is browsed on a different host than the configured WordPress Address.
wp matrix:make:route --method=GET --path=books --controller=Book --action=index
wp matrix:make:types # regenerate RouteNames.php + wppmRoutes.d.ts for editor autocompleteWP Plugin Matrix · GPL-2.0-or-later · source · pages are generated from docs/wiki/ — edit there, not in the wiki UI.
Seams
Tooling