PluginProbe
Polylang / 2.6.2
Polylang v2.6.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 +9 -27 2.92.6.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Extends the PLL_Model class with methods needed only in Polylang settings pages
8 5 *
@@ -127,9 +124,9 @@
127 124
128 125 // Delete menus locations
129 126 if ( ! empty( $this->options['nav_menus'] ) ) {
130 127 foreach ( $this->options['nav_menus'] as $theme => $locations ) {
131 - foreach ( array_keys( $locations ) as $location ) {
128 + foreach ( $locations as $location => $languages ) {
132 129 unset( $this->options['nav_menus'][ $theme ][ $location ][ $lang->slug ] );
133 130 }
134 131 }
135 132 }
@@ -213,9 +210,9 @@
213 210
214 211 // Update menus locations
215 212 if ( ! empty( $this->options['nav_menus'] ) ) {
216 213 foreach ( $this->options['nav_menus'] as $theme => $locations ) {
217 - foreach ( array_keys( $locations ) as $location ) {
214 + foreach ( $locations as $location => $languages ) {
218 215 if ( ! empty( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] ) ) {
219 216 $this->options['nav_menus'][ $theme ][ $location ][ $slug ] = $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ];
220 217 unset( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] );
221 218 }
@@ -258,9 +255,9 @@
258 255
259 256 /**
260 257 * Validates data entered when creating or updating a language
261 258 *
262 - * @see PLL_Admin_Model::add_language()
259 + * @see PLL_Admin_Model::add_language
263 260 *
264 261 * @since 0.4
265 262 *
266 263 * @param array $args
@@ -320,12 +317,11 @@
320 317 */
321 318 public function set_language_in_mass( $type, $ids, $lang ) {
322 319 global $wpdb;
323 320
324 - $ids = array_map( 'intval', $ids );
325 - $lang = $this->get_language( $lang );
326 - $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
327 - $values = array();
321 + $ids = array_map( 'intval', $ids );
322 + $lang = $this->get_language( $lang );
323 + $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
328 324
329 325 foreach ( $ids as $id ) {
330 326 $values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id );
331 327 }
@@ -337,9 +333,8 @@
337 333 }
338 334
339 335 if ( 'term' === $type ) {
340 336 clean_term_cache( $ids, 'term_language' );
341 - $translations = array();
342 337
343 338 foreach ( $ids as $id ) {
344 339 $translations[] = array( $lang->slug => $id );
345 340 }
@@ -362,13 +357,9 @@
362 357 */
363 358 public function set_translation_in_mass( $type, $translations ) {
364 359 global $wpdb;
365 360
366 - $taxonomy = $type . '_translations';
367 - $terms = array();
368 - $slugs = array();
369 - $description = array();
370 - $count = array();
361 + $taxonomy = $type . '_translations';
371 362
372 363 foreach ( $translations as $t ) {
373 364 $term = uniqid( 'pll_' ); // the term name
374 365 $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term );
@@ -384,11 +375,9 @@
384 375 }
385 376
386 377 // Get all terms with their term_id
387 378 // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
388 - $terms = $wpdb->get_results( "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
389 - $term_ids = array();
390 - $tts = array();
379 + $terms = $wpdb->get_results( "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
391 380
392 381 // Prepare terms taxonomy relationship
393 382 foreach ( $terms as $term ) {
394 383 $term_ids[] = $term->term_id;
@@ -402,9 +391,8 @@
402 391 }
403 392
404 393 // Get all terms with term_taxonomy_id
405 394 $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
406 - $trs = array();
407 395
408 396 // Prepare objects relationships
409 397 foreach ( $terms as $term ) {
410 398 $t = maybe_unserialize( $term->description );
@@ -503,13 +491,9 @@
503 491 */
504 492 public function update_translations( $old_slug, $new_slug = '' ) {
505 493 global $wpdb;
506 494
507 - $terms = get_terms( array( 'post_translations', 'term_translations' ) );
508 - $term_ids = array();
509 - $dr = array();
510 - $dt = array();
511 - $ut = array();
495 + $terms = get_terms( array( 'post_translations', 'term_translations' ) );
512 496
513 497 foreach ( $terms as $term ) {
514 498 $term_ids[ $term->taxonomy ][] = $term->term_id;
515 499 $tr = maybe_unserialize( $term->description );
@@ -578,10 +562,8 @@
578 562 public function update_default_lang( $slug ) {
579 563 // The nav menus stored in theme locations should be in the default language
580 564 $theme = get_stylesheet();
581 565 if ( ! empty( $this->options['nav_menus'][ $theme ] ) ) {
582 - $menus = array();
583 -
584 566 foreach ( $this->options['nav_menus'][ $theme ] as $key => $loc ) {
585 567 $menus[ $key ] = empty( $loc[ $slug ] ) ? 0 : $loc[ $slug ];
586 568 }
587 569 set_theme_mod( 'nav_menu_locations', $menus );