API / Minn\Runtime / AjaxController

AjaxController final readonly class

Minn\Runtime\AjaxController · public/minn/src/Minn/Runtime/AjaxController.php · 80 lines

admin-ajax.php, the endpoint plugins post their front-end work to: a form submitted without a reload, a spam check, a background job. The action a request names runs the handlers registered as wp_ajax_{action} for a signed-in visitor and wp_ajax_nopriv_{action} for anyone else, answered as the reference answers them (contracts/runtime.md "admin-ajax.php").

It is an admin request: is_admin() is true while the plugins load and admin_init fires before the handler. A handler usually ends the request itself (wp_send_json, wp_die, exit), so the endpoint's headers go out before it runs; one that returns is followed by the reference's "0".

Constants and properties

constPATH = '/wp-admin/admin-ajax.php'
privateCORE = array ( 'wp_ajax_nopriv_' => array ( 'heartbeat' => 'wp_ajax_nopriv_heartbeat', ), 'wp_ajax_' => array ( 'rest-nonce' => 'wp_ajax_rest_nonce', 'heartbeat' => 'wp_ajax_heartbeat', ), )

The core actions the endpoint answers itself, under the prefix for who is asking: the action => the handler.

privateADMIN_FILTERS = array ( 0 => array ( 0 => 'wp_refresh_nonces', 1 => 'wp_refresh_heartbeat_nonces', ), )

The filters the reference's admin includes add once plugins have loaded: the hook, the callback.

Public

staticclaims(Minn\Http\Request $request): bool#

Whether a request is for the endpoint, which the runtime boots as an admin request.

methoddispatch(Minn\Http\Request $request): Minn\Http\Response* /wp-admin/admin-ajax.php (public)#

Runs the handlers registered for the action the request names.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateaction(Minn\Http\Request $request): ?string#

The action the request names, the posted field over the query's, or null when there is none to run.

privateallowedOrigin(): array#

The two cross-origin headers, for an Origin that is this site's own address; empty for any other.

privateregisterCore(string $prefix): void#

The reference registers its own actions after admin_init, only those for who is asking, ahead of a plugin's.