PluginProbe
Polylang / 2.5.2
Polylang v2.5.2
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 +115 -161 3.0.32.5.2 View file →
@@ -1,11 +1,8 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * Extends the PLL_Model class with methods needed only in Polylang settings pages.
4 + * Extends the PLL_Model class with methods needed only in Polylang settings pages
8 5 *
9 6 * @since 1.2
10 7 */
11 8 class PLL_Admin_Model extends PLL_Model {
@@ -11,35 +8,38 @@
11 8 class PLL_Admin_Model extends PLL_Model {
12 9
13 10 /**
14 11 * Adds a new language
15 - * and creates a default category for this language.
12 + * Creates a default category for this language
16 13 *
14 + * List of arguments that $args must contain:
15 + * name -> language name ( used only for display )
16 + * slug -> language code ( ideally 2-letters ISO 639-1 language code )
17 + * locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
18 + * rtl -> 1 if rtl language, 0 otherwise
19 + * term_group -> language order when displayed
20 + *
21 + * Optional arguments that $args can contain:
22 + * no_default_cat -> if set, no default category will be created for this language
23 + * flag -> country code, see flags.php
24 + *
17 25 * @since 1.2
18 26 *
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...
23 - * @type int $rtl 1 if rtl language, 0 otherwise.
24 - * @type int $term_group Language order when displayed.
25 - * @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 - * }
28 - * @return WP_Error|true true if success / WP_Error if failed.
27 + * @param array $args
28 + * @return bool true if success / false if failed
29 29 */
30 30 public function add_language( $args ) {
31 - $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 - return $errors;
31 + if ( ! $this->validate_lang( $args ) ) {
32 + return false;
34 33 }
35 34
36 35 // First the language taxonomy
37 - $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
36 + $description = serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
38 37 $r = wp_insert_term( $args['name'], 'language', array( 'slug' => $args['slug'], 'description' => $description ) );
39 38 if ( is_wp_error( $r ) ) {
40 39 // Avoid an ugly fatal error if something went wrong ( reported once in the forum )
41 - return new WP_Error( 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) );
40 + add_settings_error( 'general', 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) );
41 + return false;
42 42 }
43 43 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 44
45 45 // The term_language taxonomy
@@ -63,34 +63,35 @@
63 63 $mo = new PLL_MO();
64 64 $mo->export_to_db( $this->get_language( $args['slug'] ) );
65 65
66 66 /**
67 - * Fires when a language is added.
67 + * Fires when a language is added
68 68 *
69 69 * @since 1.9
70 70 *
71 - * @param array $args Arguments used to create the language. @see PLL_Admin_Model::add_language().
71 + * @param array $args arguments used to create the language
72 72 */
73 73 do_action( 'pll_add_language', $args );
74 74
75 75 $this->clean_languages_cache(); // Again to set add mo_id in the cached languages list
76 76 flush_rewrite_rules(); // Refresh rewrite rules
77 +
78 + add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
77 79 return true;
78 80 }
79 81
80 82 /**
81 - * Delete a language.
83 + * Delete a language
82 84 *
83 85 * @since 1.2
84 86 *
85 - * @param int $lang_id Language term_id.
86 - * @return bool
87 + * @param int $lang_id language term_id
87 88 */
88 89 public function delete_language( $lang_id ) {
89 90 $lang = $this->get_language( (int) $lang_id );
90 91
91 92 if ( empty( $lang ) ) {
92 - return false;
93 + return;
93 94 }
94 95
95 96 // Oops ! we are deleting the default language...
96 97 // Need to do this before loosing the information for default category translations
@@ -125,9 +126,9 @@
125 126
126 127 // Delete menus locations
127 128 if ( ! empty( $this->options['nav_menus'] ) ) {
128 129 foreach ( $this->options['nav_menus'] as $theme => $locations ) {
129 - foreach ( array_keys( $locations ) as $location ) {
130 + foreach ( $locations as $location => $languages ) {
130 131 unset( $this->options['nav_menus'][ $theme ][ $location ][ $lang->slug ] );
131 132 }
132 133 }
133 134 }
@@ -139,9 +140,9 @@
139 140 }
140 141
141 142 // Delete the string translations
142 143 $post = wpcom_vip_get_page_by_title( 'polylang_mo_' . $lang->term_id, OBJECT, 'polylang_mo' );
143 - if ( $post instanceof WP_Post ) {
144 + if ( ! empty( $post ) ) {
144 145 wp_delete_post( $post->ID );
145 146 }
146 147
147 148 // Delete domain
@@ -155,33 +156,34 @@
155 156 $this->clean_languages_cache();
156 157
157 158 update_option( 'polylang', $this->options );
158 159 flush_rewrite_rules(); // refresh rewrite rules
159 - return true;
160 + add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
160 161 }
161 162
162 163 /**
163 - * Updates language properties.
164 + * Update language properties
164 165 *
166 + * List of arguments that $args must contain:
167 + * lang_id -> term_id of the language to modify
168 + * name -> language name ( used only for display )
169 + * slug -> language code ( ideally 2-letters ISO 639-1 language code
170 + * locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
171 + * rtl -> 1 if rtl language, 0 otherwise
172 + * term_group -> language order when displayed
173 + *
174 + * Optional arguments that $args can contain:
175 + * flag -> country code, see flags.php
176 + *
165 177 * @since 1.2
166 178 *
167 - * @param array $args {
168 - * @type int $lang_id Id of the language to modify.
169 - * @type string $name Language name ( used only for display ).
170 - * @type string $slug Language code ( ideally 2-letters ISO 639-1 language code ).
171 - * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
172 - * @type int $rtl 1 if rtl language, 0 otherwise.
173 - * @type int $term_group Language order when displayed.
174 - * @type string $flag Optional, country code, @see flags.php.
175 - * }
176 - * @return WP_Error|true true if success / WP_Error if failed.
179 + * @param array $args
180 + * @return bool true if success / false if failed
177 181 */
178 182 public function update_language( $args ) {
179 183 $lang = $this->get_language( (int) $args['lang_id'] );
180 -
181 - $errors = $this->validate_lang( $args, $lang );
182 - if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0
183 - return $errors;
184 + if ( ! $this->validate_lang( $args, $lang ) ) {
185 + return false;
184 186 }
185 187
186 188 // Update links to this language in posts and terms in case the slug has been modified
187 189 $slug = $args['slug'];
@@ -208,9 +210,9 @@
208 210
209 211 // Update menus locations
210 212 if ( ! empty( $this->options['nav_menus'] ) ) {
211 213 foreach ( $this->options['nav_menus'] as $theme => $locations ) {
212 - foreach ( array_keys( $locations ) as $location ) {
214 + foreach ( $locations as $location => $languages ) {
213 215 if ( ! empty( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] ) ) {
214 216 $this->options['nav_menus'][ $theme ][ $location ][ $slug ] = $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ];
215 217 unset( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] );
216 218 }
@@ -232,59 +234,53 @@
232 234
233 235 update_option( 'polylang', $this->options );
234 236
235 237 // 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'] ) );
238 + $description = serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
237 239 wp_update_term( (int) $lang->term_id, 'language', array( 'slug' => $slug, 'name' => $args['name'], 'description' => $description, 'term_group' => (int) $args['term_group'] ) );
238 - if ( empty( $lang->tl_term_id ) ) {
239 - // Attempt to repair the term_language if it has been deleted by a database cleaning tool.
240 - wp_insert_term( $args['name'], 'term_language', array( 'slug' => 'pll_' . $slug ) );
241 - } else {
242 - wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) );
243 - }
240 + wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) );
244 241
245 242 /**
246 - * Fires when a language is updated.
243 + * Fires when a language is added
247 244 *
248 245 * @since 1.9
249 246 *
250 - * @param array $args Arguments used to modify the language. @see PLL_Admin_Model::update_language().
247 + * @param array $args arguments used to modify the language
251 248 */
252 249 do_action( 'pll_update_language', $args );
253 250
254 251 $this->clean_languages_cache();
255 252 flush_rewrite_rules(); // Refresh rewrite rules
253 + add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' );
256 254 return true;
257 255 }
258 256
259 257 /**
260 - * Validates data entered when creating or updating a language.
258 + * Validates data entered when creating or updating a language
261 259 *
262 - * @see PLL_Admin_Model::add_language().
260 + * @see PLL_Admin_Model::add_language
263 261 *
264 262 * @since 0.4
265 263 *
266 - * @param array $args Parameters of {@see PLL_Admin_Model::add_language() or @see PLL_Admin_Model::update_language()}.
267 - * @param PLL_Language $lang Optional the language currently updated, the language is created if not set.
268 - * @return WP_Error
264 + * @param array $args
265 + * @param object $lang optional the language currently updated, the language is created if not set
266 + * @return bool true if success / false if failed
269 267 */
270 268 protected function validate_lang( $args, $lang = null ) {
271 - $errors = new WP_Error();
272 -
273 269 // Validate locale with the same pattern as WP 4.3. See #28303
274 270 if ( ! preg_match( '#^[a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?$#', $args['locale'], $matches ) ) {
275 - $errors->add( 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) );
271 + add_settings_error( 'general', 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) );
276 272 }
277 273
278 274 // Validate slug characters
279 275 if ( ! preg_match( '#^[a-z_-]+$#', $args['slug'] ) ) {
280 - $errors->add( 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) );
276 + add_settings_error( 'general', 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) );
281 277 }
282 278
283 279 // Validate slug is unique
284 280 foreach ( $this->get_languages_list() as $language ) {
285 - if ( $language->slug === $args['slug'] && ( null === $lang || $lang->term_id !== $language->term_id ) ) {
286 - $errors->add( 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) );
281 + if ( $language->slug === $args['slug'] && ( null === $lang || ( isset( $lang ) && $lang->term_id != $language->term_id ) ) ) {
282 + add_settings_error( 'general', 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) );
287 283 }
288 284 }
289 285
290 286 // Validate name
@@ -289,50 +285,35 @@
289 285
290 286 // Validate name
291 287 // No need to sanitize it as wp_insert_term will do it for us
292 288 if ( empty( $args['name'] ) ) {
293 - $errors->add( 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) );
289 + add_settings_error( 'general', 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) );
294 290 }
295 291
296 292 // Validate flag
297 293 if ( ! empty( $args['flag'] ) && ! file_exists( POLYLANG_DIR . '/flags/' . $args['flag'] . '.png' ) ) {
298 - $flag = PLL_Language::get_flag_informations( $args['flag'] );
299 -
300 - if ( ! empty( $flag['url'] ) ) {
301 - $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'] ) );
302 - }
303 -
304 - if ( empty( $response ) || is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
305 - $errors->add( 'pll_invalid_flag', __( 'The flag does not exist', 'polylang' ) );
306 - }
294 + add_settings_error( 'general', 'pll_invalid_flag', __( 'The flag does not exist', 'polylang' ) );
307 295 }
308 296
309 - return $errors;
297 + return get_settings_errors() ? false : true;
310 298 }
311 299
312 300 /**
313 - * Assigns a language to posts or terms in mass.
301 + * Used to set the language of posts or terms in mass
314 302 *
315 303 * @since 1.2
316 304 *
317 - * @param string $type Either 'post' or 'term'.
318 - * @param int[] $ids Array of post ids or term ids.
319 - * @param PLL_Language|string $lang Language to assign to the posts or terms.
320 - * @return void
305 + * @param string $type either 'post' or 'term'
306 + * @param array $ids array of post ids or term ids
307 + * @param object|string $lang object or slug
321 308 */
322 309 public function set_language_in_mass( $type, $ids, $lang ) {
323 310 global $wpdb;
324 311
312 + $ids = array_map( 'intval', $ids );
325 313 $lang = $this->get_language( $lang );
314 + $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
326 315
327 - if ( empty( $lang ) ) {
328 - return;
329 - }
330 -
331 - $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
332 - $values = array();
333 - $ids = array_map( 'intval', $ids );
334 -
335 316 foreach ( $ids as $id ) {
336 317 $values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id );
337 318 }
338 319
@@ -343,9 +324,8 @@
343 324 }
344 325
345 326 if ( 'term' === $type ) {
346 327 clean_term_cache( $ids, 'term_language' );
347 - $translations = array();
348 328
349 329 foreach ( $ids as $id ) {
350 330 $translations[] = array( $lang->slug => $id );
351 331 }
@@ -358,30 +338,25 @@
358 338 }
359 339 }
360 340
361 341 /**
362 - * Creates translations groups in mass.
342 + * Used to create a translations groups in mass
363 343 *
364 344 * @since 1.6.3
365 345 *
366 - * @param string $type Either 'post' or 'term'
367 - * @param array $translations Array of translations arrays.
368 - * @return void
346 + * @param string $type either 'post' or 'term'
347 + * @param array $translations array of translations arrays
369 348 */
370 349 public function set_translation_in_mass( $type, $translations ) {
371 350 global $wpdb;
372 351
373 - $taxonomy = $type . '_translations';
374 - $terms = array();
375 - $slugs = array();
376 - $description = array();
377 - $count = array();
352 + $taxonomy = $type . '_translations';
378 353
379 354 foreach ( $translations as $t ) {
380 355 $term = uniqid( 'pll_' ); // the term name
381 356 $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term );
382 357 $slugs[] = $wpdb->prepare( '%s', $term );
383 - $description[ $term ] = maybe_serialize( $t );
358 + $description[ $term ] = serialize( $t );
384 359 $count[ $term ] = count( $t );
385 360 }
386 361
387 362 // Insert terms
@@ -391,11 +366,9 @@
391 366 }
392 367
393 368 // Get all terms with their term_id
394 369 // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
395 - $terms = $wpdb->get_results( "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
396 - $term_ids = array();
397 - $tts = array();
370 + $terms = $wpdb->get_results( "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
398 371
399 372 // Prepare terms taxonomy relationship
400 373 foreach ( $terms as $term ) {
401 374 $term_ids[] = $term->term_id;
@@ -409,19 +382,16 @@
409 382 }
410 383
411 384 // Get all terms with term_taxonomy_id
412 385 $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
413 - $trs = array();
414 386
415 - // Prepare objects relationships.
416 - if ( is_array( $terms ) ) {
417 - foreach ( $terms as $term ) {
418 - $t = maybe_unserialize( $term->description );
419 - if ( in_array( $t, $translations ) ) {
420 - foreach ( $t as $object_id ) {
421 - if ( ! empty( $object_id ) ) {
422 - $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
423 - }
387 + // Prepare objects relationships
388 + foreach ( $terms as $term ) {
389 + $t = unserialize( $term->description );
390 + if ( in_array( $t, $translations ) ) {
391 + foreach ( $t as $object_id ) {
392 + if ( ! empty( $object_id ) ) {
393 + $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
424 394 }
425 395 }
426 396 }
427 397 }
@@ -436,32 +406,27 @@
436 406 clean_term_cache( $term_ids, $taxonomy );
437 407 }
438 408
439 409 /**
440 - * Returns untranslated posts and terms ids ( used in settings ).
410 + * Returns untranslated posts and terms ids ( used in settings )
441 411 *
442 412 * @since 0.9
443 - * @since 2.2.6 Add the $limit argument.
413 + * @since 2.2.6 Add the $limit argument
444 414 *
445 - * @param int $limit Max number of posts or terms to return. Defaults to -1 (no limit).
446 - * @return array {
447 - * Objects without language.
448 - *
449 - * @type int[] $posts Array of post ids.
450 - * @type int[] $terms Array of term ids.
451 - * }
415 + * @param in $limit Max number of posts or terms to return. Defaults to -1 (no limit).
416 + * @return array Array made of an array of post ids and an array of term ids
452 417 */
453 418 public function get_objects_with_no_lang( $limit = -1 ) {
454 419 global $wpdb;
455 420
456 421 /**
457 - * Filters the max number of posts or terms to return when searching objects with no language.
422 + * Filters the max number of posts or terms to return when searching objects with no language
458 423 * This filter can be used to decrease the memory usage in case the number of objects
459 424 * without language is too big. Using a negative value is equivalent to have no limit.
460 425 *
461 426 * @since 2.2.6
462 427 *
463 - * @param int $limit Max number of posts or terms to retrieve from the database.
428 + * @param int $limit Max number of posts or terms to retrieve from the database
464 429 */
465 430 $limit = (int) apply_filters( 'get_objects_with_no_lang_limit', $limit );
466 431
467 432 $posts = get_posts(
@@ -480,9 +445,9 @@
480 445 ),
481 446 )
482 447 );
483 448
484 - // PHPCS:disable WordPress.DB.PreparedSQL
449 + // PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared
485 450 $terms = $wpdb->get_col(
486 451 sprintf(
487 452 "SELECT {$wpdb->term_taxonomy}.term_id FROM {$wpdb->term_taxonomy}
488 453 WHERE taxonomy IN ('%s')
@@ -497,56 +462,48 @@
497 462 );
498 463 // PHPCS:enable
499 464
500 465 /**
501 - * Filters the list of untranslated posts ids and terms ids
466 + * Filter the list of untranslated posts ids and terms ids
502 467 *
503 468 * @since 0.9
504 469 *
505 - * @param array|false $objects false if no ids found, list of post and/or term ids otherwise.
470 + * @param bool|array $objects false if no ids found, list of post and/or term ids otherwise
506 471 */
507 472 return apply_filters( 'pll_get_objects_with_no_lang', empty( $posts ) && empty( $terms ) ? false : array( 'posts' => $posts, 'terms' => $terms ) );
508 473 }
509 474
510 475 /**
511 - * Updates the translations when a language slug has been modified in settings
512 - * or deletes them when a language is removed.
476 + * Used to delete translations or update the translations when a language slug has been modified in settings
513 477 *
514 478 * @since 0.5
515 479 *
516 - * @param string $old_slug The old language slug.
517 - * @param string $new_slug Optional, the new language slug, if not set it means that the language has been deleted.
518 - * @return void
480 + * @param string $old_slug the old language slug
481 + * @param string $new_slug optional, the new language slug, if not set it means the correspondent has been deleted
519 482 */
520 483 public function update_translations( $old_slug, $new_slug = '' ) {
521 484 global $wpdb;
522 485
523 - $terms = get_terms( array( 'post_translations', 'term_translations' ) );
524 - $term_ids = array();
525 - $dr = array();
526 - $dt = array();
527 - $ut = array();
486 + $terms = get_terms( array( 'post_translations', 'term_translations' ) );
528 487
529 - if ( is_array( $terms ) ) {
530 - foreach ( $terms as $term ) {
531 - $term_ids[ $term->taxonomy ][] = $term->term_id;
532 - $tr = maybe_unserialize( $term->description );
533 - if ( ! empty( $tr[ $old_slug ] ) ) {
534 - if ( $new_slug ) {
535 - $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete
536 - } else {
537 - $dr['id'][] = (int) $tr[ $old_slug ];
538 - $dr['tt'][] = (int) $term->term_taxonomy_id;
539 - }
540 - unset( $tr[ $old_slug ] );
488 + foreach ( $terms as $term ) {
489 + $term_ids[ $term->taxonomy ][] = $term->term_id;
490 + $tr = unserialize( $term->description );
491 + if ( ! empty( $tr[ $old_slug ] ) ) {
492 + if ( $new_slug ) {
493 + $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete
494 + } else {
495 + $dr['id'][] = (int) $tr[ $old_slug ];
496 + $dr['tt'][] = (int) $term->term_taxonomy_id;
497 + }
498 + unset( $tr[ $old_slug ] );
541 499
542 - if ( empty( $tr ) || 1 == count( $tr ) ) {
543 - $dt['t'][] = (int) $term->term_id;
544 - $dt['tt'][] = (int) $term->term_taxonomy_id;
545 - } else {
546 - $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, maybe_serialize( $tr ) );
547 - $ut['in'][] = (int) $term->term_id;
548 - }
500 + if ( empty( $tr ) || 1 == count( $tr ) ) {
501 + $dt['t'][] = (int) $term->term_id;
502 + $dt['tt'][] = (int) $term->term_taxonomy_id;
503 + } else {
504 + $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, serialize( $tr ) );
505 + $ut['in'][] = (int) $term->term_id;
549 506 }
550 507 }
551 508 }
552 509
@@ -586,21 +543,18 @@
586 543 }
587 544
588 545 /**
589 546 * Updates the default language
590 - * taking care to update the default category & the nav menu locations.
547 + * taking care to update the default category & the nav menu locations
591 548 *
592 549 * @since 1.8
593 550 *
594 - * @param string $slug New language slug.
595 - * @return void
551 + * @param string $slug new language slug
596 552 */
597 553 public function update_default_lang( $slug ) {
598 554 // The nav menus stored in theme locations should be in the default language
599 555 $theme = get_stylesheet();
600 556 if ( ! empty( $this->options['nav_menus'][ $theme ] ) ) {
601 - $menus = array();
602 -
603 557 foreach ( $this->options['nav_menus'][ $theme ] as $key => $loc ) {
604 558 $menus[ $key ] = empty( $loc[ $slug ] ) ? 0 : $loc[ $slug ];
605 559 }
606 560 set_theme_mod( 'nav_menu_locations', $menus );