LanguageNegotiation.php
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace WPML\PB\Helper;
class LanguageNegotiation {
/**
* @return bool
*/
public static function isUsingDomains() {
return apply_filters( 'wpml_setting', [], 'language_domains' )
&& constant( 'WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN' ) === (int) apply_filters( 'wpml_setting', 1, 'language_negotiation_type' );
}
/**
* @param string $languageCode Language code.
*
* @retun string|null
*/
public static function getDomainByLanguage( $languageCode ) {
return wpml_collect( self::getMappedDomains() )->first( function( $domain, $code ) use ( $languageCode ) {
return $languageCode === $code;
} );
}
/**
* @return array
*/
private static function getMappedDomains() {
$defaultLanguage = apply_filters( 'wpml_default_language', null );
$homeUrl = apply_filters( 'wpml_permalink', get_home_url(), $defaultLanguage );
$defaultDomain = wp_parse_url( $homeUrl, PHP_URL_HOST );
$domains = apply_filters( 'wpml_setting', [], 'language_domains' );
$domains[ $defaultLanguage ] = $defaultDomain;
return $domains;
}
}