PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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 +14 -82 3.0.13.1.4 View file →
@@ -51,13 +51,8 @@
51 51 if ( ! isset( $this->options['default_lang'] ) ) {
52 52 // If this is the first language created, set it as default language
53 53 $this->options['default_lang'] = $args['slug'];
54 54 update_option( 'polylang', $this->options );
55 -
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 55 }
61 56
62 57 // Init a mo_id for this language
63 58 $mo = new PLL_MO();
@@ -234,9 +229,14 @@
234 229
235 230 // And finally update the language itself
236 231 $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
237 232 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'] ) );
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 + }
239 239
240 240 /**
241 241 * Fires when a language is updated.
242 242 *
@@ -431,79 +431,8 @@
431 431 clean_term_cache( $term_ids, $taxonomy );
432 432 }
433 433
434 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 435 * Updates the translations when a language slug has been modified in settings
507 436 * or deletes them when a language is removed.
508 437 *
509 438 * @since 0.5
@@ -600,13 +529,16 @@
600 529 }
601 530 set_theme_mod( 'nav_menu_locations', $menus );
602 531 }
603 532
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 - }
533 + /**
534 + * Fires when a default language is updated.
535 + *
536 + * @since 3.1
537 + *
538 + * @param string $slug Slug.
539 + */
540 + do_action( 'pll_update_default_lang', $slug );
609 541
610 542 // Update options
611 543 $this->options['default_lang'] = $slug;
612 544 update_option( 'polylang', $this->options );