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