PluginProbe
Polylang / 2.8
Polylang v2.8
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/filters.php +35 -77 3.0.22.8 View file →
@@ -8,35 +8,11 @@
8 8 *
9 9 * @since 1.4
10 10 */
11 11 class PLL_Filters {
12 - /**
13 - * Stores the plugin options.
14 - *
15 - * @var array
16 - */
17 - public $options;
12 + public $links_model, $model, $options, $curlang;
18 13
19 14 /**
20 - * @var PLL_Model
21 - */
22 - public $model;
23 -
24 - /**
25 - * Instance of a child class of PLL_Links_Model.
26 - *
27 - * @var PLL_Links_Model
28 - */
29 - public $links_model;
30 -
31 - /**
32 - * Current language.
33 - *
34 - * @var PLL_Language
35 - */
36 - public $curlang;
37 -
38 - /**
39 15 * Constructor: setups filters
40 16 *
41 17 * @since 1.4
42 18 *
@@ -47,13 +23,8 @@
47 23 $this->model = &$polylang->model;
48 24 $this->options = &$polylang->options;
49 25 $this->curlang = &$polylang->curlang;
50 26
51 - // Deletes our cache for sticky posts when the list is updated.
52 - add_action( 'update_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) );
53 - add_action( 'add_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) );
54 - add_action( 'delete_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) );
55 -
56 27 // Filters the comments according to the current language
57 28 add_action( 'parse_comment_query', array( $this, 'parse_comment_query' ) );
58 29 add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 10, 2 );
59 30
@@ -84,28 +55,17 @@
84 55 add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_personal_data_exporter' ), 0 ); // Since WP 4.9.6
85 56 }
86 57
87 58 /**
88 - * Deletes the cache for multilingual sticky posts.
59 + * Get the language to filter a comments query
89 60 *
90 - * @since 2.8.4
91 - *
92 - * @return void
93 - */
94 - public function delete_sticky_posts_cache() {
95 - wp_cache_delete( 'sticky_posts', 'options' );
96 - }
97 -
98 - /**
99 - * Get the language to filter a comments query.
100 - *
101 61 * @since 2.0
102 62 *
103 - * @param WP_Comment_Query $query WP_Comment_Query object.
104 - * @return PLL_Language|false The language to use in the filter, false otherwise.
63 + * @param object $query
64 + * @return object|bool the language(s) to use in the filter, false otherwise
105 65 */
106 66 protected function get_comments_queried_language( $query ) {
107 - // Don't filter comments if comment ids or post ids are specified.
67 + // Don't filter comments if comment ids or post ids are specified
108 68 $plucked = wp_array_slice_assoc( $query->query_vars, array( 'comment__in', 'parent', 'post_id', 'post__in', 'post_parent' ) );
109 69 $fields = array_filter( $plucked );
110 70 if ( ! empty( $fields ) ) {
111 71 return false;
@@ -110,9 +70,9 @@
110 70 if ( ! empty( $fields ) ) {
111 71 return false;
112 72 }
113 73
114 - // Don't filter comments if a non translated post type is specified.
74 + // Don't filter comments if a non translated post type is specified
115 75 if ( ! empty( $query->query_vars['post_type'] ) && ! $this->model->is_translated_post_type( $query->query_vars['post_type'] ) ) {
116 76 return false;
117 77 }
118 78
@@ -119,34 +79,32 @@
119 79 return empty( $query->query_vars['lang'] ) ? $this->curlang : $this->model->get_language( $query->query_vars['lang'] );
120 80 }
121 81
122 82 /**
123 - * Adds a language dependent cache domain when querying comments.
124 - * Useful as the 'lang' parameter is not included in cache key by WordPress.
125 - * Needed since WP 4.6 as comments have been added to persistent cache. See #36906, #37419.
83 + * Adds language dependent cache domain when querying comments
84 + * Useful as the 'lang' parameter is not included in cache key by WordPress
85 + * Needed since WP 4.6 as comments have been added to persistent cache. See #36906, #37419
126 86 *
127 87 * @since 2.0
128 88 *
129 - * @param WP_Comment_Query $query WP_Comment_Query object.
130 - * @return void
89 + * @param object $query
131 90 */
132 91 public function parse_comment_query( $query ) {
133 - $lang = $this->get_comments_queried_language( $query );
134 - if ( $lang ) {
135 - $key = '_' . $lang->slug;
92 + if ( $lang = $this->get_comments_queried_language( $query ) ) {
93 + $key = '_' . ( is_array( $lang ) ? implode( ',', $lang ) : $this->model->get_language( $lang )->slug );
136 94 $query->query_vars['cache_domain'] = empty( $query->query_vars['cache_domain'] ) ? 'pll' . $key : $query->query_vars['cache_domain'] . $key;
137 95 }
138 96 }
139 97
140 98 /**
141 - * Filters the comments according to the current language.
142 - * Used by the recent comments widget and admin language filter.
99 + * Filters the comments according to the current language
100 + * Used by the recent comments widget and admin language filter
143 101 *
144 102 * @since 0.2
145 103 *
146 - * @param string[] $clauses SQL clauses.
147 - * @param WP_Comment_Query $query WP_Comment_Query object.
148 - * @return string[] Modified $clauses.
104 + * @param array $clauses sql clauses
105 + * @param object $query WP_Comment_Query object
106 + * @return array modified $clauses
149 107 */
150 108 public function comments_clauses( $clauses, $query ) {
151 109 global $wpdb;
152 110
@@ -152,9 +110,9 @@
152 110
153 111 $lang = $this->get_comments_queried_language( $query );
154 112
155 113 if ( ! empty( $lang ) ) {
156 - // If this clause is not already added by WP.
114 + // If this clause is not already added by WP
157 115 if ( ! strpos( $clauses['join'], '.ID' ) ) {
158 116 $clauses['join'] .= " JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
159 117 }
160 118
@@ -164,15 +122,15 @@
164 122 return $clauses;
165 123 }
166 124
167 125 /**
168 - * Filters get_pages() per language.
126 + * Filters get_pages per language
169 127 *
170 128 * @since 1.4
171 129 *
172 - * @param WP_Post[] $pages An array of pages already queried.
173 - * @param array $args Array of get_pages() arguments.
174 - * @return WP_Post[] Modified list of pages.
130 + * @param array $pages an array of pages already queried
131 + * @param array $args get_pages arguments
132 + * @return array modified list of pages
175 133 */
176 134 public function get_pages( $pages, $args ) {
177 135 if ( isset( $args['lang'] ) && empty( $args['lang'] ) ) {
178 136 return $pages;
@@ -233,36 +191,36 @@
233 191 return $pages;
234 192 }
235 193
236 194 /**
237 - * Modifies the sql request for get_adjacent_post to filter by the current language.
195 + * Modifies the sql request for get_adjacent_post to filter by the current language
238 196 *
239 197 * @since 0.1
240 198 *
241 199 * @param string $sql The JOIN clause in the SQL.
242 200 * @param bool $in_same_term Whether post should be in a same taxonomy term.
243 - * @param int[] $excluded_terms Array of excluded term IDs.
201 + * @param array $excluded_terms Array of excluded term IDs.
244 202 * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true.
245 203 * @param WP_Post $post WP_Post object.
246 - * @return string Modified JOIN clause.
204 + * @return string modified JOIN clause
247 205 */
248 - public function posts_join( $sql, $in_same_term, $excluded_terms, $taxonomy, $post ) {
206 + public function posts_join( $sql, $in_same_term, $excluded_terms, $taxonomy = '', $post = null ) {
249 207 return $this->model->is_translated_post_type( $post->post_type ) && ! empty( $this->curlang ) ? $sql . $this->model->post->join_clause( 'p' ) : $sql;
250 208 }
251 209
252 210 /**
253 - * Modifies the sql request for wp_get_archives and get_adjacent_post to filter by the current language.
211 + * Modifies the sql request for wp_get_archives and get_adjacent_post to filter by the current language
254 212 *
255 213 * @since 0.1
256 214 *
257 215 * @param string $sql The WHERE clause in the SQL.
258 216 * @param bool $in_same_term Whether post should be in a same taxonomy term.
259 - * @param int[] $excluded_terms Array of excluded term IDs.
217 + * @param array $excluded_terms Array of excluded term IDs.
260 218 * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true.
261 219 * @param WP_Post $post WP_Post object.
262 - * @return string Modified WHERE clause.
220 + * @return string modified WHERE clause
263 221 */
264 - public function posts_where( $sql, $in_same_term, $excluded_terms, $taxonomy, $post ) {
222 + public function posts_where( $sql, $in_same_term, $excluded_terms, $taxonomy = '', $post = null ) {
265 223 return $this->model->is_translated_post_type( $post->post_type ) && ! empty( $this->curlang ) ? $sql . $this->model->post->where_clause( $this->curlang ) : $sql;
266 224 }
267 225
268 226 /**
@@ -305,15 +263,15 @@
305 263 return $caps;
306 264 }
307 265
308 266 /**
309 - * Translates the site title in emails sent to the user (change email, reset password).
310 - * It is necessary to filter the email because WP evaluates the site title before calling switch_to_locale().
267 + * Translates the site title in emails sent to the user (change email, reset password)
268 + * It is necessary to filter the email because WP evaluates the site title before calling switch_to_locale()
311 269 *
312 270 * @since 2.1.3
313 271 *
314 - * @param string[] $email Email contents.
315 - * @return string[] Translated email contents.
272 + * @param array $email
273 + * @return array
316 274 */
317 275 public function translate_user_email( $email ) {
318 276 $blog_name = wp_specialchars_decode( pll__( get_option( 'blogname' ) ), ENT_QUOTES );
319 277 $email['subject'] = sprintf( $email['subject'], $blog_name );
@@ -360,9 +318,9 @@
360 318 *
361 319 * @since 2.3.6
362 320 *
363 321 * @param array $exporters Personal data exporters
364 - * @return array
322 + * @retun array
365 323 */
366 324 public function register_personal_data_exporter( $exporters ) {
367 325 $exporters[] = array(
368 326 'exporter_friendly_name' => __( 'Translated user descriptions', 'polylang' ),