PluginProbe
Polylang / 2.0.3
Polylang v2.0.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 +9 -197 2.72.0.3 View file →
@@ -27,30 +27,10 @@
27 27
28 28 // Filters the get_pages function according to the current language
29 29 add_filter( 'get_pages', array( $this, 'get_pages' ), 10, 2 );
30 30
31 - // Rewrites next and previous post links to filter them by language
32 - add_filter( 'get_previous_post_join', array( $this, 'posts_join' ), 10, 5 );
33 - add_filter( 'get_next_post_join', array( $this, 'posts_join' ), 10, 5 );
34 - add_filter( 'get_previous_post_where', array( $this, 'posts_where' ), 10, 5 );
35 - add_filter( 'get_next_post_where', array( $this, 'posts_where' ), 10, 5 );
36 -
37 31 // Converts the locale to a valid W3C locale
38 32 add_filter( 'language_attributes', array( $this, 'language_attributes' ) );
39 -
40 - // Prevents deleting all the translations of the default category
41 - add_filter( 'map_meta_cap', array( $this, 'fix_delete_default_category' ), 10, 4 );
42 -
43 - // Translate the site title in emails sent to users
44 - add_filter( 'password_change_email', array( $this, 'translate_user_email' ) );
45 - add_filter( 'email_change_email', array( $this, 'translate_user_email' ) );
46 -
47 - // Translates the privacy policy page
48 - add_filter( 'option_wp_page_for_privacy_policy', array( $this, 'translate_page_for_privacy_policy' ), 20 ); // Since WP 4.9.6
49 - add_filter( 'map_meta_cap', array( $this, 'fix_privacy_policy_page_editing' ), 10, 4 );
50 -
51 - // Personal data exporter
52 - add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_personal_data_exporter' ), 0 ); // Since WP 4.9.6
53 33 }
54 34
55 35 /**
56 36 * Get the language to filter a comments query
@@ -145,25 +125,22 @@
145 125 if ( ! empty( $args['number'] ) && ! $once ) {
146 126 $once = true; // avoid infinite loop
147 127
148 128 $r = array(
149 - 'lang' => 0, // So this query is not filtered
129 + 'lang' => 0, // So this query is not filtered
150 130 'numberposts' => -1,
151 131 'nopaging' => true,
152 132 'post_type' => $args['post_type'],
153 133 'fields' => 'ids',
154 - 'tax_query' => array(
155 - array(
156 - 'taxonomy' => 'language',
157 - 'field' => 'term_taxonomy_id', // Since WP 3.5
158 - 'terms' => $language->term_taxonomy_id,
159 - 'operator' => 'NOT IN',
160 - ),
161 - ),
134 + 'tax_query' => array( array(
135 + 'taxonomy' => 'language',
136 + 'field' => 'term_taxonomy_id', // Since WP 3.5
137 + 'terms' => $language->term_taxonomy_id,
138 + 'operator' => 'NOT IN',
139 + ) ),
162 140 );
163 141
164 - // Take care that 'exclude' argument accepts integer or strings too
165 - $args['exclude'] = array_merge( wp_parse_id_list( $args['exclude'] ), get_posts( $r ) );
142 + $args['exclude'] = array_merge( $args['exclude'], get_posts( $r ) );
166 143 $pages = get_pages( $args );
167 144 }
168 145
169 146 $ids = wp_list_pluck( $pages, 'ID' );
@@ -176,10 +153,8 @@
176 153 if ( ! in_array( $page->ID, $ids ) ) {
177 154 unset( $pages[ $key ] );
178 155 }
179 156 }
180 -
181 - $pages = array_values( $pages ); // In case 3rd parties suppose the existence of $pages[0]
182 157 }
183 158
184 159 // Not done by WP but extremely useful for performance when manipulating taxonomies
185 160 update_object_term_cache( $ids, $args['post_type'] );
@@ -188,40 +163,8 @@
188 163 return $pages;
189 164 }
190 165
191 166 /**
192 - * Modifies the sql request for get_adjacent_post to filter by the current language
193 - *
194 - * @since 0.1
195 - *
196 - * @param string $sql The JOIN clause in the SQL.
197 - * @param bool $in_same_term Whether post should be in a same taxonomy term.
198 - * @param array $excluded_terms Array of excluded term IDs.
199 - * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true.
200 - * @param WP_Post $post WP_Post object.
201 - * @return string modified JOIN clause
202 - */
203 - public function posts_join( $sql, $in_same_term, $excluded_terms, $taxonomy = '', $post = null ) {
204 - return $this->model->is_translated_post_type( $post->post_type ) && ! empty( $this->curlang ) ? $sql . $this->model->post->join_clause( 'p' ) : $sql;
205 - }
206 -
207 - /**
208 - * Modifies the sql request for wp_get_archives and get_adjacent_post to filter by the current language
209 - *
210 - * @since 0.1
211 - *
212 - * @param string $sql The WHERE clause in the SQL.
213 - * @param bool $in_same_term Whether post should be in a same taxonomy term.
214 - * @param array $excluded_terms Array of excluded term IDs.
215 - * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true.
216 - * @param WP_Post $post WP_Post object.
217 - * @return string modified WHERE clause
218 - */
219 - public function posts_where( $sql, $in_same_term, $excluded_terms, $taxonomy = '', $post = null ) {
220 - return $this->model->is_translated_post_type( $post->post_type ) && ! empty( $this->curlang ) ? $sql . $this->model->post->where_clause( $this->curlang ) : $sql;
221 - }
222 -
223 - /**
224 167 * Converts WordPress locale to valid W3 locale in html language attributes
225 168 *
226 169 * @since 1.8
227 170 *
@@ -228,141 +171,10 @@
228 171 * @param string $output language attributes
229 172 * @return string
230 173 */
231 174 public function language_attributes( $output ) {
232 - if ( $language = $this->model->get_language( is_admin() ? get_user_locale() : get_locale() ) ) {
175 + if ( $language = $this->model->get_language( get_locale() ) ) {
233 176 $output = str_replace( '"' . get_bloginfo( 'language' ) . '"', '"' . $language->get_locale( 'display' ) . '"', $output );
234 177 }
235 178 return $output;
236 - }
237 -
238 - /**
239 - * Prevents deleting all the translations of the default category
240 - *
241 - * @since 2.1
242 - *
243 - * @param array $caps The user's actual capabilities.
244 - * @param string $cap Capability name.
245 - * @param int $user_id The user ID.
246 - * @param array $args Adds the context to the cap. The category id.
247 - * @return array
248 - */
249 - public function fix_delete_default_category( $caps, $cap, $user_id, $args ) {
250 - if ( 'delete_term' === $cap ) {
251 - $term = get_term( reset( $args ) ); // Since WP 4.4, we can get the term to get the taxonomy
252 - if ( $term instanceof WP_Term ) {
253 - $default_cat = get_option( 'default_' . $term->taxonomy );
254 - if ( $default_cat && array_intersect( $args, $this->model->term->get_translations( $default_cat ) ) ) {
255 - $caps[] = 'do_not_allow';
256 - }
257 - }
258 - }
259 -
260 - return $caps;
261 - }
262 -
263 - /**
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()
266 - *
267 - * @since 2.1.3
268 - *
269 - * @param array $email
270 - * @return array
271 - */
272 - public function translate_user_email( $email ) {
273 - $blog_name = wp_specialchars_decode( pll__( get_option( 'blogname' ) ), ENT_QUOTES );
274 - $email['subject'] = sprintf( $email['subject'], $blog_name );
275 - $email['message'] = str_replace( '###SITENAME###', $blog_name, $email['message'] );
276 - return $email;
277 - }
278 -
279 - /**
280 - * Translates the privacy policy page, on both frontend and admin
281 - *
282 - * @since 2.3.6
283 - *
284 - * @param int $id Privacy policy page id
285 - * @return int
286 - */
287 - public function translate_page_for_privacy_policy( $id ) {
288 - return empty( $this->curlang ) ? $id : $this->model->post->get( $id, $this->curlang );
289 - }
290 -
291 - /**
292 - * Prevents edit and delete links for the translations of the privacy policy page for non admin
293 - *
294 - * @since 2.3.7
295 - *
296 - * @param array $caps The user's actual capabilities.
297 - * @param string $cap Capability name.
298 - * @param int $user_id The user ID.
299 - * @param array $args Adds the context to the cap. The category id.
300 - * @return array
301 - */
302 - public function fix_privacy_policy_page_editing( $caps, $cap, $user_id, $args ) {
303 - if ( in_array( $cap, array( 'edit_page', 'edit_post', 'delete_page', 'delete_post' ) ) ) {
304 - $privacy_page = get_option( 'wp_page_for_privacy_policy' );
305 - if ( $privacy_page && array_intersect( $args, $this->model->post->get_translations( $privacy_page ) ) ) {
306 - $caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) );
307 - }
308 - }
309 -
310 - return $caps;
311 - }
312 -
313 - /**
314 - * Register our personal data exporter
315 - *
316 - * @since 2.3.6
317 - *
318 - * @param array $exporters Personal data exporters
319 - * @retun array
320 - */
321 - public function register_personal_data_exporter( $exporters ) {
322 - $exporters[] = array(
323 - 'exporter_friendly_name' => __( 'Translated user descriptions', 'polylang' ),
324 - 'callback' => array( $this, 'user_data_exporter' ),
325 - );
326 - return $exporters;
327 - }
328 -
329 - /**
330 - * Export translated user description as WP exports only the description in the default language
331 - *
332 - * @since 2.3.6
333 - *
334 - * @param string $email_address User email address
335 - * @return array Personal data
336 - */
337 - public function user_data_exporter( $email_address ) {
338 - $email_address = trim( $email_address );
339 - $data_to_export = array();
340 - $user_data_to_export = array();
341 -
342 - if ( $user = get_user_by( 'email', $email_address ) ) {
343 - foreach ( $this->model->get_languages_list() as $lang ) {
344 - if ( $lang->slug !== $this->options['default_lang'] && $value = get_user_meta( $user->ID, 'description_' . $lang->slug, true ) ) {
345 - $user_data_to_export[] = array(
346 - /* translators: %s is a language native name */
347 - 'name' => sprintf( __( 'User description - %s', 'polylang' ), $lang->name ),
348 - 'value' => $value,
349 - );
350 - }
351 - }
352 -
353 - if ( ! empty( $user_data_to_export ) ) {
354 - $data_to_export[] = array(
355 - 'group_id' => 'user',
356 - 'group_label' => __( 'User', 'polylang' ),
357 - 'item_id' => "user-{$user->ID}",
358 - 'data' => $user_data_to_export,
359 - );
360 - }
361 - }
362 -
363 - return array(
364 - 'data' => $data_to_export,
365 - 'done' => true,
366 - );
367 179 }
368 180 }