PluginProbe
Polylang / 3.6.7
Polylang v3.6.7
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 | admin/admin-model.php +177 -254 3.03.6.7 View file →
@@ -16,27 +16,34 @@
16 16 *
17 17 * @since 1.2
18 18 *
19 19 * @param array $args {
20 - * @type string $name Language name ( used only for display ).
21 - * @type string $slug Language code ( ideally 2-letters ISO 639-1 language code ).
22 - * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
20 + * @type string $name Language name (used only for display).
21 + * @type string $slug Language code (ideally 2-letters ISO 639-1 language code).
22 + * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will
23 + * not be loaded...
23 24 * @type int $rtl 1 if rtl language, 0 otherwise.
24 25 * @type int $term_group Language order when displayed.
25 26 * @type string $no_default_cat Optional, if set, no default category will be created for this language.
26 - * @type string $flag Optional, country code, @see flags.php.
27 + * @type string $flag Optional, country code, {@see settings/flags.php}.
27 28 * }
28 29 * @return WP_Error|true true if success / WP_Error if failed.
29 30 */
30 31 public function add_language( $args ) {
31 32 $errors = $this->validate_lang( $args );
32 - if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0
33 + if ( $errors->has_errors() ) {
33 34 return $errors;
34 35 }
35 36
36 37 // First the language taxonomy
37 - $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
38 - $r = wp_insert_term( $args['name'], 'language', array( 'slug' => $args['slug'], 'description' => $description ) );
38 + $r = wp_insert_term(
39 + $args['name'],
40 + 'language',
41 + array(
42 + 'slug' => $args['slug'],
43 + 'description' => $this->build_language_metas( $args ),
44 + )
45 + );
39 46 if ( is_wp_error( $r ) ) {
40 47 // Avoid an ugly fatal error if something went wrong ( reported once in the forum )
41 48 return new WP_Error( 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) );
42 49 }
@@ -41,28 +48,22 @@
41 48 return new WP_Error( 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) );
42 49 }
43 50 wp_update_term( (int) $r['term_id'], 'language', array( 'term_group' => (int) $args['term_group'] ) ); // can't set the term group directly in wp_insert_term
44 51
45 - // The term_language taxonomy
46 - // Don't want shared terms so use a different slug
47 - wp_insert_term( $args['name'], 'term_language', array( 'slug' => 'pll_' . $args['slug'] ) );
52 + // The other language taxonomies.
53 + $this->update_secondary_language_terms( $args['slug'], $args['name'] );
48 54
49 - $this->clean_languages_cache(); // Update the languages list now !
50 -
51 55 if ( ! isset( $this->options['default_lang'] ) ) {
52 56 // If this is the first language created, set it as default language
53 57 $this->options['default_lang'] = $args['slug'];
54 58 update_option( 'polylang', $this->options );
59 + }
55 60
56 - // And assign default language to default category
57 - $this->term->set_language( (int) get_option( 'default_category' ), (int) $r['term_id'] );
58 - } elseif ( empty( $args['no_default_cat'] ) ) {
59 - $this->create_default_category( $args['slug'] );
60 - }
61 + // Refresh languages.
62 + $this->clean_languages_cache();
63 + $this->get_languages_list();
61 64
62 - // Init a mo_id for this language
63 - $mo = new PLL_MO();
64 - $mo->export_to_db( $this->get_language( $args['slug'] ) );
65 + flush_rewrite_rules(); // Refresh rewrite rules.
65 66
66 67 /**
67 68 * Fires when a language is added.
68 69 *
@@ -71,10 +72,8 @@
71 72 * @param array $args Arguments used to create the language. @see PLL_Admin_Model::add_language().
72 73 */
73 74 do_action( 'pll_add_language', $args );
74 75
75 - $this->clean_languages_cache(); // Again to set add mo_id in the cached languages list
76 - flush_rewrite_rules(); // Refresh rewrite rules
77 76 return true;
78 77 }
79 78
80 79 /**
@@ -93,9 +92,9 @@
93 92 }
94 93
95 94 // Oops ! we are deleting the default language...
96 95 // Need to do this before loosing the information for default category translations
97 - if ( $this->options['default_lang'] == $lang->slug ) {
96 + if ( $lang->is_default ) {
98 97 $slugs = $this->get_languages_list( array( 'fields' => 'slug' ) );
99 98 $slugs = array_diff( $slugs, array( $lang->slug ) );
100 99
101 100 if ( ! empty( $slugs ) ) {
@@ -132,28 +131,29 @@
132 131 }
133 132 }
134 133
135 134 // Delete users options
136 - foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
137 - delete_user_meta( $user_id, 'pll_filter_content', $lang->slug );
138 - delete_user_meta( $user_id, 'description_' . $lang->slug );
139 - }
135 + delete_metadata( 'user', 0, 'pll_filter_content', '', true );
136 + delete_metadata( 'user', 0, "description_{$lang->slug}", '', true );
140 137
141 - // Delete the string translations
142 - $post = wpcom_vip_get_page_by_title( 'polylang_mo_' . $lang->term_id, OBJECT, 'polylang_mo' );
143 - if ( $post instanceof WP_Post ) {
144 - wp_delete_post( $post->ID );
145 - }
146 -
147 138 // Delete domain
148 139 unset( $this->options['domains'][ $lang->slug ] );
149 140
150 - // Delete the language itself
151 - wp_delete_term( $lang->term_id, 'language' );
152 - wp_delete_term( $lang->tl_term_id, 'term_language' );
141 + /*
142 + * Delete the language itself.
143 + *
144 + * Reverses the language taxonomies order is required to make sure 'language' is deleted in last.
145 + *
146 + * The initial order with the 'language' taxonomy at the beginning of 'PLL_Language::term_props' property
147 + * is done by {@see PLL_Model::filter_language_terms_orderby()}
148 + */
149 + foreach ( array_reverse( $lang->get_tax_props( 'term_id' ) ) as $taxonomy_name => $term_id ) {
150 + wp_delete_term( $term_id, $taxonomy_name );
151 + }
153 152
154 - // Update languages list
153 + // Refresh languages.
155 154 $this->clean_languages_cache();
155 + $this->get_languages_list();
156 156
157 157 update_option( 'polylang', $this->options );
158 158 flush_rewrite_rules(); // refresh rewrite rules
159 159 return true;
@@ -177,8 +177,12 @@
177 177 */
178 178 public function update_language( $args ) {
179 179 $lang = $this->get_language( (int) $args['lang_id'] );
180 180
181 + if ( empty( $lang ) ) {
182 + return new WP_Error( 'pll_invalid_language_id', __( 'The language does not seem to exist.', 'polylang' ) );
183 + }
184 +
181 185 $errors = $this->validate_lang( $args, $lang );
182 186 if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0
183 187 return $errors;
184 188 }
@@ -224,9 +228,9 @@
224 228 unset( $this->options['domains'][ $old_slug ] );
225 229 }
226 230
227 231 // Update the default language option if necessary
228 - if ( $this->options['default_lang'] == $old_slug ) {
232 + if ( $lang->is_default ) {
229 233 $this->options['default_lang'] = $slug;
230 234 }
231 235 }
232 236
@@ -231,28 +235,121 @@
231 235 }
232 236
233 237 update_option( 'polylang', $this->options );
234 238
235 - // And finally update the language itself
236 - $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
237 - wp_update_term( (int) $lang->term_id, 'language', array( 'slug' => $slug, 'name' => $args['name'], 'description' => $description, 'term_group' => (int) $args['term_group'] ) );
238 - wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) );
239 + // And finally update the language itself.
240 + $this->update_secondary_language_terms( $args['slug'], $args['name'], $lang );
239 241
242 + $description = $this->build_language_metas( $args );
243 + wp_update_term( $lang->get_tax_prop( 'language', 'term_id' ), 'language', array( 'slug' => $slug, 'name' => $args['name'], 'description' => $description, 'term_group' => (int) $args['term_group'] ) );
244 +
245 + // Refresh languages.
246 + $this->clean_languages_cache();
247 + $this->get_languages_list();
248 +
249 + // Refresh rewrite rules.
250 + flush_rewrite_rules();
251 +
240 252 /**
241 - * Fires when a language is updated.
253 + * Fires after a language is updated.
242 254 *
243 255 * @since 1.9
256 + * @since 3.2 Added $lang parameter.
244 257 *
245 - * @param array $args Arguments used to modify the language. @see PLL_Admin_Model::update_language().
258 + * @param array $args {
259 + * Arguments used to modify the language. @see PLL_Admin_Model::update_language().
260 + *
261 + * @type string $name Language name (used only for display).
262 + * @type string $slug Language code (ideally 2-letters ISO 639-1 language code).
263 + * @type string $locale WordPress locale.
264 + * @type int $rtl 1 if rtl language, 0 otherwise.
265 + * @type int $term_group Language order when displayed.
266 + * @type string $no_default_cat Optional, if set, no default category has been created for this language.
267 + * @type string $flag Optional, country code, @see flags.php.
268 + * }
269 + * @param PLL_Language $lang Previous value of the language being edited.
246 270 */
247 - do_action( 'pll_update_language', $args );
271 + do_action( 'pll_update_language', $args, $lang );
248 272
249 - $this->clean_languages_cache();
250 - flush_rewrite_rules(); // Refresh rewrite rules
251 273 return true;
252 274 }
253 275
254 276 /**
277 + * Builds the language metas into an array and serializes it, to be stored in the term description.
278 + *
279 + * @since 3.4
280 + *
281 + * @param array $args {
282 + * @type string $name Language name (used only for display).
283 + * @type string $slug Language code (ideally 2-letters ISO 639-1 language code).
284 + * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be
285 + * loaded...
286 + * @type int $rtl 1 if rtl language, 0 otherwise.
287 + * @type int $term_group Language order when displayed.
288 + * @type int $lang_id Optional, ID of the language to modify. An empty value means the language is being
289 + * created.
290 + * @type string $flag Optional, country code, {@see settings/flags.php}.
291 + * }
292 + * @return string The serialized description array updated.
293 + */
294 + protected function build_language_metas( array $args ) {
295 + if ( ! empty( $args['lang_id'] ) ) {
296 + $language_term = get_term( (int) $args['lang_id'] );
297 +
298 + if ( $language_term instanceof WP_Term ) {
299 + $old_data = maybe_unserialize( $language_term->description );
300 + }
301 + }
302 +
303 + if ( empty( $old_data ) || ! is_array( $old_data ) ) {
304 + $old_data = array();
305 + }
306 +
307 + $new_data = array(
308 + 'locale' => $args['locale'],
309 + 'rtl' => ! empty( $args['rtl'] ) ? 1 : 0,
310 + 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'],
311 + );
312 +
313 + /**
314 + * Allow to add data to store for a language.
315 + * `$locale`, `$rtl`, and `$flag_code` cannot be overwritten.
316 + *
317 + * @since 3.4
318 + *
319 + * @param mixed[] $add_data Data to add.
320 + * @param mixed[] $args {
321 + * Arguments used to create the language.
322 + *
323 + * @type string $name Language name (used only for display).
324 + * @type string $slug Language code (ideally 2-letters ISO 639-1 language code).
325 + * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will
326 + * not be loaded...
327 + * @type int $rtl 1 if rtl language, 0 otherwise.
328 + * @type int $term_group Language order when displayed.
329 + * @type int $lang_id Optional, ID of the language to modify. An empty value means the language is
330 + * being created.
331 + * @type string $flag Optional, country code, {@see settings/flags.php}.
332 + * }
333 + * @param mixed[] $new_data New data.
334 + * @param mixed[] $old_data {
335 + * Original data. Contains at least the following:
336 + *
337 + * @type string $locale WordPress locale.
338 + * @type int $rtl 1 if rtl language, 0 otherwise.
339 + * @type string $flag_code Country code.
340 + * }
341 + */
342 + $add_data = apply_filters( 'pll_language_metas', array(), $args, $new_data, $old_data );
343 + // Don't allow to overwrite `$locale`, `$rtl`, and `$flag_code`.
344 + $new_data = array_merge( $old_data, $add_data, $new_data );
345 +
346 + /** @var non-empty-string $serialized maybe_serialize() cannot return anything else than a string when fed by an array. */
347 + $serialized = maybe_serialize( $new_data );
348 + return $serialized;
349 + }
350 +
351 + /**
255 352 * Validates data entered when creating or updating a language.
256 353 *
257 354 * @see PLL_Admin_Model::add_language().
258 355 *
@@ -257,10 +354,10 @@
257 354 * @see PLL_Admin_Model::add_language().
258 355 *
259 356 * @since 0.4
260 357 *
261 - * @param array $args Parameters of {@see PLL_Admin_Model::add_language() or @see PLL_Admin_Model::update_language()}.
262 - * @param PLL_Language $lang Optional the language currently updated, the language is created if not set.
358 + * @param array $args Parameters of {@see PLL_Admin_Model::add_language() or @see PLL_Admin_Model::update_language()}.
359 + * @param PLL_Language|null $lang Optional the language currently updated, the language is created if not set.
263 360 * @return WP_Error
264 361 */
265 362 protected function validate_lang( $args, $lang = null ) {
266 363 $errors = new WP_Error();
@@ -288,9 +385,9 @@
288 385 $errors->add( 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) );
289 386 }
290 387
291 388 // Validate flag
292 - if ( ! empty( $args['flag'] ) && ! file_exists( POLYLANG_DIR . '/flags/' . $args['flag'] . '.png' ) ) {
389 + if ( ! empty( $args['flag'] ) && ! is_readable( POLYLANG_DIR . '/flags/' . $args['flag'] . '.png' ) ) {
293 390 $flag = PLL_Language::get_flag_informations( $args['flag'] );
294 391
295 392 if ( ! empty( $flag['url'] ) ) {
296 393 $response = function_exists( 'vip_safe_wp_remote_get' ) ? vip_safe_wp_remote_get( esc_url_raw( $flag['url'] ) ) : wp_remote_get( esc_url_raw( $flag['url'] ) );
@@ -304,206 +401,8 @@
304 401 return $errors;
305 402 }
306 403
307 404 /**
308 - * Assigns a language to posts or terms in mass.
309 - *
310 - * @since 1.2
311 - *
312 - * @param string $type Either 'post' or 'term'.
313 - * @param int[] $ids Array of post ids or term ids.
314 - * @param PLL_Language|string $lang Language to assign to the posts or terms.
315 - * @return void
316 - */
317 - public function set_language_in_mass( $type, $ids, $lang ) {
318 - global $wpdb;
319 -
320 - $lang = $this->get_language( $lang );
321 -
322 - if ( empty( $lang ) ) {
323 - return;
324 - }
325 -
326 - $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
327 - $values = array();
328 - $ids = array_map( 'intval', $ids );
329 -
330 - foreach ( $ids as $id ) {
331 - $values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id );
332 - }
333 -
334 - if ( ! empty( $values ) ) {
335 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
336 - $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', array_unique( $values ) ) );
337 - $lang->update_count(); // Updating term count is mandatory ( thanks to AndyDeGroo )
338 - }
339 -
340 - if ( 'term' === $type ) {
341 - clean_term_cache( $ids, 'term_language' );
342 - $translations = array();
343 -
344 - foreach ( $ids as $id ) {
345 - $translations[] = array( $lang->slug => $id );
346 - }
347 -
348 - if ( ! empty( $translations ) ) {
349 - $this->set_translation_in_mass( 'term', $translations );
350 - }
351 - } else {
352 - clean_term_cache( $ids, 'language' );
353 - }
354 - }
355 -
356 - /**
357 - * Creates translations groups in mass.
358 - *
359 - * @since 1.6.3
360 - *
361 - * @param string $type Either 'post' or 'term'
362 - * @param array $translations Array of translations arrays.
363 - * @return void
364 - */
365 - public function set_translation_in_mass( $type, $translations ) {
366 - global $wpdb;
367 -
368 - $taxonomy = $type . '_translations';
369 - $terms = array();
370 - $slugs = array();
371 - $description = array();
372 - $count = array();
373 -
374 - foreach ( $translations as $t ) {
375 - $term = uniqid( 'pll_' ); // the term name
376 - $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term );
377 - $slugs[] = $wpdb->prepare( '%s', $term );
378 - $description[ $term ] = maybe_serialize( $t );
379 - $count[ $term ] = count( $t );
380 - }
381 -
382 - // Insert terms
383 - if ( ! empty( $terms ) ) {
384 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
385 - $wpdb->query( "INSERT INTO {$wpdb->terms} ( slug, name ) VALUES " . implode( ',', array_unique( $terms ) ) );
386 - }
387 -
388 - // Get all terms with their term_id
389 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
390 - $terms = $wpdb->get_results( "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
391 - $term_ids = array();
392 - $tts = array();
393 -
394 - // Prepare terms taxonomy relationship
395 - foreach ( $terms as $term ) {
396 - $term_ids[] = $term->term_id;
397 - $tts[] = $wpdb->prepare( '( %d, %s, %s, %d )', $term->term_id, $taxonomy, $description[ $term->slug ], $count[ $term->slug ] );
398 - }
399 -
400 - // Insert term_taxonomy
401 - if ( ! empty( $tts ) ) {
402 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
403 - $wpdb->query( "INSERT INTO {$wpdb->term_taxonomy} ( term_id, taxonomy, description, count ) VALUES " . implode( ',', array_unique( $tts ) ) );
404 - }
405 -
406 - // Get all terms with term_taxonomy_id
407 - $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
408 - $trs = array();
409 -
410 - // Prepare objects relationships.
411 - if ( is_array( $terms ) ) {
412 - foreach ( $terms as $term ) {
413 - $t = maybe_unserialize( $term->description );
414 - if ( in_array( $t, $translations ) ) {
415 - foreach ( $t as $object_id ) {
416 - if ( ! empty( $object_id ) ) {
417 - $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
418 - }
419 - }
420 - }
421 - }
422 - }
423 -
424 - // Insert term_relationships
425 - if ( ! empty( $trs ) ) {
426 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
427 - $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
428 - $trs = array_unique( $trs );
429 - }
430 -
431 - clean_term_cache( $term_ids, $taxonomy );
432 - }
433 -
434 - /**
435 - * Returns untranslated posts and terms ids ( used in settings ).
436 - *
437 - * @since 0.9
438 - * @since 2.2.6 Add the $limit argument.
439 - *
440 - * @param int $limit Max number of posts or terms to return. Defaults to -1 (no limit).
441 - * @return array {
442 - * Objects without language.
443 - *
444 - * @type int[] $posts Array of post ids.
445 - * @type int[] $terms Array of term ids.
446 - * }
447 - */
448 - public function get_objects_with_no_lang( $limit = -1 ) {
449 - global $wpdb;
450 -
451 - /**
452 - * Filters the max number of posts or terms to return when searching objects with no language.
453 - * This filter can be used to decrease the memory usage in case the number of objects
454 - * without language is too big. Using a negative value is equivalent to have no limit.
455 - *
456 - * @since 2.2.6
457 - *
458 - * @param int $limit Max number of posts or terms to retrieve from the database.
459 - */
460 - $limit = (int) apply_filters( 'get_objects_with_no_lang_limit', $limit );
461 -
462 - $posts = get_posts(
463 - array(
464 - 'numberposts' => $limit,
465 - 'nopaging' => $limit <= 0,
466 - 'post_type' => $this->get_translated_post_types(),
467 - 'post_status' => 'any',
468 - 'fields' => 'ids',
469 - 'tax_query' => array(
470 - array(
471 - 'taxonomy' => 'language',
472 - 'terms' => $this->get_languages_list( array( 'fields' => 'term_id' ) ),
473 - 'operator' => 'NOT IN',
474 - ),
475 - ),
476 - )
477 - );
478 -
479 - // PHPCS:disable WordPress.DB.PreparedSQL
480 - $terms = $wpdb->get_col(
481 - sprintf(
482 - "SELECT {$wpdb->term_taxonomy}.term_id FROM {$wpdb->term_taxonomy}
483 - WHERE taxonomy IN ('%s')
484 - AND {$wpdb->term_taxonomy}.term_id NOT IN (
485 - SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (%s)
486 - )
487 - %s",
488 - implode( "','", array_map( 'esc_sql', $this->get_translated_taxonomies() ) ),
489 - implode( ',', array_map( 'intval', $this->get_languages_list( array( 'fields' => 'tl_term_taxonomy_id' ) ) ) ),
490 - $limit > 0 ? "LIMIT {$limit}" : ''
491 - )
492 - );
493 - // PHPCS:enable
494 -
495 - /**
496 - * Filters the list of untranslated posts ids and terms ids
497 - *
498 - * @since 0.9
499 - *
500 - * @param array|false $objects false if no ids found, list of post and/or term ids otherwise.
501 - */
502 - return apply_filters( 'pll_get_objects_with_no_lang', empty( $posts ) && empty( $terms ) ? false : array( 'posts' => $posts, 'terms' => $terms ) );
503 - }
504 -
505 - /**
506 405 * Updates the translations when a language slug has been modified in settings
507 406 * or deletes them when a language is removed.
508 407 *
509 408 * @since 0.5
@@ -514,18 +413,39 @@
514 413 */
515 414 public function update_translations( $old_slug, $new_slug = '' ) {
516 415 global $wpdb;
517 416
518 - $terms = get_terms( array( 'post_translations', 'term_translations' ) );
519 417 $term_ids = array();
520 418 $dr = array();
521 419 $dt = array();
522 420 $ut = array();
523 421
422 + $taxonomies = $this->translatable_objects->get_taxonomy_names( array( 'translations' ) );
423 + $terms = get_terms( array( 'taxonomy' => $taxonomies ) );
424 +
524 425 if ( is_array( $terms ) ) {
525 426 foreach ( $terms as $term ) {
526 427 $term_ids[ $term->taxonomy ][] = $term->term_id;
527 428 $tr = maybe_unserialize( $term->description );
429 +
430 + /**
431 + * Filters the unserialized translation group description before it is
432 + * updated when a language is deleted or a language slug is changed.
433 + *
434 + * @since 3.2
435 + *
436 + * @param (int|string[])[] $tr {
437 + * List of translations with lang codes as array keys and IDs as array values.
438 + * Also in this array:
439 + *
440 + * @type string[] $sync List of synchronized translations with lang codes as array keys and array values.
441 + * }
442 + * @param string $old_slug The old language slug.
443 + * @param string $new_slug The new language slug.
444 + * @param WP_Term $term The term containing the post or term translation group.
445 + */
446 + $tr = apply_filters( 'update_translation_group', $tr, $old_slug, $new_slug, $term );
447 +
528 448 if ( ! empty( $tr[ $old_slug ] ) ) {
529 449 if ( $new_slug ) {
530 450 $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete
531 451 } else {
@@ -600,13 +520,16 @@
600 520 }
601 521 set_theme_mod( 'nav_menu_locations', $menus );
602 522 }
603 523
604 - // The default category should be in the default language
605 - $default_cats = $this->term->get_translations( get_option( 'default_category' ) );
606 - if ( isset( $default_cats[ $slug ] ) ) {
607 - update_option( 'default_category', $default_cats[ $slug ] );
608 - }
524 + /**
525 + * Fires when a default language is updated.
526 + *
527 + * @since 3.1
528 + *
529 + * @param string $slug Slug.
530 + */
531 + do_action( 'pll_update_default_lang', $slug );
609 532
610 533 // Update options
611 534 $this->options['default_lang'] = $slug;
612 535 update_option( 'polylang', $this->options );