return []; } $this->wpFunctions->setTransient($cacheKey, $rawResponse, self::TRANSIENT_EXPIRATION); } $response = json_decode($this->wpFunctions->wpRemoteRetrieveBody($rawResponse), true); if (!is_array($response) || (array_key_exists('success', $response) && $response['success'] === false)) { $this->logError("MailPoet: Failed to fetch translations from WordPress.com API with code 200 and response: " . json_encode($response)); return []; } return $response['data']; } private function selectUpdatesToInstall(array $responseData) { $installedTranslations = $this->wpFunctions->wpGetInstalledTranslations('plugins'); $translationsToInstall = []; foreach ($responseData as $pluginName => $languagePacks) { foreach ($languagePacks as $languagePack) { // Check revision date if translation is already installed. if (array_key_exists($pluginName, $installedTranslations) && array_key_exists($languagePack['wp_locale'], $installedTranslations[$pluginName])) { $installedFromWpOrg = ($pluginName === $this->freeSlug) && ($installedTranslations[$pluginName][$languagePack['wp_locale']]['Project-Id-Version'] !== self::MAILPOET_FREE_DOT_COM_PROJECT_ID); $installedTranslationRevisionTime = new CarbonImmutable($installedTranslations[$pluginName][$languagePack['wp_locale']]['PO-Revision-Date']); $newTranslationRevisionTime = new CarbonImmutable($languagePack['last_modified']); // In case installed translation pack comes from WP.org make sure that the one coming from WP.com has newer date if ($installedFromWpOrg && $newTranslationRevisionTime <= $installedTranslationRevisionTime) { $languagePack['last_modified'] = $installedTranslationRevisionTime->addSecond()->toDateTimeString(); $newTranslationRevisionTime = new CarbonImmutable($languagePack['last_modified']); } // Skip if translation language pack is not newer than what is installed already. if ($newTranslationRevisionTime <= $installedTranslationRevisionTime) { continue; } } $translationsToInstall[] = [ 'type' => 'plugin', 'slug' => $pluginName, 'language' => $languagePack['wp_locale'], 'version' => $languagePack['version'], 'updated' => $languagePack['last_modified'], 'package' => $languagePack['package'], 'autoupdate' => true, ]; } } return $translationsToInstall; } private function removeDuplicateTranslationsFromOrg(array $translationsDotOrg, array $translationsDotComData) { $localesAvailableFromDotCom = array_unique(array_column($translationsDotComData, 'wp_locale')); return array_filter($translationsDotOrg, function ($translation) use($localesAvailableFromDotCom) { if ( $translation['slug'] !== $this->freeSlug || !in_array($translation['language'], $localesAvailableFromDotCom, true) ) { return true; } return false; }); } private function logError(string $message): void { if (class_exists(Debugger::class)) { Debugger::log($message, ILogger::ERROR); } if (function_exists('error_log')) { error_log($message); // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged } } /** * @return array|\WP_Error */ private function fetchApiResponse(array $requestBody) { // Ten seconds, plus one extra second for every 10 locales. $timeout = 10 + (int)(count($requestBody['locales']) / 10); $body = wp_json_encode($requestBody); if ($body === false) { return new WP_Error('wp_json_encode_error', 'Failed to encode request body to retrieve translations'); } $response = $this->wpFunctions->wpRemotePost(self::API_UPDATES_BASE_URI, [ 'body' => $body, 'headers' => ['Content-Type: application/json'], 'timeout' => $timeout, ]); return $response; } }
Fatal error: Uncaught Error: Class "MailPoet\Config\TranslationUpdater" not found in /htdocs/wp-content/plugins/mailpoet/lib/Config/Localizer.php:75 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/lib/Config/Localizer.php(17): MailPoet\Config\Localizer->getUpdater(Object(MailPoet\WP\Functions)) #1 /htdocs/wp-content/plugins/mailpoet/lib/Config/Localizer.php(13): MailPoet\Config\Localizer->setupTranslationsUpdater(Object(MailPoet\WP\Functions)) #2 /htdocs/wp-content/plugins/mailpoet/lib/Config/Initializer.php(477): MailPoet\Config\Localizer->init(Object(MailPoet\WP\Functions)) #3 /htdocs/wp-content/plugins/mailpoet/lib/Config/Initializer.php(230): MailPoet\Config\Initializer->setupLocalizer() #4 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(90): MailPoet\Config\Initializer->init() #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/lib/Config/Localizer.php on line 75