en = isset($data['token']) ? trim($data['token']) : null; if (!$this->requestEndpoint || !$this->requestMethod || !$this->requestApiVersion) { $errorMessage = __('Invalid API request.', 'mailpoet'); $errorResponse = $this->createErrorResponse(Error::BAD_REQUEST, $errorMessage, Response::STATUS_BAD_REQUEST); return $errorResponse; } else if (!empty($this->endpointNamespaces[$this->requestApiVersion])) { foreach ($this->endpointNamespaces[$this->requestApiVersion] as $namespace) { $endpointClass = sprintf( '%s\%s', $namespace, ucfirst($this->requestEndpoint) ); if ($this->container->has($endpointClass)) { $this->requestEndpointClass = $endpointClass; break; } } $this->requestData = isset($data['data']) ? WPFunctions::get()->stripslashesDeep($data['data']) : []; // remove reserved keywords from data if (is_array($this->requestData) && !empty($this->requestData)) { // filter out reserved keywords from data $reservedKeywords = [ 'token', 'endpoint', 'method', 'api_version', 'mailpoet_method', // alias of 'method' 'mailpoet_redirect', ]; $this->requestData = array_diff_key( $this->requestData, array_flip($reservedKeywords) ); } } } public function processRoute() { try { if ( empty($this->requestEndpointClass) || !$this->container->has($this->requestEndpointClass) ) { throw new \Exception(__('Invalid API endpoint.', 'mailpoet')); } $endpoint = $this->container->get($this->requestEndpointClass); if (!method_exists($endpoint, $this->requestMethod)) { throw new \Exception(__('Invalid API endpoint method.', 'mailpoet')); } if (!$endpoint->isMethodAllowed($this->requestMethod, $this->requestType)) { throw new \Exception(__('HTTP request method not allowed.', 'mailpoet')); } if ( class_exists(Debugger::class) && class_exists(DIPanel::class) && class_exists(ApiPanel::class) ) { ApiPanel::init($endpoint, $this->requestMethod, $this->requestData); DIPanel::init(); } // check the accessibility of the requested endpoint's action // by default, an endpoint's action is considered "private" if (!$this->validatePermissions($this->requestMethod, $endpoint->permissions)) { $errorMessage = __('You do not have the required permissions.', 'mailpoet'); $errorResponse = $this->createErrorResponse(Error::FORBIDDEN, $errorMessage, Response::STATUS_FORBIDDEN); return $errorResponse; } $response = $endpoint->{$this->requestMethod}($this->requestData); return $response; } catch (Exception $e) { $this->logError($e); return $this->errorHandler->convertToResponse($e); } catch (Throwable $e) { if (class_exists(Debugger::class) && Debugger::$logDirectory) { Debugger::log($e, ILogger::EXCEPTION); } $this->logError($e); $errorMessage = $e->getMessage(); $errorResponse = $this->createErrorResponse(Error::BAD_REQUEST, $errorMessage, Response::STATUS_BAD_REQUEST); return $errorResponse; } } public function validatePermissions($requestMethod, $permissions) { // validate method permission if defined, otherwise validate global permission return(!empty($permissions['methods'][$requestMethod])) ? $this->accessControl->validatePermission($permissions['methods'][$requestMethod]) : $this->accessControl->validatePermission($permissions['global']); } public function setTokenAndAPIVersion() { echo sprintf( '', esc_js($this->wp->wpCreateNonce('mailpoet_token')), esc_js(self::CURRENT_VERSION) ); } public function addTokenToHeartbeatResponse($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(), ]); } }
Fatal error: Uncaught Error: Class "MailPoet\API\JSON\API" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:656 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getAPIService() #1 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #2 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #3 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #4 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #5 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...') #6 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #7 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #8 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #9 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #10 /htdocs/index.php(17): require('/htdocs/wp-blog...') #11 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 656