PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
3.8.11 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 All 235 releases
← All changes | include/filters-links.php +14 -39 2.9.1 → 2.0.12 View file →
@@ -1,19 +1,16 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * Manages links filters needed on both frontend and admin
4 + * manages links filters needed on both frontend and admin
8 5 *
9 6 * @since 1.8
10 7 */
11 8 class PLL_Filters_Links {
12 - public $links, $links_model, $model, $options, $curlang;
9 + public $links, $links_model, $model, $options;
13 10
14 11 /**
15 - * Constructor
12 + * constructor
16 13 *
17 14 * @since 1.8
18 15 *
19 16 * @param object $polylang
@@ -22,11 +19,10 @@
22 19 $this->links = &$polylang->links;
23 20 $this->links_model = &$polylang->links_model;
24 21 $this->model = &$polylang->model;
25 22 $this->options = &$polylang->options;
26 - $this->curlang = &$polylang->curlang;
27 23
28 - // Low priority on links filters to come after any other modifications.
24 + // low priority on links filters to come after any other modifications
29 25 if ( $this->options['force_lang'] ) {
30 26 add_filter( 'post_link', array( $this, 'post_type_link' ), 20, 2 );
31 27 add_filter( '_get_page_link', array( $this, '_get_page_link' ), 20, 2 );
32 28 }
@@ -37,19 +33,15 @@
37 33 if ( $this->options['force_lang'] > 0 ) {
38 34 add_filter( 'attachment_link', array( $this, 'attachment_link' ), 20, 2 );
39 35 }
40 36
41 - // Keeps the preview post link on default domain when using multiple domains and SSO is not available.
42 - if ( 3 === $this->options['force_lang'] && ! class_exists( 'PLL_Xdata_Domain' ) ) {
37 + if ( 3 === $this->options['force_lang'] ) {
43 38 add_filter( 'preview_post_link', array( $this, 'preview_post_link' ), 20 );
44 39 }
45 -
46 - // Rewrites post types archives links to filter them by language.
47 - add_filter( 'post_type_archive_link', array( $this, 'post_type_archive_link' ), 20, 2 );
48 40 }
49 41
50 42 /**
51 - * Modifies page links
43 + * modifies page links
52 44 *
53 45 * @since 1.7
54 46 *
55 47 * @param string $link post link
@@ -57,13 +49,13 @@
57 49 * @return string modified post link
58 50 */
59 51 public function _get_page_link( $link, $post_id ) {
60 52 // /!\ WP does not use pretty permalinks for preview
61 - return false !== strpos( $link, 'preview=true' ) && false !== strpos( $link, 'page_id=' ) ? $link : $this->links_model->switch_language_in_link( $link, $this->model->post->get_language( $post_id ) );
53 + return false !== strpos( $link, 'preview=true' ) && false !== strpos( $link, 'page_id=' ) ? $link : $this->links_model->add_language_to_link( $link, $this->model->post->get_language( $post_id ) );
62 54 }
63 55
64 56 /**
65 - * Modifies attachment links
57 + * modifies attachment links
66 58 *
67 59 * @since 1.6.2
68 60 *
69 61 * @param string $link attachment link
@@ -70,13 +62,13 @@
70 62 * @param int $post_id attachment link
71 63 * @return string modified attachment link
72 64 */
73 65 public function attachment_link( $link, $post_id ) {
74 - return wp_get_post_parent_id( $post_id ) ? $link : $this->links_model->switch_language_in_link( $link, $this->model->post->get_language( $post_id ) );
66 + return wp_get_post_parent_id( $post_id ) ? $link : $this->links_model->add_language_to_link( $link, $this->model->post->get_language( $post_id ) );
75 67 }
76 68
77 69 /**
78 - * Modifies custom posts links
70 + * modifies custom posts links
79 71 *
80 72 * @since 1.6
81 73 *
82 74 * @param string $link post link
@@ -86,9 +78,9 @@
86 78 public function post_type_link( $link, $post ) {
87 79 // /!\ WP does not use pretty permalinks for preview
88 80 if ( ( false === strpos( $link, 'preview=true' ) || false === strpos( $link, 'p=' ) ) && $this->model->is_translated_post_type( $post->post_type ) ) {
89 81 $lang = $this->model->post->get_language( $post->ID );
90 - $link = $this->options['force_lang'] ? $this->links_model->switch_language_in_link( $link, $lang ) : $link;
82 + $link = $this->options['force_lang'] ? $this->links_model->add_language_to_link( $link, $lang ) : $link;
91 83
92 84 /**
93 85 * Filter a post or custom post type link
94 86 *
@@ -104,9 +96,9 @@
104 96 return $link;
105 97 }
106 98
107 99 /**
108 - * Modifies term link
100 + * modifies term link
109 101 *
110 102 * @since 0.7
111 103 *
112 104 * @param string $link term link
@@ -116,9 +108,9 @@
116 108 */
117 109 public function term_link( $link, $term, $tax ) {
118 110 if ( $this->model->is_translated_taxonomy( $tax ) ) {
119 111 $lang = $this->model->term->get_language( $term->term_id );
120 - $link = $this->options['force_lang'] ? $this->links_model->switch_language_in_link( $link, $lang ) : $link;
112 + $link = $this->options['force_lang'] ? $this->links_model->add_language_to_link( $link, $lang ) : $link;
121 113
122 114 /**
123 115 * Filter a term link
124 116 *
@@ -139,9 +131,9 @@
139 131 return $link;
140 132 }
141 133
142 134 /**
143 - * Keeps the preview post link on default domain when using multiple domains
135 + * FIXME: keeps the preview post link on default domain when using multiple domains
144 136 *
145 137 * @since 1.6.1
146 138 *
147 139 * @param string $url
@@ -148,24 +140,7 @@
148 140 * @return string modified url
149 141 */
150 142 public function preview_post_link( $url ) {
151 143 return $this->links_model->remove_language_from_link( $url );
152 - }
153 -
154 - /**
155 - * Modifies the post type archive links to add the language parameter
156 - * only if the post type is translated
157 - *
158 - * The filter was originally only on frontend but is needed on admin too for
159 - * compatibility with the archive link of the ACF link field since ACF 5.4.0
160 - *
161 - * @since 1.7.6
162 - *
163 - * @param string $link
164 - * @param string $post_type
165 - * @return string modified link
166 - */
167 - public function post_type_archive_link( $link, $post_type ) {
168 - return $this->model->is_translated_post_type( $post_type ) && 'post' !== $post_type ? $this->links_model->switch_language_in_link( $link, $this->curlang ) : $link;
169 144 }
170 145 }
171 146