cessful * * or [ok: bool, error: string, dns: array] if domain verification failed * * or [error: string, status: bool] for other errors */ public function verifyAuthorizedSenderDomain(string $domain): array { $records = $this->bridge->getAuthorizedSenderDomains(); $allDomains = $this->returnAllDomains($records); $alreadyExist = in_array($domain, $allDomains); if (!$alreadyExist) { // can't verify a domain that does not exist throw new \InvalidArgumentException(self::AUTHORIZED_SENDER_DOMAIN_ERROR_NOT_CREATED); } $verifiedDomains = $this->getFullyVerifiedSenderDomains(true); $alreadyVerified = in_array($domain, $verifiedDomains); if ($alreadyVerified) { // no need to reverify an already verified domain throw new \InvalidArgumentException(self::AUTHORIZED_SENDER_DOMAIN_ERROR_ALREADY_VERIFIED); } $response = $this->bridge->verifyAuthorizedSenderDomain($domain); // API response contains status, but we need to check that dns array is not included if ($response['status'] === API::RESPONSE_STATUS_ERROR && !isset($response['dns'])) { throw new \InvalidArgumentException($response['message']); } $this->currentRecords = null; $this->reloadCache(); return $response; } public function getSenderDomainsByStatus(array $status): array { return array_filter($this->getAllRawData(), function(array $senderDomainData) use ($status) { return in_array($senderDomainData['domain_status'] ?? null, $status); }); } /** * Returns sender domains that have all required records, including DMARC. */ public function getFullyVerifiedSenderDomains($domainsOnly = false): array { $domainData = $this->getSenderDomainsByStatus([self::DOMAIN_STATUS_VERIFIED]); return $domainsOnly ? $this->extractDomains($domainData) : $domainData; } /** * Returns sender domains that were verified before DMARC record was required. */ public function getPartiallyVerifiedSenderDomains($domainsOnly = false): array { $domainData = $this->getSenderDomainsByStatus([self::DOMAIN_STATUS_PARTIALLY_VERIFIED]); return $domainsOnly ? $this->extractDomains($domainData) : $domainData; } public function getUnverifiedSenderDomains($domainsOnly = false): array { $domainData = $this->getSenderDomainsByStatus([self::DOMAIN_STATUS_UNVERIFIED]); return $domainsOnly ? $this->extractDomains($domainData) : $domainData; } public function getFullyOrPartiallyVerifiedSenderDomains($domainsOnly = false): array { $domainData = $this->getSenderDomainsByStatus([self::DOMAIN_STATUS_PARTIALLY_VERIFIED, self::DOMAIN_STATUS_VERIFIED]); return $domainsOnly ? $this->extractDomains($domainData) : $domainData; } private function extractDomains(array $domainData): array { $extractedDomains = []; foreach ($domainData as $data) { $extractedDomains[] = $this->domainExtractor($data); } return $extractedDomains; } private function domainExtractor(array $domainData): string { return $domainData['domain'] ?? ''; } public function getSenderDomainsGroupedByStatus(): array { $groupedDomains = []; foreach ($this->getAllRawData() as $senderDomainData) { $status = $senderDomainData['domain_status'] ?? 'unknown'; if (!isset($groupedDomains[$status])) { $groupedDomains[$status] = []; } $groupedDomains[$status][] = $senderDomainData; } return $groupedDomains; } /** * Little helper function to return All Domains. alias to `array_keys` * * The domain is the key returned from the Bridge::getAuthorizedSenderDomains */ private function returnAllDomains(array $records): array { $domains = array_keys($records); return $domains; } private function reloadCache() { $currentRawData = $this->bridge->getRawSenderDomainData(); if (!$currentRawData) return; // Do not modify cache if there is no data from the API $this->currentRawData = $currentRawData; $this->wp->setTransient(self::SENDER_DOMAINS_KEY, $this->currentRawData, 60 * 60 * 24 * 7); } public function isCacheAvailable(): bool { return is_array($this->wp->getTransient(self::SENDER_DOMAINS_KEY)); } private function getAllRawData(): array { if ($this->currentRawData === null) { $currentData = $this->wp->getTransient(self::SENDER_DOMAINS_KEY); if (is_array($currentData)) { $this->currentRawData = $currentData; } else { $this->reloadCache(); } } return is_array($this->currentRawData) ? $this->currentRawData : []; } private function getAllRecords(): array { if ($this->currentRecords === null) { $this->currentRecords = $this->bridge->getAuthorizedSenderDomains(); } return $this->currentRecords; } public function isNewUser(): bool { $installedVersion = $this->settingsController->get('version'); // Setup wizard has not been completed if ($installedVersion === null) { return true; } $installedAfterNewDomainRestrictions = $this->settingsController->get(self::INSTALLED_AFTER_NEW_RESTRICTIONS_OPTION, false); if ($installedAfterNewDomainRestrictions) { return true; } return $this->newsletterStatisticsRepository->countBy([]) === 0; } public function isSmallSender(): bool { return $this->subscribers->getSubscribersCount() <= self::LOWER_LIMIT; } public function isBigSender(): bool { return $this->subscribers->getSubscribersCount() > self::UPPER_LIMIT; } public function isAuthorizedDomainRequiredForNewCampaigns(): bool { return $this->settingsController->get('mta.method') === Mailer::METHOD_MAILPOET && !$this->isSmallSender(); } public function isAuthorizedDomainRequiredForExistingCampaigns(): bool { return $this->settingsController->get('mta.method') === Mailer::METHOD_MAILPOET && $this->isBigSender(); } public function getContextData(): array { return [ 'verifiedSenderDomains' => $this->getFullyVerifiedSenderDomains(true), 'partiallyVerifiedSenderDomains' => $this->getPartiallyVerifiedSenderDomains(true), 'allSenderDomains' => $this->getAllSenderDomains(), 'senderRestrictions' => [ 'lowerLimit' => self::LOWER_LIMIT, 'alwaysRewrite' => false, ], ]; } public function getContextDataForAutomations(): array { $data = $this->getContextData(); $data['senderRestrictions']['alwaysRewrite'] = true; return $data; } }
Fatal error: Uncaught Error: Class "MailPoet\Services\AuthorizedSenderDomainController" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:4838 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(4828): MailPoetGenerated\FreeCachedContainer->getAuthorizedSenderDomainControllerService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(926): MailPoetGenerated\FreeCachedContainer->getAuthorizedEmailsControllerService() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5592): MailPoetGenerated\FreeCachedContainer->getSettingsService() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2612): MailPoetGenerated\FreeCachedContainer->getDotcomLicenseProvisionerService() #4 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getHooks2Service() #5 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #6 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #7 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #8 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #9 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...') #10 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #11 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #12 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #13 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #14 /htdocs/index.php(17): require('/htdocs/wp-blog...') #15 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 4838