PluginProbe
Polylang / 2.6.3
Polylang v2.6.3
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-filters-term.php +32 -52 2.92.6.3 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages filters and actions related to terms on admin side
8 5 *
@@ -81,9 +78,8 @@
81 78 $dropdown = new PLL_Walker_Dropdown();
82 79
83 80 $dropdown_html = $dropdown->walk(
84 81 $this->model->get_languages_list(),
85 - -1,
86 82 array(
87 83 'name' => 'term_lang_choice',
88 84 'value' => 'term_id',
89 85 'selected' => $lang ? $lang->term_id : '',
@@ -110,9 +106,9 @@
110 106
111 107 // Adds translation fields
112 108 echo '<div id="term-translations" class="form-field">';
113 109 if ( $lang ) {
114 - include __DIR__ . '/view-translations-term.php';
110 + include PLL_ADMIN_INC . '/view-translations-term.php';
115 111 }
116 112 echo '</div>' . "\n";
117 113 }
118 114
@@ -135,10 +131,10 @@
135 131 if ( ! post_type_exists( $post_type ) ) {
136 132 return;
137 133 }
138 134
139 - $term_id = $tag->term_id;
140 - $taxonomy = $tag->taxonomy; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
135 + $term_id = $tag->term_id;
136 + $taxonomy = $tag->taxonomy;
141 137
142 138 $lang = $this->model->term->get_language( $term_id );
143 139 $lang = empty( $lang ) ? $this->pref_lang : $lang;
144 140
@@ -148,9 +144,8 @@
148 144 $dropdown = new PLL_Walker_Dropdown();
149 145
150 146 $dropdown_html = $dropdown->walk(
151 147 $this->model->get_languages_list(),
152 - -1,
153 148 array(
154 149 'name' => 'term_lang_choice',
155 150 'value' => 'term_id',
156 151 'selected' => $lang ? $lang->term_id : '',
@@ -177,9 +172,9 @@
177 172 );
178 173
179 174 echo '<tr id="term-translations" class="form-field">';
180 175 if ( $lang ) {
181 - include __DIR__ . '/view-translations-term.php';
176 + include PLL_ADMIN_INC . '/view-translations-term.php';
182 177 }
183 178 echo '</tr>' . "\n";
184 179 }
185 180
@@ -273,12 +268,10 @@
273 268 );
274 269
275 270 // If we have several terms with the same name, they are translations of each other
276 271 if ( count( $terms ) > 1 ) {
277 - $translations = array();
278 -
279 272 foreach ( $terms as $term ) {
280 - $translations[ $this->model->term->get_language( $term->term_id )->slug ] = $term->term_id;
273 + $translations[ $this->model->term->get_language( $term->term_id )->slug ] = $term->term_id;
281 274 }
282 275
283 276 $this->model->term->save_translations( $term_id, $translations );
284 277 }
@@ -372,9 +365,9 @@
372 365 if ( current_user_can( $tax->cap->edit_terms ) || ( isset( $_POST['tax_input'][ $taxonomy ] ) && current_user_can( $tax->cap->assign_terms ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
373 366 $this->save_language( $term_id, $taxonomy );
374 367
375 368 if ( isset( $_POST['term_tr_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
376 - $this->save_translations( $term_id );
369 + $translations = $this->save_translations( $term_id );
377 370 }
378 371 }
379 372 }
380 373
@@ -404,13 +397,13 @@
404 397
405 398 // If the term already exists in another language
406 399 if ( ! $slug && $this->model->is_translated_taxonomy( $taxonomy ) && term_exists( $name, $taxonomy ) ) {
407 400 if ( isset( $_POST['term_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
408 - $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
401 + $slug = $name . '-' . $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) )->slug; // phpcs:ignore WordPress.Security.NonceVerification
409 402 }
410 403
411 404 elseif ( isset( $_POST['inline_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
412 - $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
405 + $slug = $name . '-' . $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) )->slug; // phpcs:ignore WordPress.Security.NonceVerification
413 406 }
414 407
415 408 // *Post* bulk edit, in case a new term is created
416 409 elseif ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
@@ -415,17 +408,13 @@
415 408 // *Post* bulk edit, in case a new term is created
416 409 elseif ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
417 410 // Bulk edit does not modify the language
418 411 if ( -1 == $_GET['inline_lang_choice'] ) { // phpcs:ignore WordPress.Security.NonceVerification
419 - $lang = $this->model->post->get_language( $this->post_id );
412 + $slug = $name . '-' . $this->model->post->get_language( $this->post_id )->slug;
420 413 } else {
421 - $lang = $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
414 + $slug = $name . '-' . $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) )->slug; // phpcs:ignore WordPress.Security.NonceVerification
422 415 }
423 416 }
424 -
425 - if ( ! empty( $lang ) && ! $this->model->term_exists_by_slug( $name, $lang, $taxonomy ) ) {
426 - $slug = $name . '-' . $lang->slug;
427 - }
428 417 }
429 418
430 419 return $slug;
431 420 }
@@ -441,11 +430,11 @@
441 430 if ( ! isset( $_POST['taxonomy'], $_POST['post_type'], $_POST['lang'] ) ) {
442 431 wp_die( 0 );
443 432 }
444 433
445 - $lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) );
446 - $term_id = isset( $_POST['term_id'] ) ? (int) $_POST['term_id'] : null; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
447 - $taxonomy = sanitize_key( $_POST['taxonomy'] );
434 + $lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) );
435 + $term_id = isset( $_POST['term_id'] ) ? (int) $_POST['term_id'] : null;
436 + $taxonomy = sanitize_key( $_POST['taxonomy'] );
448 437 $post_type = sanitize_key( $_POST['post_type'] );
449 438
450 439 if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
451 440 wp_die( 0 );
@@ -452,9 +441,9 @@
452 441 }
453 442
454 443 ob_start();
455 444 if ( $lang ) {
456 - include __DIR__ . '/view-translations-term.php';
445 + include PLL_ADMIN_INC . '/view-translations-term.php';
457 446 }
458 447 $x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) );
459 448 ob_end_clean();
460 449
@@ -510,9 +499,9 @@
510 499 }
511 500
512 501 $s = wp_unslash( $_GET['term'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
513 502 $post_type = sanitize_key( $_GET['post_type'] );
514 - $taxonomy = sanitize_key( $_GET['taxonomy'] );
503 + $taxonomy = sanitize_key( $_GET['taxonomy'] );
515 504
516 505 if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
517 506 wp_die( 0 );
518 507 }
@@ -519,42 +508,34 @@
519 508
520 509 $term_language = $this->model->get_language( sanitize_key( $_GET['term_language'] ) );
521 510 $translation_language = $this->model->get_language( sanitize_key( $_GET['translation_language'] ) );
522 511
523 - $terms = array();
524 512 $return = array();
525 513
526 - // Add current translation in list.
527 - // Not in add term as term_id is not set.
528 - if ( isset( $_GET['term_id'] ) && 'undefined' !== $_GET['term_id'] && $term_id = $this->model->term->get_translation( (int) $_GET['term_id'], $translation_language ) ) {
529 - $terms = array( get_term( $term_id, $taxonomy ) );
530 - }
531 -
532 - // It is more efficient to use one common query for all languages as soon as there are more than 2.
514 + // It is more efficient to use one common query for all languages as soon as there are more than 2
533 515 foreach ( get_terms( $taxonomy, 'hide_empty=0&lang=0&name__like=' . $s ) as $term ) {
534 516 $lang = $this->model->term->get_language( $term->term_id );
535 517
536 518 if ( $lang && $lang->slug == $translation_language->slug && ! $this->model->term->get_translation( $term->term_id, $term_language ) ) {
537 - $terms[] = $term;
519 + $return[] = array(
520 + 'id' => $term->term_id,
521 + 'value' => $term->name,
522 + 'link' => $this->links->edit_term_translation_link( $term->term_id, $taxonomy, $post_type ),
523 + );
538 524 }
539 525 }
540 526
541 - // Format the ajax response.
542 - foreach ( $terms as $term ) {
543 - $return[] = array(
544 - 'id' => $term->term_id,
545 - 'value' => rtrim( // Trim the seperator added at the end by WP.
546 - get_term_parents_list(
547 - $term->term_id,
548 - $term->taxonomy,
549 - array(
550 - 'separator' => ' > ',
551 - 'link' => false,
552 - )
553 - ),
554 - ' >'
555 - ),
556 - 'link' => $this->links->edit_term_translation_link( $term->term_id, $term->taxonomy, $post_type ),
527 + // Add current translation in list
528 + // Not in add term as term_id is not set
529 + if ( isset( $_GET['term_id'] ) && 'undefined' !== $_GET['term_id'] && $term_id = $this->model->term->get_translation( (int) $_GET['term_id'], $translation_language ) ) {
530 + $term = get_term( $term_id, $taxonomy );
531 + array_unshift(
532 + $return,
533 + array(
534 + 'id' => $term_id,
535 + 'value' => $term->name,
536 + 'link' => $this->links->edit_term_translation_link( $term->term_id, $taxonomy, $post_type ),
537 + )
557 538 );
558 539 }
559 540
560 541 wp_die( wp_json_encode( $return ) );
@@ -623,9 +604,8 @@
623 604 }
624 605
625 606 $avoid_recursion = true;
626 607 $lang = $this->model->term->get_language( $term_id );
627 - $translations = array();
628 608
629 609 foreach ( $this->model->term->get_translations( $term_id ) as $key => $tr_id ) {
630 610 if ( $lang->slug == $key ) {
631 611 $translations[ $key ] = $new_term_id;