PluginProbe
Polylang / 2.5.2
Polylang v2.5.2
3.8.10 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 All 234 releases
← All changes | frontend/frontend-links.php +17 -30 3.0 → 2.5.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages links filters and url of translations on frontend
8 5 *
@@ -8,23 +5,12 @@
8 5 *
9 6 * @since 1.2
10 7 */
11 8 class PLL_Frontend_Links extends PLL_Links {
12 - /**
13 - * Current language.
14 - *
15 - * @var PLL_Language
16 - */
17 9 public $curlang;
10 + public $cache; // Our internal non persistent cache object
18 11
19 12 /**
20 - * Internal non persistent cache object.
21 - *
22 - * @var PLL_Cache
23 - */
24 - public $cache;
25 -
26 - /**
27 13 * Constructor
28 14 *
29 15 * @since 1.2
30 16 *
@@ -38,13 +24,13 @@
38 24
39 25 }
40 26
41 27 /**
42 - * Returns the url of the translation (if it exists) of the current page.
28 + * Returns the url of the translation ( if exists ) of the current page
43 29 *
44 30 * @since 0.1
45 31 *
46 - * @param PLL_Language $language Language object.
32 + * @param object $language
47 33 * @return string
48 34 */
49 35 public function get_translation_url( $language ) {
50 36 global $wp_query;
@@ -57,27 +43,28 @@
57 43 // See https://wordpress.org/support/topic/patch-for-fixing-a-notice
58 44 $queried_object_id = $wp_query->get_queried_object_id();
59 45
60 46 /**
61 - * Filters the translation url before Polylang attempts to find one.
62 - * Internally used by Polylang for the static front page and posts page.
47 + * Filter the translation url before Polylang attempts to find one
48 + * Internally used by Polylang for the static front page and posts page
63 49 *
64 50 * @since 1.8
65 51 *
66 - * @param string $url Empty or the url of the translation of teh current page.
67 - * @param PLL_Language $language Language of the translation.
68 - * @param int $queried_object_id Queried object id.
52 + * @param string $url Empty or the url of the translation of teh current page
53 + * @param object $language Language of the translation
54 + * @param int $queried_object_id Queried object id
69 55 */
70 56 if ( ! $url = apply_filters( 'pll_pre_translation_url', '', $language, $queried_object_id ) ) {
71 57 $qv = $wp_query->query_vars;
58 + $hide = $this->options['default_lang'] == $language->slug && $this->options['hide_default'];
72 59
73 60 // Post and attachment
74 - if ( is_single() && ( $this->options['media_support'] || ! is_attachment() ) && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->model->post->current_user_can_read( $id ) ) {
61 + if ( is_single() && ( $this->options['media_support'] || ! is_attachment() ) && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->current_user_can_read( $id ) ) {
75 62 $url = get_permalink( $id );
76 63 }
77 64
78 65 // Page
79 - elseif ( is_page() && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->model->post->current_user_can_read( $id ) ) {
66 + elseif ( is_page() && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->current_user_can_read( $id ) ) {
80 67 $url = get_page_link( $id );
81 68 }
82 69
83 70 elseif ( is_search() ) {
@@ -108,9 +95,9 @@
108 95 elseif ( ( is_category() || is_tag() || is_tax() ) && ( $term = get_queried_object() ) && $this->model->is_translated_taxonomy( $term->taxonomy ) ) {
109 96 $lang = $this->model->term->get_language( $term->term_id );
110 97
111 98 if ( ! $lang || $language->slug == $lang->slug ) {
112 - $url = get_term_link( $term, $term->taxonomy ); // Self link
99 + $url = wpcom_vip_get_term_link( $term, $term->taxonomy ); // Self link
113 100 }
114 101
115 102 elseif ( $tr_id = $this->model->term->get_translation( $term->term_id, $language ) ) {
116 103 if ( $tr_term = get_term( $tr_id, $term->taxonomy ) ) {
@@ -127,9 +114,9 @@
127 114 * @param string $lang The language code of the translation
128 115 * @param array $args Arguments used to evaluated the number of posts in the archive
129 116 */
130 117 if ( ! apply_filters( 'pll_hide_archive_translation_url', ! $count, $language->slug, array( 'taxonomy' => $term->taxonomy ) ) ) {
131 - $url = get_term_link( $tr_term, $term->taxonomy );
118 + $url = wpcom_vip_get_term_link( $tr_term, $term->taxonomy );
132 119 }
133 120 }
134 121 }
135 122 }
@@ -193,9 +180,9 @@
193 180 * @param object $language
194 181 * @return string
195 182 */
196 183 public function get_archive_url( $language ) {
197 - $url = pll_get_requested_url();
184 + $url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
198 185 $url = $this->links_model->switch_language_in_link( $url, $language );
199 186 $url = $this->links_model->remove_paged_from_link( $url );
200 187
201 188 /**
@@ -209,14 +196,14 @@
209 196 return apply_filters( 'pll_get_archive_url', $url, $language );
210 197 }
211 198
212 199 /**
213 - * Returns the home url in the right language.
200 + * Returns the home url in the right language
214 201 *
215 202 * @since 0.1
216 203 *
217 - * @param PLL_Language|string $language Optional, defaults to current language.
218 - * @param bool $is_search Optional, whether we need the home url for a search form, defaults to false.
204 + * @param object $language Optional, defaults to current language
205 + * @param bool $is_search Optional, whether we need the home url for a search form, defaults to false
219 206 */
220 207 public function get_home_url( $language = '', $is_search = false ) {
221 208 if ( empty( $language ) ) {
222 209 $language = $this->curlang;