PluginProbe
Polylang / 2.3
Polylang v2.3
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 +6 -120 2.92.3 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 *
@@ -23,13 +20,8 @@
23 20 $this->model = &$polylang->model;
24 21 $this->options = &$polylang->options;
25 22 $this->curlang = &$polylang->curlang;
26 23
27 - // Deletes our cache for sticky posts when the list is updated.
28 - add_action( 'update_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) );
29 - add_action( 'add_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) );
30 - add_action( 'delete_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) );
31 -
32 24 // Filters the comments according to the current language
33 25 add_action( 'parse_comment_query', array( $this, 'parse_comment_query' ) );
34 26 add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 10, 2 );
35 27
@@ -50,27 +42,11 @@
50 42
51 43 // Translate the site title in emails sent to users
52 44 add_filter( 'password_change_email', array( $this, 'translate_user_email' ) );
53 45 add_filter( 'email_change_email', array( $this, 'translate_user_email' ) );
54 -
55 - // Translates the privacy policy page
56 - add_filter( 'option_wp_page_for_privacy_policy', array( $this, 'translate_page_for_privacy_policy' ), 20 ); // Since WP 4.9.6
57 - add_filter( 'map_meta_cap', array( $this, 'fix_privacy_policy_page_editing' ), 10, 4 );
58 -
59 - // Personal data exporter
60 - add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_personal_data_exporter' ), 0 ); // Since WP 4.9.6
61 46 }
62 47
63 48 /**
64 - * Deletes the cache for multilingual sticky posts.
65 - *
66 - * @since 2.8.4
67 - */
68 - public function delete_sticky_posts_cache() {
69 - wp_cache_delete( 'sticky_posts', 'options' );
70 - }
71 -
72 - /**
73 49 * Get the language to filter a comments query
74 50 *
75 51 * @since 2.0
76 52 *
@@ -162,9 +138,9 @@
162 138 if ( ! empty( $args['number'] ) && ! $once ) {
163 139 $once = true; // avoid infinite loop
164 140
165 141 $r = array(
166 - 'lang' => 0, // So this query is not filtered
142 + 'lang' => 0, // So this query is not filtered
167 143 'numberposts' => -1,
168 144 'nopaging' => true,
169 145 'post_type' => $args['post_type'],
170 146 'fields' => 'ids',
@@ -177,10 +153,9 @@
177 153 ),
178 154 ),
179 155 );
180 156
181 - // Take care that 'exclude' argument accepts integer or strings too
182 - $args['exclude'] = array_merge( wp_parse_id_list( $args['exclude'] ), get_posts( $r ) );
157 + $args['exclude'] = array_merge( $args['exclude'], get_posts( $r ) );
183 158 $pages = get_pages( $args );
184 159 }
185 160
186 161 $ids = wp_list_pluck( $pages, 'ID' );
@@ -245,14 +220,15 @@
245 220 * @param string $output language attributes
246 221 * @return string
247 222 */
248 223 public function language_attributes( $output ) {
249 - if ( $language = $this->model->get_language( is_admin() ? get_user_locale() : get_locale() ) ) {
224 + if ( $language = $this->model->get_language( get_locale() ) ) {
250 225 $output = str_replace( '"' . get_bloginfo( 'language' ) . '"', '"' . $language->get_locale( 'display' ) . '"', $output );
251 226 }
252 227 return $output;
253 228 }
254 229
230 +
255 231 /**
256 232 * Prevents deleting all the translations of the default category
257 233 *
258 234 * @since 2.1
@@ -285,101 +261,11 @@
285 261 *
286 262 * @param array $email
287 263 * @return array
288 264 */
289 - public function translate_user_email( $email ) {
290 - $blog_name = wp_specialchars_decode( pll__( get_option( 'blogname' ) ), ENT_QUOTES );
265 + function translate_user_email( $email ) {
266 + $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
291 267 $email['subject'] = sprintf( $email['subject'], $blog_name );
292 268 $email['message'] = str_replace( '###SITENAME###', $blog_name, $email['message'] );
293 269 return $email;
294 - }
295 -
296 - /**
297 - * Translates the privacy policy page, on both frontend and admin
298 - *
299 - * @since 2.3.6
300 - *
301 - * @param int $id Privacy policy page id
302 - * @return int
303 - */
304 - public function translate_page_for_privacy_policy( $id ) {
305 - return empty( $this->curlang ) ? $id : $this->model->post->get( $id, $this->curlang );
306 - }
307 -
308 - /**
309 - * Prevents edit and delete links for the translations of the privacy policy page for non admin
310 - *
311 - * @since 2.3.7
312 - *
313 - * @param array $caps The user's actual capabilities.
314 - * @param string $cap Capability name.
315 - * @param int $user_id The user ID.
316 - * @param array $args Adds the context to the cap. The category id.
317 - * @return array
318 - */
319 - public function fix_privacy_policy_page_editing( $caps, $cap, $user_id, $args ) {
320 - if ( in_array( $cap, array( 'edit_page', 'edit_post', 'delete_page', 'delete_post' ) ) ) {
321 - $privacy_page = get_option( 'wp_page_for_privacy_policy' );
322 - if ( $privacy_page && array_intersect( $args, $this->model->post->get_translations( $privacy_page ) ) ) {
323 - $caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) );
324 - }
325 - }
326 -
327 - return $caps;
328 - }
329 -
330 - /**
331 - * Register our personal data exporter
332 - *
333 - * @since 2.3.6
334 - *
335 - * @param array $exporters Personal data exporters
336 - * @retun array
337 - */
338 - public function register_personal_data_exporter( $exporters ) {
339 - $exporters[] = array(
340 - 'exporter_friendly_name' => __( 'Translated user descriptions', 'polylang' ),
341 - 'callback' => array( $this, 'user_data_exporter' ),
342 - );
343 - return $exporters;
344 - }
345 -
346 - /**
347 - * Export translated user description as WP exports only the description in the default language
348 - *
349 - * @since 2.3.6
350 - *
351 - * @param string $email_address User email address
352 - * @return array Personal data
353 - */
354 - public function user_data_exporter( $email_address ) {
355 - $email_address = trim( $email_address );
356 - $data_to_export = array();
357 - $user_data_to_export = array();
358 -
359 - if ( $user = get_user_by( 'email', $email_address ) ) {
360 - foreach ( $this->model->get_languages_list() as $lang ) {
361 - if ( $lang->slug !== $this->options['default_lang'] && $value = get_user_meta( $user->ID, 'description_' . $lang->slug, true ) ) {
362 - $user_data_to_export[] = array(
363 - /* translators: %s is a language native name */
364 - 'name' => sprintf( __( 'User description - %s', 'polylang' ), $lang->name ),
365 - 'value' => $value,
366 - );
367 - }
368 - }
369 -
370 - if ( ! empty( $user_data_to_export ) ) {
371 - $data_to_export[] = array(
372 - 'group_id' => 'user',
373 - 'group_label' => __( 'User', 'polylang' ),
374 - 'item_id' => "user-{$user->ID}",
375 - 'data' => $user_data_to_export,
376 - );
377 - }
378 - }
379 -
380 - return array(
381 - 'data' => $data_to_export,
382 - 'done' => true,
383 - );
384 270 }
385 271 }