PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/links-domain.php +21 -9 2.72.0.12 View file →
@@ -20,10 +20,10 @@
20 20 parent::__construct( $model );
21 21
22 22 $this->hosts = $this->get_hosts();
23 23
24 - // Filter the site url ( mainly to get the correct login form )
25 - add_filter( 'site_url', array( $this, 'site_url' ) );
24 + // Filrer the site url ( mainly to get the correct login form )
25 + add_filter( 'site_url', array( $this, 'site_url' ) );
26 26 }
27 27
28 28
29 29 /**
@@ -37,9 +37,9 @@
37 37 * @return string modified url
38 38 */
39 39 public function add_language_to_link( $url, $lang ) {
40 40 if ( ! empty( $lang ) && ! empty( $this->hosts[ $lang->slug ] ) ) {
41 - $url = preg_replace( '#://(' . wp_parse_url( $this->home, PHP_URL_HOST ) . ')($|/.*)#', '://' . $this->hosts[ $lang->slug ] . '$2', $url );
41 + $url = str_replace( '://' . parse_url( $this->home, PHP_URL_HOST ), '://' . $this->hosts[ $lang->slug ], $url );
42 42 }
43 43 return $url;
44 44 }
45 45
@@ -53,14 +53,29 @@
53 53 * @return string modified url
54 54 */
55 55 public function remove_language_from_link( $url ) {
56 56 if ( ! empty( $this->hosts ) ) {
57 - $url = preg_replace( '#://(' . implode( '|', $this->hosts ) . ')($|/.*)#', '://' . wp_parse_url( $this->home, PHP_URL_HOST ) . '$2', $url );
57 + $url = preg_replace( '#:\/\/(' . implode( '|', $this->hosts ) . ')#', '://' . parse_url( $this->home, PHP_URL_HOST ), $url );
58 58 }
59 59 return $url;
60 60 }
61 61
62 62 /**
63 + * Returns the language based on language code in url
64 + * links_model interface
65 + *
66 + * @since 1.2
67 + * @since 2.0 add $url argument
68 + *
69 + * @param string $url optional, defaults to current url
70 + * @return string language slug
71 + */
72 + public function get_language_from_url( $url = '' ) {
73 + $host = empty( $url ) ? $_SERVER['HTTP_HOST'] : parse_url( $url, PHP_URL_HOST );
74 + return ( $lang = array_search( $host , $this->hosts ) ) ? $lang : '';
75 + }
76 +
77 + /**
63 78 * Returns the home url
64 79 * links_model interface
65 80 *
66 81 * @since 1.3.1
@@ -67,9 +82,9 @@
67 82 *
68 83 * @param object $lang PLL_Language object
69 84 * @return string
70 85 */
71 - public function home_url( $lang ) {
86 + function home_url( $lang ) {
72 87 return trailingslashit( empty( $this->options['domains'][ $lang->slug ] ) ? $this->home : $this->options['domains'][ $lang->slug ] );
73 88 }
74 89
75 90 /**
@@ -81,12 +96,9 @@
81 96 */
82 97 public function get_hosts() {
83 98 $hosts = array();
84 99 foreach ( $this->options['domains'] as $lang => $domain ) {
85 - $host = wp_parse_url( $domain, PHP_URL_HOST );
86 - // The use of the constant is mandatory in PHP 7.2 and PHP 7.3 to avoid a deprecated notice.
87 - $hosts[ $lang ] = defined( 'INTL_IDNA_VARIANT_UTS46' ) ? idn_to_ascii( $host, 0, INTL_IDNA_VARIANT_UTS46 ) : idn_to_ascii( $host );
100 + $hosts[ $lang ] = parse_url( $domain, PHP_URL_HOST );
88 101 }
89 -
90 102 return $hosts;
91 103 }
92 104 }