/** * This method will be called when WP will execute * ajax action handler, and will be stop whole PHP * process execution at the end of execution of this * method, because WP work in such a way. */ public function __invoke() { $response = $this->factory->make(Response::class); $request = Request::createFromEnvironment($this->factory->make(Environment::class, ['items' => $_SERVER + $_REQUEST])); $callable = $this->callable; $result = $callable($request, $response); if (!$result instanceof MessageInterface) { echo $result; } else { foreach ($result->getHeaders() as $name => $headers) { foreach ($headers as $header) { @header($name . ': ' . $header); } } echo (string) $result->getBody(); } $this->wpService->wp_die(); }