PluginProbe
Polylang / 3.7.7
Polylang v3.7.7
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-subdomain.php +25 -23 3.03.7.7 View file →
@@ -3,11 +3,10 @@
3 3 * @package Polylang
4 4 */
5 5
6 6 /**
7 - * Links model for use when the language code is added in url as a subdomain
8 - * for example en.mysite.com/something
9 - * implements the "links_model interface"
7 + * Links model for use when the language code is added in the url as a subdomain
8 + * for example en.mysite.com/something.
10 9 *
11 10 * @since 1.2
12 11 */
13 12 class PLL_Links_Subdomain extends PLL_Links_Abstract_Domain {
@@ -32,41 +31,43 @@
32 31 }
33 32
34 33 /**
35 34 * Adds the language code in a url.
36 - * links_model interface.
37 35 *
38 36 * @since 1.2
37 + * @since 3.4 Accepts now a language slug.
39 38 *
40 - * @param string $url The url to modify.
41 - * @param PLL_Language $lang The language object.
42 - * @return string Modified url.
39 + * @param string $url The url to modify.
40 + * @param PLL_Language|string|false $language Language object or slug.
41 + * @return string The modified url.
43 42 */
44 - public function add_language_to_link( $url, $lang ) {
45 - if ( ! empty( $lang ) && false === strpos( $url, '://' . $lang->slug . '.' ) ) {
46 - $url = $this->options['default_lang'] == $lang->slug && $this->options['hide_default'] ? $url : str_replace( $this->www, '://' . $lang->slug . '.', $url );
43 + public function add_language_to_link( $url, $language ) {
44 + if ( $language instanceof PLL_Language ) {
45 + $language = $language->slug;
47 46 }
47 +
48 + if ( ! empty( $language ) && false === strpos( $url, '://' . $language . '.' ) ) {
49 + $url = $this->options['default_lang'] === $language && $this->options['hide_default'] ? $url : str_replace( $this->www, '://' . $language . '.', $url );
50 + }
48 51 return $url;
49 52 }
50 53
51 54 /**
52 - * Returns the url without language code
53 - * links_model interface
55 + * Returns the url without the language code.
54 56 *
55 57 * @since 1.2
56 58 *
57 - * @param string $url url to modify
58 - * @return string modified url
59 + * @param string $url The url to modify.
60 + * @return string The modified url.
59 61 */
60 62 public function remove_language_from_link( $url ) {
61 - $languages = array();
63 + $languages = $this->model->get_languages_list(
64 + array(
65 + 'hide_default' => $this->options['hide_default'],
66 + 'fields' => 'slug',
67 + )
68 + );
62 69
63 - foreach ( $this->model->get_languages_list() as $language ) {
64 - if ( ! $this->options['hide_default'] || $this->options['default_lang'] != $language->slug ) {
65 - $languages[] = $language->slug;
66 - }
67 - }
68 -
69 70 if ( ! empty( $languages ) ) {
70 71 $url = preg_replace( '#://(' . implode( '|', $languages ) . ')\.#', $this->www, $url );
71 72 }
72 73
@@ -73,9 +74,9 @@
73 74 return $url;
74 75 }
75 76
76 77 /**
77 - * Get hosts managed on the website.
78 + * Get the hosts managed on the website.
78 79 *
79 80 * @since 1.5
80 81 *
81 82 * @return string[] The list of hosts.
@@ -82,9 +83,10 @@
82 83 */
83 84 public function get_hosts() {
84 85 $hosts = array();
85 86 foreach ( $this->model->get_languages_list() as $lang ) {
86 - $hosts[ $lang->slug ] = wp_parse_url( $this->home_url( $lang ), PHP_URL_HOST );
87 + $host = wp_parse_url( $this->home_url( $lang ), PHP_URL_HOST );
88 + $hosts[ $lang->slug ] = $host ?: '';
87 89 }
88 90 return $hosts;
89 91 }
90 92 }