AbstractWpController
extends AbstractController
in package
Page-controller base for the WordPress adapter — the Inertia counterpart to the REST-only {@see AbstractWpRestController}.
Extends the framework AbstractController (so it inherits the full ControllerInterface surface plus the redirect/flash/response/getService helpers) and adds the two things the framework base leaves to the host:
render()— delegates to the per-request InertiaAdapter resolved from the container, so a controller calls$this->render('Component', $props)instead of wiring Inertia by hand.- the auth gate —
setRequireLogin()/setRequireCapabilities()mapped onto WordPress's own functions.
It deliberately carries NO Moodle-only concerns (sesskey, context objects, page layout/heading/navbar). REST stays on its own base: the WP REST lifecycle (register_rest_route + permission_callback over WP_REST_Request) does not match the kernel request → handle() cycle, so the two bases do not share an inheritance chain (see the adapter's first ADR).
Table of Contents
Methods
- setRequireCapabilities() : void
- Require every listed capability of the current user, or halt with a 403.
- setRequireLogin() : void
- Require an authenticated WordPress user; unauthenticated visitors are sent to the login screen (WordPress's `auth_redirect()` halts and redirects).
- render() : void
- Render an Inertia component through the container-bound adapter.
- inertia() : InertiaAdapter
- Resolve the per-request Inertia adapter from the container.
Methods
setRequireCapabilities()
Require every listed capability of the current user, or halt with a 403.
public
setRequireCapabilities(array<int, string> $capabilities[, string $context = 'system' ][, int $instanceId = 0 ]) : void
WordPress has no Moodle-style context/instance model. The mapping:
$instanceId > 0→current_user_can($cap, $instanceId), i.e. the id is passed as the meta-capability object id WordPress resolves viamap_meta_cap(e.g.current_user_can('edit_post', 123)).$instanceId === 0→current_user_can($cap), a global capability check.$context(string) has no native WordPress equivalent and is advisory only; it is accepted for cross-adapter signature parity and ignored here.
Parameters
- $capabilities : array<int, string>
- $context : string = 'system'
- $instanceId : int = 0
setRequireLogin()
Require an authenticated WordPress user; unauthenticated visitors are sent to the login screen (WordPress's `auth_redirect()` halts and redirects).
public
setRequireLogin() : void
render()
Render an Inertia component through the container-bound adapter.
protected
render(string $component[, array<string, mixed> $props = [] ]) : void
Parameters
- $component : string
- $props : array<string, mixed> = []
inertia()
Resolve the per-request Inertia adapter from the container.
private
inertia() : InertiaAdapter