ictionary, if not it will try to retrieve the first one that * contains the country code. * * @param array $languageCodes * @return string */ protected function extractValidLanguageCode(array $languageCodes) { // TODO Need Assertion to ensure $languageCodes is not empty and contains only strings /** * Filter Allowed Language Codes * * @param array $allowedLanguageCodes */ $allowedLanguageCodes = apply_filters( self::FILTER_ALLOWED_LANGUAGE_CODE_SETTING, self::ALLOWED_LANGUAGE_CODES ); if (empty($allowedLanguageCodes)) { // TODO Need validation for Language Code return (string)$languageCodes[0]; } foreach ($languageCodes as $index => $languageCode) { if (in_array($languageCode, $allowedLanguageCodes, true)) { return $languageCode; } } foreach ($languageCodes as $languageCode) { foreach ($allowedLanguageCodes as $currentAllowedLanguageCode) { $countryCode = substr($currentAllowedLanguageCode, 0, 2); if ($countryCode === $languageCode) { return $currentAllowedLanguageCode; } } } return self::SETTING_LOCALE_DEFAULT_LANGUAGE; } /** * Init all the gateways and add to the db for the first time * @param $gateway */ protected function updateGatewaySettings($gateway) { $gateway->settings['enabled'] = $gateway->is_available() ? 'yes' : 'no'; update_option( $gateway->id . "_settings", $gateway->settings ); } }