| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * @package Polylang |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | - * Extends the PLL_Model class with methods needed only in Polylang settings pages | |
| 7 | + * Extends the PLL_Model class with methods needed only in Polylang settings pages. | |
| 8 | 8 | * |
| 9 | 9 | * @since 1.2 |
| 10 | 10 | */ |
| 11 | 11 | class PLL_Admin_Model extends PLL_Model { |
| @@ -11,25 +11,22 @@ | ||
| 11 | 11 | class PLL_Admin_Model extends PLL_Model { |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Adds a new language |
| 15 | - * Creates a default category for this language | |
| 15 | + * and creates a default category for this language. | |
| 16 | 16 | * |
| 17 | - * List of arguments that $args must contain: | |
| 18 | - * name -> language name ( used only for display ) | |
| 19 | - * slug -> language code ( ideally 2-letters ISO 639-1 language code ) | |
| 20 | - * locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded... | |
| 21 | - * rtl -> 1 if rtl language, 0 otherwise | |
| 22 | - * term_group -> language order when displayed | |
| 23 | - * | |
| 24 | - * Optional arguments that $args can contain: | |
| 25 | - * no_default_cat -> if set, no default category will be created for this language | |
| 26 | - * flag -> country code, see flags.php | |
| 27 | - * | |
| 28 | 17 | * @since 1.2 |
| 29 | 18 | * |
| 30 | - * @param array $args | |
| 31 | - * @return bool true if success / false if failed | |
| 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. | |
| 32 | 29 | */ |
| 33 | 30 | public function add_language( $args ) { |
| 34 | 31 | $errors = $this->validate_lang( $args ); |
| 35 | 32 | if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0 |
| @@ -54,13 +51,8 @@ | ||
| 54 | 51 | if ( ! isset( $this->options['default_lang'] ) ) { |
| 55 | 52 | // If this is the first language created, set it as default language |
| 56 | 53 | $this->options['default_lang'] = $args['slug']; |
| 57 | 54 | update_option( 'polylang', $this->options ); |
| 58 | - | |
| 59 | - // And assign default language to default category | |
| 60 | - $this->term->set_language( (int) get_option( 'default_category' ), (int) $r['term_id'] ); | |
| 61 | - } elseif ( empty( $args['no_default_cat'] ) ) { | |
| 62 | - $this->create_default_category( $args['slug'] ); | |
| 63 | 55 | } |
| 64 | 56 | |
| 65 | 57 | // Init a mo_id for this language |
| 66 | 58 | $mo = new PLL_MO(); |
| @@ -66,13 +58,13 @@ | ||
| 66 | 58 | $mo = new PLL_MO(); |
| 67 | 59 | $mo->export_to_db( $this->get_language( $args['slug'] ) ); |
| 68 | 60 | |
| 69 | 61 | /** |
| 70 | - * Fires when a language is added | |
| 62 | + * Fires when a language is added. | |
| 71 | 63 | * |
| 72 | 64 | * @since 1.9 |
| 73 | 65 | * |
| 74 | - * @param array $args arguments used to create the language | |
| 66 | + * @param array $args Arguments used to create the language. @see PLL_Admin_Model::add_language(). | |
| 75 | 67 | */ |
| 76 | 68 | do_action( 'pll_add_language', $args ); |
| 77 | 69 | |
| 78 | 70 | $this->clean_languages_cache(); // Again to set add mo_id in the cached languages list |
| @@ -80,13 +72,14 @@ | ||
| 80 | 72 | return true; |
| 81 | 73 | } |
| 82 | 74 | |
| 83 | 75 | /** |
| 84 | - * Delete a language | |
| 76 | + * Delete a language. | |
| 85 | 77 | * |
| 86 | 78 | * @since 1.2 |
| 87 | 79 | * |
| 88 | - * @param int $lang_id language term_id | |
| 80 | + * @param int $lang_id Language term_id. | |
| 81 | + * @return bool | |
| 89 | 82 | */ |
| 90 | 83 | public function delete_language( $lang_id ) { |
| 91 | 84 | $lang = $this->get_language( (int) $lang_id ); |
| 92 | 85 | |
| @@ -141,9 +134,9 @@ | ||
| 141 | 134 | } |
| 142 | 135 | |
| 143 | 136 | // Delete the string translations |
| 144 | 137 | $post = wpcom_vip_get_page_by_title( 'polylang_mo_' . $lang->term_id, OBJECT, 'polylang_mo' ); |
| 145 | - if ( ! empty( $post ) ) { | |
| 138 | + if ( $post instanceof WP_Post ) { | |
| 146 | 139 | wp_delete_post( $post->ID ); |
| 147 | 140 | } |
| 148 | 141 | |
| 149 | 142 | // Delete domain |
| @@ -161,25 +154,22 @@ | ||
| 161 | 154 | return true; |
| 162 | 155 | } |
| 163 | 156 | |
| 164 | 157 | /** |
| 165 | - * Update language properties | |
| 158 | + * Updates language properties. | |
| 166 | 159 | * |
| 167 | - * List of arguments that $args must contain: | |
| 168 | - * lang_id -> term_id of the language to modify | |
| 169 | - * name -> language name ( used only for display ) | |
| 170 | - * slug -> language code ( ideally 2-letters ISO 639-1 language code | |
| 171 | - * locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded... | |
| 172 | - * rtl -> 1 if rtl language, 0 otherwise | |
| 173 | - * term_group -> language order when displayed | |
| 174 | - * | |
| 175 | - * Optional arguments that $args can contain: | |
| 176 | - * flag -> country code, see flags.php | |
| 177 | - * | |
| 178 | 160 | * @since 1.2 |
| 179 | 161 | * |
| 180 | - * @param array $args | |
| 181 | - * @return bool true if success / false if failed | |
| 162 | + * @param array $args { | |
| 163 | + * @type int $lang_id Id of the language to modify. | |
| 164 | + * @type string $name Language name ( used only for display ). | |
| 165 | + * @type string $slug Language code ( ideally 2-letters ISO 639-1 language code ). | |
| 166 | + * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded... | |
| 167 | + * @type int $rtl 1 if rtl language, 0 otherwise. | |
| 168 | + * @type int $term_group Language order when displayed. | |
| 169 | + * @type string $flag Optional, country code, @see flags.php. | |
| 170 | + * } | |
| 171 | + * @return WP_Error|true true if success / WP_Error if failed. | |
| 182 | 172 | */ |
| 183 | 173 | public function update_language( $args ) { |
| 184 | 174 | $lang = $this->get_language( (int) $args['lang_id'] ); |
| 185 | 175 | |
| @@ -239,18 +229,35 @@ | ||
| 239 | 229 | |
| 240 | 230 | // And finally update the language itself |
| 241 | 231 | $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) ); |
| 242 | 232 | wp_update_term( (int) $lang->term_id, 'language', array( 'slug' => $slug, 'name' => $args['name'], 'description' => $description, 'term_group' => (int) $args['term_group'] ) ); |
| 243 | - wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) ); | |
| 233 | + if ( empty( $lang->tl_term_id ) ) { | |
| 234 | + // Attempt to repair the term_language if it has been deleted by a database cleaning tool. | |
| 235 | + wp_insert_term( $args['name'], 'term_language', array( 'slug' => 'pll_' . $slug ) ); | |
| 236 | + } else { | |
| 237 | + wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) ); | |
| 238 | + } | |
| 244 | 239 | |
| 245 | 240 | /** |
| 246 | - * Fires when a language is added | |
| 241 | + * Fires after a language is updated. | |
| 247 | 242 | * |
| 248 | 243 | * @since 1.9 |
| 244 | + * @since 3.2 Added $lang parameter. | |
| 249 | 245 | * |
| 250 | - * @param array $args arguments used to modify the language | |
| 246 | + * @param array $args { | |
| 247 | + * Arguments used to modify the language. @see PLL_Admin_Model::update_language(). | |
| 248 | + * | |
| 249 | + * @type string $name Language name (used only for display). | |
| 250 | + * @type string $slug Language code (ideally 2-letters ISO 639-1 language code). | |
| 251 | + * @type string $locale WordPress locale. | |
| 252 | + * @type int $rtl 1 if rtl language, 0 otherwise. | |
| 253 | + * @type int $term_group Language order when displayed. | |
| 254 | + * @type string $no_default_cat Optional, if set, no default category has been created for this language. | |
| 255 | + * @type string $flag Optional, country code, @see flags.php. | |
| 256 | + * } | |
| 257 | + * @param PLL_Language $lang Previous value of the language beeing edited. | |
| 251 | 258 | */ |
| 252 | - do_action( 'pll_update_language', $args ); | |
| 259 | + do_action( 'pll_update_language', $args, $lang ); | |
| 253 | 260 | |
| 254 | 261 | $this->clean_languages_cache(); |
| 255 | 262 | flush_rewrite_rules(); // Refresh rewrite rules |
| 256 | 263 | return true; |
| @@ -256,17 +263,17 @@ | ||
| 256 | 263 | return true; |
| 257 | 264 | } |
| 258 | 265 | |
| 259 | 266 | /** |
| 260 | - * Validates data entered when creating or updating a language | |
| 267 | + * Validates data entered when creating or updating a language. | |
| 261 | 268 | * |
| 262 | - * @see PLL_Admin_Model::add_language | |
| 269 | + * @see PLL_Admin_Model::add_language(). | |
| 263 | 270 | * |
| 264 | 271 | * @since 0.4 |
| 265 | 272 | * |
| 266 | - * @param array $args | |
| 267 | - * @param object $lang optional the language currently updated, the language is created if not set | |
| 268 | - * @return bool true if success / false if failed | |
| 273 | + * @param array $args Parameters of {@see PLL_Admin_Model::add_language() or @see PLL_Admin_Model::update_language()}. | |
| 274 | + * @param PLL_Language $lang Optional the language currently updated, the language is created if not set. | |
| 275 | + * @return WP_Error | |
| 269 | 276 | */ |
| 270 | 277 | protected function validate_lang( $args, $lang = null ) { |
| 271 | 278 | $errors = new WP_Error(); |
| 272 | 279 | |
| @@ -281,9 +288,9 @@ | ||
| 281 | 288 | } |
| 282 | 289 | |
| 283 | 290 | // Validate slug is unique |
| 284 | 291 | foreach ( $this->get_languages_list() as $language ) { |
| 285 | - if ( $language->slug === $args['slug'] && ( null === $lang || ( isset( $lang ) && $lang->term_id != $language->term_id ) ) ) { | |
| 292 | + if ( $language->slug === $args['slug'] && ( null === $lang || $lang->term_id !== $language->term_id ) ) { | |
| 286 | 293 | $errors->add( 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) ); |
| 287 | 294 | } |
| 288 | 295 | } |
| 289 | 296 | |
| @@ -309,23 +316,29 @@ | ||
| 309 | 316 | return $errors; |
| 310 | 317 | } |
| 311 | 318 | |
| 312 | 319 | /** |
| 313 | - * Used to set the language of posts or terms in mass | |
| 320 | + * Assigns a language to posts or terms in mass. | |
| 314 | 321 | * |
| 315 | 322 | * @since 1.2 |
| 316 | 323 | * |
| 317 | - * @param string $type either 'post' or 'term' | |
| 318 | - * @param array $ids array of post ids or term ids | |
| 319 | - * @param object|string $lang object or slug | |
| 324 | + * @param string $type Either 'post' or 'term'. | |
| 325 | + * @param int[] $ids Array of post ids or term ids. | |
| 326 | + * @param PLL_Language|string $lang Language to assign to the posts or terms. | |
| 327 | + * @return void | |
| 320 | 328 | */ |
| 321 | 329 | public function set_language_in_mass( $type, $ids, $lang ) { |
| 322 | 330 | global $wpdb; |
| 323 | 331 | |
| 324 | - $ids = array_map( 'intval', $ids ); | |
| 325 | - $lang = $this->get_language( $lang ); | |
| 332 | + $lang = $this->get_language( $lang ); | |
| 333 | + | |
| 334 | + if ( empty( $lang ) ) { | |
| 335 | + return; | |
| 336 | + } | |
| 337 | + | |
| 326 | 338 | $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id; |
| 327 | 339 | $values = array(); |
| 340 | + $ids = array_map( 'intval', $ids ); | |
| 328 | 341 | |
| 329 | 342 | foreach ( $ids as $id ) { |
| 330 | 343 | $values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id ); |
| 331 | 344 | } |
| @@ -352,14 +365,15 @@ | ||
| 352 | 365 | } |
| 353 | 366 | } |
| 354 | 367 | |
| 355 | 368 | /** |
| 356 | - * Used to create a translations groups in mass | |
| 369 | + * Creates translations groups in mass. | |
| 357 | 370 | * |
| 358 | 371 | * @since 1.6.3 |
| 359 | 372 | * |
| 360 | - * @param string $type either 'post' or 'term' | |
| 361 | - * @param array $translations array of translations arrays | |
| 373 | + * @param string $type Either 'post' or 'term' | |
| 374 | + * @param array $translations Array of translations arrays. | |
| 375 | + * @return void | |
| 362 | 376 | */ |
| 363 | 377 | public function set_translation_in_mass( $type, $translations ) { |
| 364 | 378 | global $wpdb; |
| 365 | 379 | |
| @@ -401,18 +415,20 @@ | ||
| 401 | 415 | $wpdb->query( "INSERT INTO {$wpdb->term_taxonomy} ( term_id, taxonomy, description, count ) VALUES " . implode( ',', array_unique( $tts ) ) ); |
| 402 | 416 | } |
| 403 | 417 | |
| 404 | 418 | // Get all terms with term_taxonomy_id |
| 405 | - $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) ); | |
| 419 | + $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false ) ); | |
| 406 | 420 | $trs = array(); |
| 407 | 421 | |
| 408 | - // Prepare objects relationships | |
| 409 | - foreach ( $terms as $term ) { | |
| 410 | - $t = maybe_unserialize( $term->description ); | |
| 411 | - if ( in_array( $t, $translations ) ) { | |
| 412 | - foreach ( $t as $object_id ) { | |
| 413 | - if ( ! empty( $object_id ) ) { | |
| 414 | - $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id ); | |
| 422 | + // Prepare objects relationships. | |
| 423 | + if ( is_array( $terms ) ) { | |
| 424 | + foreach ( $terms as $term ) { | |
| 425 | + $t = maybe_unserialize( $term->description ); | |
| 426 | + if ( in_array( $t, $translations ) ) { | |
| 427 | + foreach ( $t as $object_id ) { | |
| 428 | + if ( ! empty( $object_id ) ) { | |
| 429 | + $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id ); | |
| 430 | + } | |
| 415 | 431 | } |
| 416 | 432 | } |
| 417 | 433 | } |
| 418 | 434 | } |
| @@ -427,108 +443,65 @@ | ||
| 427 | 443 | clean_term_cache( $term_ids, $taxonomy ); |
| 428 | 444 | } |
| 429 | 445 | |
| 430 | 446 | /** |
| 431 | - * Returns untranslated posts and terms ids ( used in settings ) | |
| 447 | + * Updates the translations when a language slug has been modified in settings | |
| 448 | + * or deletes them when a language is removed. | |
| 432 | 449 | * |
| 433 | - * @since 0.9 | |
| 434 | - * @since 2.2.6 Add the $limit argument | |
| 435 | - * | |
| 436 | - * @param in $limit Max number of posts or terms to return. Defaults to -1 (no limit). | |
| 437 | - * @return array Array made of an array of post ids and an array of term ids | |
| 438 | - */ | |
| 439 | - public function get_objects_with_no_lang( $limit = -1 ) { | |
| 440 | - global $wpdb; | |
| 441 | - | |
| 442 | - /** | |
| 443 | - * Filters the max number of posts or terms to return when searching objects with no language | |
| 444 | - * This filter can be used to decrease the memory usage in case the number of objects | |
| 445 | - * without language is too big. Using a negative value is equivalent to have no limit. | |
| 446 | - * | |
| 447 | - * @since 2.2.6 | |
| 448 | - * | |
| 449 | - * @param int $limit Max number of posts or terms to retrieve from the database | |
| 450 | - */ | |
| 451 | - $limit = (int) apply_filters( 'get_objects_with_no_lang_limit', $limit ); | |
| 452 | - | |
| 453 | - $posts = get_posts( | |
| 454 | - array( | |
| 455 | - 'numberposts' => $limit, | |
| 456 | - 'nopaging' => $limit <= 0, | |
| 457 | - 'post_type' => $this->get_translated_post_types(), | |
| 458 | - 'post_status' => 'any', | |
| 459 | - 'fields' => 'ids', | |
| 460 | - 'tax_query' => array( | |
| 461 | - array( | |
| 462 | - 'taxonomy' => 'language', | |
| 463 | - 'terms' => $this->get_languages_list( array( 'fields' => 'term_id' ) ), | |
| 464 | - 'operator' => 'NOT IN', | |
| 465 | - ), | |
| 466 | - ), | |
| 467 | - ) | |
| 468 | - ); | |
| 469 | - | |
| 470 | - // PHPCS:disable WordPress.DB.PreparedSQL | |
| 471 | - $terms = $wpdb->get_col( | |
| 472 | - sprintf( | |
| 473 | - "SELECT {$wpdb->term_taxonomy}.term_id FROM {$wpdb->term_taxonomy} | |
| 474 | - WHERE taxonomy IN ('%s') | |
| 475 | - AND {$wpdb->term_taxonomy}.term_id NOT IN ( | |
| 476 | - SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (%s) | |
| 477 | - ) | |
| 478 | - %s", | |
| 479 | - implode( "','", array_map( 'esc_sql', $this->get_translated_taxonomies() ) ), | |
| 480 | - implode( ',', array_map( 'intval', $this->get_languages_list( array( 'fields' => 'tl_term_taxonomy_id' ) ) ) ), | |
| 481 | - $limit > 0 ? "LIMIT {$limit}" : '' | |
| 482 | - ) | |
| 483 | - ); | |
| 484 | - // PHPCS:enable | |
| 485 | - | |
| 486 | - /** | |
| 487 | - * Filter the list of untranslated posts ids and terms ids | |
| 488 | - * | |
| 489 | - * @since 0.9 | |
| 490 | - * | |
| 491 | - * @param bool|array $objects false if no ids found, list of post and/or term ids otherwise | |
| 492 | - */ | |
| 493 | - return apply_filters( 'pll_get_objects_with_no_lang', empty( $posts ) && empty( $terms ) ? false : array( 'posts' => $posts, 'terms' => $terms ) ); | |
| 494 | - } | |
| 495 | - | |
| 496 | - /** | |
| 497 | - * Used to delete translations or update the translations when a language slug has been modified in settings | |
| 498 | - * | |
| 499 | 450 | * @since 0.5 |
| 500 | 451 | * |
| 501 | - * @param string $old_slug the old language slug | |
| 502 | - * @param string $new_slug optional, the new language slug, if not set it means the correspondent has been deleted | |
| 452 | + * @param string $old_slug The old language slug. | |
| 453 | + * @param string $new_slug Optional, the new language slug, if not set it means that the language has been deleted. | |
| 454 | + * @return void | |
| 503 | 455 | */ |
| 504 | 456 | public function update_translations( $old_slug, $new_slug = '' ) { |
| 505 | 457 | global $wpdb; |
| 506 | 458 | |
| 507 | - $terms = get_terms( array( 'post_translations', 'term_translations' ) ); | |
| 459 | + $terms = get_terms( array( 'taxonomy' => array( 'post_translations', 'term_translations' ) ) ); | |
| 508 | 460 | $term_ids = array(); |
| 509 | 461 | $dr = array(); |
| 510 | 462 | $dt = array(); |
| 511 | 463 | $ut = array(); |
| 512 | 464 | |
| 513 | - foreach ( $terms as $term ) { | |
| 514 | - $term_ids[ $term->taxonomy ][] = $term->term_id; | |
| 515 | - $tr = maybe_unserialize( $term->description ); | |
| 516 | - if ( ! empty( $tr[ $old_slug ] ) ) { | |
| 517 | - if ( $new_slug ) { | |
| 518 | - $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete | |
| 519 | - } else { | |
| 520 | - $dr['id'][] = (int) $tr[ $old_slug ]; | |
| 521 | - $dr['tt'][] = (int) $term->term_taxonomy_id; | |
| 522 | - } | |
| 523 | - unset( $tr[ $old_slug ] ); | |
| 465 | + if ( is_array( $terms ) ) { | |
| 466 | + foreach ( $terms as $term ) { | |
| 467 | + $term_ids[ $term->taxonomy ][] = $term->term_id; | |
| 468 | + $tr = maybe_unserialize( $term->description ); | |
| 524 | 469 | |
| 525 | - if ( empty( $tr ) || 1 == count( $tr ) ) { | |
| 526 | - $dt['t'][] = (int) $term->term_id; | |
| 527 | - $dt['tt'][] = (int) $term->term_taxonomy_id; | |
| 528 | - } else { | |
| 529 | - $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, maybe_serialize( $tr ) ); | |
| 530 | - $ut['in'][] = (int) $term->term_id; | |
| 470 | + /** | |
| 471 | + * Filters the unserialized translation group description before it is | |
| 472 | + * updated when a language is deleted or a language slug is changed. | |
| 473 | + * | |
| 474 | + * @since 3.2 | |
| 475 | + * | |
| 476 | + * @param (int|string[])[] $tr { | |
| 477 | + * List of translations with lang codes as array keys and IDs as array values. | |
| 478 | + * Also in this array: | |
| 479 | + * | |
| 480 | + * @type string[] $sync List of synchronized translations with lang codes as array keys and array values. | |
| 481 | + * } | |
| 482 | + * @param string $old_slug The old language slug. | |
| 483 | + * @param string $new_slug The new language slug. | |
| 484 | + * @param WP_Term $term The term containing the post or term translation group. | |
| 485 | + */ | |
| 486 | + $tr = apply_filters( 'update_translation_group', $tr, $old_slug, $new_slug, $term ); | |
| 487 | + | |
| 488 | + if ( ! empty( $tr[ $old_slug ] ) ) { | |
| 489 | + if ( $new_slug ) { | |
| 490 | + $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete | |
| 491 | + } else { | |
| 492 | + $dr['id'][] = (int) $tr[ $old_slug ]; | |
| 493 | + $dr['tt'][] = (int) $term->term_taxonomy_id; | |
| 494 | + } | |
| 495 | + unset( $tr[ $old_slug ] ); | |
| 496 | + | |
| 497 | + if ( empty( $tr ) || 1 == count( $tr ) ) { | |
| 498 | + $dt['t'][] = (int) $term->term_id; | |
| 499 | + $dt['tt'][] = (int) $term->term_taxonomy_id; | |
| 500 | + } else { | |
| 501 | + $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, maybe_serialize( $tr ) ); | |
| 502 | + $ut['in'][] = (int) $term->term_id; | |
| 503 | + } | |
| 531 | 504 | } |
| 532 | 505 | } |
| 533 | 506 | } |
| 534 | 507 | |
| @@ -568,13 +541,14 @@ | ||
| 568 | 541 | } |
| 569 | 542 | |
| 570 | 543 | /** |
| 571 | 544 | * Updates the default language |
| 572 | - * taking care to update the default category & the nav menu locations | |
| 545 | + * taking care to update the default category & the nav menu locations. | |
| 573 | 546 | * |
| 574 | 547 | * @since 1.8 |
| 575 | 548 | * |
| 576 | - * @param string $slug new language slug | |
| 549 | + * @param string $slug New language slug. | |
| 550 | + * @return void | |
| 577 | 551 | */ |
| 578 | 552 | public function update_default_lang( $slug ) { |
| 579 | 553 | // The nav menus stored in theme locations should be in the default language |
| 580 | 554 | $theme = get_stylesheet(); |
| @@ -586,13 +560,16 @@ | ||
| 586 | 560 | } |
| 587 | 561 | set_theme_mod( 'nav_menu_locations', $menus ); |
| 588 | 562 | } |
| 589 | 563 | |
| 590 | - // The default category should be in the default language | |
| 591 | - $default_cats = $this->term->get_translations( get_option( 'default_category' ) ); | |
| 592 | - if ( isset( $default_cats[ $slug ] ) ) { | |
| 593 | - update_option( 'default_category', $default_cats[ $slug ] ); | |
| 594 | - } | |
| 564 | + /** | |
| 565 | + * Fires when a default language is updated. | |
| 566 | + * | |
| 567 | + * @since 3.1 | |
| 568 | + * | |
| 569 | + * @param string $slug Slug. | |
| 570 | + */ | |
| 571 | + do_action( 'pll_update_default_lang', $slug ); | |
| 595 | 572 | |
| 596 | 573 | // Update options |
| 597 | 574 | $this->options['default_lang'] = $slug; |
| 598 | 575 | update_option( 'polylang', $this->options ); |