ddTokenToHeartbeatResponse($response) { $response['mailpoet_token'] = $this->wp->wpCreateNonce('mailpoet_token'); return $response; } public function addEndpointNamespace($namespace, $version) { if (!empty($this->endpointNamespaces[$version][$namespace])) return; $this->endpointNamespaces[$version][] = $namespace; } public function getEndpointNamespaces() { return $this->endpointNamespaces; } public function getRequestedEndpointClass() { return $this->requestEndpointClass; } public function getRequestedAPIVersion() { return $this->requestApiVersion; } public function createErrorResponse($errorType, $errorMessage, $responseStatus) { $errorMessages = [ $errorType => $errorMessage, ]; if ($errorType === Error::BAD_REQUEST) { $mpReinstallErrorMessage = __('The plugin has encountered an unexpected error. Please reload the page. If that does not help, [link]re-install the MailPoet Plugin.[/link]', 'mailpoet'); $mpReinstallErrorMessage = Helpers::replaceLinkTags( $mpReinstallErrorMessage, 'https://kb.mailpoet.com/article/258-re-installing-updating-the-plugin-via-ftp', ['target' => '_blank'] ); $errorMessages[Error::REINSTALL_PLUGIN] = $mpReinstallErrorMessage; } $errorResponse = new ErrorResponse( $errorMessages, [], $responseStatus ); return $errorResponse; } private function logError(Throwable $e): void { // logging to the php log if (function_exists('error_log')) { error_log((string)$e); // phpcs:ignore Squiz.PHP.DiscouragedFunctions } // logging to the MailPoet table $this->loggerFactory->getLogger(LoggerFactory::TOPIC_API)->warning($e->getMessage(), [ 'requestMethod' => $this->requestMethod, 'requestEndpoint' => $this->requestEndpoint, 'exceptionMessage' => $e->getMessage(), 'exceptionTrace' => $e->getTrace(), ]); } }