| @@ -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 | * |
| @@ -45,15 +42,8 @@ | ||
| 45 | 42 | |
| 46 | 43 | // Translate the site title in emails sent to users |
| 47 | 44 | add_filter( 'password_change_email', array( $this, 'translate_user_email' ) ); |
| 48 | 45 | add_filter( 'email_change_email', array( $this, 'translate_user_email' ) ); |
| 49 | - | |
| 50 | - // Translates the privacy policy page | |
| 51 | - add_filter( 'option_wp_page_for_privacy_policy', array( $this, 'translate_page_for_privacy_policy' ), 20 ); // Since WP 4.9.6 | |
| 52 | - add_filter( 'map_meta_cap', array( $this, 'fix_privacy_policy_page_editing' ), 10, 4 ); | |
| 53 | - | |
| 54 | - // Personal data exporter | |
| 55 | - add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_personal_data_exporter' ), 0 ); // Since WP 4.9.6 | |
| 56 | 46 | } |
| 57 | 47 | |
| 58 | 48 | /** |
| 59 | 49 | * Get the language to filter a comments query |
| @@ -148,9 +138,9 @@ | ||
| 148 | 138 | if ( ! empty( $args['number'] ) && ! $once ) { |
| 149 | 139 | $once = true; // avoid infinite loop |
| 150 | 140 | |
| 151 | 141 | $r = array( |
| 152 | - 'lang' => 0, // So this query is not filtered | |
| 142 | + 'lang' => 0, // So this query is not filtered | |
| 153 | 143 | 'numberposts' => -1, |
| 154 | 144 | 'nopaging' => true, |
| 155 | 145 | 'post_type' => $args['post_type'], |
| 156 | 146 | 'fields' => 'ids', |
| @@ -163,10 +153,9 @@ | ||
| 163 | 153 | ), |
| 164 | 154 | ), |
| 165 | 155 | ); |
| 166 | 156 | |
| 167 | - // Take care that 'exclude' argument accepts integer or strings too | |
| 168 | - $args['exclude'] = array_merge( wp_parse_id_list( $args['exclude'] ), get_posts( $r ) ); | |
| 157 | + $args['exclude'] = array_merge( $args['exclude'], get_posts( $r ) ); | |
| 169 | 158 | $pages = get_pages( $args ); |
| 170 | 159 | } |
| 171 | 160 | |
| 172 | 161 | $ids = wp_list_pluck( $pages, 'ID' ); |
| @@ -231,14 +220,15 @@ | ||
| 231 | 220 | * @param string $output language attributes |
| 232 | 221 | * @return string |
| 233 | 222 | */ |
| 234 | 223 | public function language_attributes( $output ) { |
| 235 | - if ( $language = $this->model->get_language( is_admin() ? get_user_locale() : get_locale() ) ) { | |
| 224 | + if ( $language = $this->model->get_language( get_locale() ) ) { | |
| 236 | 225 | $output = str_replace( '"' . get_bloginfo( 'language' ) . '"', '"' . $language->get_locale( 'display' ) . '"', $output ); |
| 237 | 226 | } |
| 238 | 227 | return $output; |
| 239 | 228 | } |
| 240 | 229 | |
| 230 | + | |
| 241 | 231 | /** |
| 242 | 232 | * Prevents deleting all the translations of the default category |
| 243 | 233 | * |
| 244 | 234 | * @since 2.1 |
| @@ -271,101 +261,11 @@ | ||
| 271 | 261 | * |
| 272 | 262 | * @param array $email |
| 273 | 263 | * @return array |
| 274 | 264 | */ |
| 275 | - public function translate_user_email( $email ) { | |
| 276 | - $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 ); | |
| 277 | 267 | $email['subject'] = sprintf( $email['subject'], $blog_name ); |
| 278 | 268 | $email['message'] = str_replace( '###SITENAME###', $blog_name, $email['message'] ); |
| 279 | 269 | return $email; |
| 280 | - } | |
| 281 | - | |
| 282 | - /** | |
| 283 | - * Translates the privacy policy page, on both frontend and admin | |
| 284 | - * | |
| 285 | - * @since 2.3.6 | |
| 286 | - * | |
| 287 | - * @param int $id Privacy policy page id | |
| 288 | - * @return int | |
| 289 | - */ | |
| 290 | - public function translate_page_for_privacy_policy( $id ) { | |
| 291 | - return empty( $this->curlang ) ? $id : $this->model->post->get( $id, $this->curlang ); | |
| 292 | - } | |
| 293 | - | |
| 294 | - /** | |
| 295 | - * Prevents edit and delete links for the translations of the privacy policy page for non admin | |
| 296 | - * | |
| 297 | - * @since 2.3.7 | |
| 298 | - * | |
| 299 | - * @param array $caps The user's actual capabilities. | |
| 300 | - * @param string $cap Capability name. | |
| 301 | - * @param int $user_id The user ID. | |
| 302 | - * @param array $args Adds the context to the cap. The category id. | |
| 303 | - * @return array | |
| 304 | - */ | |
| 305 | - public function fix_privacy_policy_page_editing( $caps, $cap, $user_id, $args ) { | |
| 306 | - if ( in_array( $cap, array( 'edit_page', 'edit_post', 'delete_page', 'delete_post' ) ) ) { | |
| 307 | - $privacy_page = get_option( 'wp_page_for_privacy_policy' ); | |
| 308 | - if ( $privacy_page && array_intersect( $args, $this->model->post->get_translations( $privacy_page ) ) ) { | |
| 309 | - $caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) ); | |
| 310 | - } | |
| 311 | - } | |
| 312 | - | |
| 313 | - return $caps; | |
| 314 | - } | |
| 315 | - | |
| 316 | - /** | |
| 317 | - * Register our personal data exporter | |
| 318 | - * | |
| 319 | - * @since 2.3.6 | |
| 320 | - * | |
| 321 | - * @param array $exporters Personal data exporters | |
| 322 | - * @retun array | |
| 323 | - */ | |
| 324 | - public function register_personal_data_exporter( $exporters ) { | |
| 325 | - $exporters[] = array( | |
| 326 | - 'exporter_friendly_name' => __( 'Translated user descriptions', 'polylang' ), | |
| 327 | - 'callback' => array( $this, 'user_data_exporter' ), | |
| 328 | - ); | |
| 329 | - return $exporters; | |
| 330 | - } | |
| 331 | - | |
| 332 | - /** | |
| 333 | - * Export translated user description as WP exports only the description in the default language | |
| 334 | - * | |
| 335 | - * @since 2.3.6 | |
| 336 | - * | |
| 337 | - * @param string $email_address User email address | |
| 338 | - * @return array Personal data | |
| 339 | - */ | |
| 340 | - public function user_data_exporter( $email_address ) { | |
| 341 | - $email_address = trim( $email_address ); | |
| 342 | - $data_to_export = array(); | |
| 343 | - $user_data_to_export = array(); | |
| 344 | - | |
| 345 | - if ( $user = get_user_by( 'email', $email_address ) ) { | |
| 346 | - foreach ( $this->model->get_languages_list() as $lang ) { | |
| 347 | - if ( $lang->slug !== $this->options['default_lang'] && $value = get_user_meta( $user->ID, 'description_' . $lang->slug, true ) ) { | |
| 348 | - $user_data_to_export[] = array( | |
| 349 | - /* translators: %s is a language native name */ | |
| 350 | - 'name' => sprintf( __( 'User description - %s', 'polylang' ), $lang->name ), | |
| 351 | - 'value' => $value, | |
| 352 | - ); | |
| 353 | - } | |
| 354 | - } | |
| 355 | - | |
| 356 | - if ( ! empty( $user_data_to_export ) ) { | |
| 357 | - $data_to_export[] = array( | |
| 358 | - 'group_id' => 'user', | |
| 359 | - 'group_label' => __( 'User', 'polylang' ), | |
| 360 | - 'item_id' => "user-{$user->ID}", | |
| 361 | - 'data' => $user_data_to_export, | |
| 362 | - ); | |
| 363 | - } | |
| 364 | - } | |
| 365 | - | |
| 366 | - return array( | |
| 367 | - 'data' => $data_to_export, | |
| 368 | - 'done' => true, | |
| 369 | - ); | |
| 370 | 270 | } |
| 371 | 271 | } |