PluginProbe
Polylang / 2.0.3
Polylang v2.0.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-model.php +81 -161 2.92.0.3 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 *
@@ -30,19 +27,19 @@
30 27 * @param array $args
31 28 * @return bool true if success / false if failed
32 29 */
33 30 public function add_language( $args ) {
34 - $errors = $this->validate_lang( $args );
35 - if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0
36 - return $errors;
31 + if ( ! $this->validate_lang( $args ) ) {
32 + return false;
37 33 }
38 34
39 35 // First the language taxonomy
40 - $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'] ) );
41 37 $r = wp_insert_term( $args['name'], 'language', array( 'slug' => $args['slug'], 'description' => $description ) );
42 38 if ( is_wp_error( $r ) ) {
43 39 // Avoid an ugly fatal error if something went wrong ( reported once in the forum )
44 - 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;
45 42 }
46 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
47 44
48 45 // The term_language taxonomy
@@ -48,9 +45,9 @@
48 45 // The term_language taxonomy
49 46 // Don't want shared terms so use a different slug
50 47 wp_insert_term( $args['name'], 'term_language', array( 'slug' => 'pll_' . $args['slug'] ) );
51 48
52 - $this->clean_languages_cache(); // Update the languages list now !
49 + $this->clean_languages_cache(); // Udpate the languages list now !
53 50
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'];
@@ -76,8 +73,10 @@
76 73 do_action( 'pll_add_language', $args );
77 74
78 75 $this->clean_languages_cache(); // Again to set add mo_id in the cached languages list
79 76 flush_rewrite_rules(); // Refresh rewrite rules
77 +
78 + add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
80 79 return true;
81 80 }
82 81
83 82 /**
@@ -89,12 +88,8 @@
89 88 */
90 89 public function delete_language( $lang_id ) {
91 90 $lang = $this->get_language( (int) $lang_id );
92 91
93 - if ( empty( $lang ) ) {
94 - return false;
95 - }
96 -
97 92 // Oops ! we are deleting the default language...
98 93 // Need to do this before loosing the information for default category translations
99 94 if ( $this->options['default_lang'] == $lang->slug ) {
100 95 $slugs = $this->get_languages_list( array( 'fields' => 'slug' ) );
@@ -127,9 +122,9 @@
127 122
128 123 // Delete menus locations
129 124 if ( ! empty( $this->options['nav_menus'] ) ) {
130 125 foreach ( $this->options['nav_menus'] as $theme => $locations ) {
131 - foreach ( array_keys( $locations ) as $location ) {
126 + foreach ( $locations as $location => $languages ) {
132 127 unset( $this->options['nav_menus'][ $theme ][ $location ][ $lang->slug ] );
133 128 }
134 129 }
135 130 }
@@ -135,10 +130,11 @@
135 130 }
136 131
137 132 // Delete users options
138 133 foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
134 + delete_user_meta( $user_id, 'user_lang', $lang->locale );
139 135 delete_user_meta( $user_id, 'pll_filter_content', $lang->slug );
140 - delete_user_meta( $user_id, 'description_' . $lang->slug );
136 + delete_user_meta( $user_id, 'description_'.$lang->slug );
141 137 }
142 138
143 139 // Delete the string translations
144 140 $post = wpcom_vip_get_page_by_title( 'polylang_mo_' . $lang->term_id, OBJECT, 'polylang_mo' );
@@ -157,9 +153,9 @@
157 153 $this->clean_languages_cache();
158 154
159 155 update_option( 'polylang', $this->options );
160 156 flush_rewrite_rules(); // refresh rewrite rules
161 - return true;
157 + add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
162 158 }
163 159
164 160 /**
165 161 * Update language properties
@@ -181,12 +177,10 @@
181 177 * @return bool true if success / false if failed
182 178 */
183 179 public function update_language( $args ) {
184 180 $lang = $this->get_language( (int) $args['lang_id'] );
185 -
186 - $errors = $this->validate_lang( $args, $lang );
187 - if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0
188 - return $errors;
181 + if ( ! $this->validate_lang( $args, $lang ) ) {
182 + return false;
189 183 }
190 184
191 185 // Update links to this language in posts and terms in case the slug has been modified
192 186 $slug = $args['slug'];
@@ -213,9 +207,9 @@
213 207
214 208 // Update menus locations
215 209 if ( ! empty( $this->options['nav_menus'] ) ) {
216 210 foreach ( $this->options['nav_menus'] as $theme => $locations ) {
217 - foreach ( array_keys( $locations ) as $location ) {
211 + foreach ( $locations as $location => $languages ) {
218 212 if ( ! empty( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] ) ) {
219 213 $this->options['nav_menus'][ $theme ][ $location ][ $slug ] = $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ];
220 214 unset( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] );
221 215 }
@@ -237,9 +231,9 @@
237 231
238 232 update_option( 'polylang', $this->options );
239 233
240 234 // And finally update the language itself
241 - $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
235 + $description = serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
242 236 wp_update_term( (int) $lang->term_id, 'language', array( 'slug' => $slug, 'name' => $args['name'], 'description' => $description, 'term_group' => (int) $args['term_group'] ) );
243 237 wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) );
244 238
245 239 /**
@@ -252,16 +246,16 @@
252 246 do_action( 'pll_update_language', $args );
253 247
254 248 $this->clean_languages_cache();
255 249 flush_rewrite_rules(); // Refresh rewrite rules
250 + add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' );
256 251 return true;
257 252 }
258 253
259 254 /**
260 255 * Validates data entered when creating or updating a language
256 + * @see PLL_Admin_Model::add_language
261 257 *
262 - * @see PLL_Admin_Model::add_language()
263 - *
264 258 * @since 0.4
265 259 *
266 260 * @param array $args
267 261 * @param object $lang optional the language currently updated, the language is created if not set
@@ -267,47 +261,35 @@
267 261 * @param object $lang optional the language currently updated, the language is created if not set
268 262 * @return bool true if success / false if failed
269 263 */
270 264 protected function validate_lang( $args, $lang = null ) {
271 - $errors = new WP_Error();
272 -
273 265 // Validate locale with the same pattern as WP 4.3. See #28303
274 266 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' ) );
267 + add_settings_error( 'general', 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) );
276 268 }
277 269
278 270 // Validate slug characters
279 271 if ( ! preg_match( '#^[a-z_-]+$#', $args['slug'] ) ) {
280 - $errors->add( 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) );
272 + add_settings_error( 'general', 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) );
281 273 }
282 274
283 275 // Validate slug is unique
284 - foreach ( $this->get_languages_list() as $language ) {
285 - if ( $language->slug === $args['slug'] && ( null === $lang || ( isset( $lang ) && $lang->term_id != $language->term_id ) ) ) {
286 - $errors->add( 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) );
287 - }
276 + if ( $this->get_language( $args['slug'] ) && ( null === $lang || ( isset( $lang ) && $lang->slug != $args['slug'] ) ) ) {
277 + add_settings_error( 'general', 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) );
288 278 }
289 279
290 280 // Validate name
291 281 // No need to sanitize it as wp_insert_term will do it for us
292 282 if ( empty( $args['name'] ) ) {
293 - $errors->add( 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) );
283 + add_settings_error( 'general', 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) );
294 284 }
295 285
296 286 // Validate flag
297 287 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 - }
288 + add_settings_error( 'general', 'pll_invalid_flag', __( 'The flag does not exist', 'polylang' ) );
307 289 }
308 290
309 - return $errors;
291 + return get_settings_errors() ? false : true;
310 292 }
311 293
312 294 /**
313 295 * Used to set the language of posts or terms in mass
@@ -320,12 +302,11 @@
320 302 */
321 303 public function set_language_in_mass( $type, $ids, $lang ) {
322 304 global $wpdb;
323 305
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();
306 + $ids = array_map( 'intval', $ids );
307 + $lang = $this->get_language( $lang );
308 + $tt_id = 'term' == $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
328 309
329 310 foreach ( $ids as $id ) {
330 311 $values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id );
331 312 }
@@ -330,17 +311,14 @@
330 311 $values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id );
331 312 }
332 313
333 314 if ( ! empty( $values ) ) {
334 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
335 - $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', array_unique( $values ) ) );
315 + $values = array_unique( $values );
316 + $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $values ) );
336 317 $lang->update_count(); // Updating term count is mandatory ( thanks to AndyDeGroo )
337 318 }
338 319
339 - if ( 'term' === $type ) {
340 - clean_term_cache( $ids, 'term_language' );
341 - $translations = array();
342 -
320 + if ( 'term' == $type ) {
343 321 foreach ( $ids as $id ) {
344 322 $translations[] = array( $lang->slug => $id );
345 323 }
346 324
@@ -346,10 +324,8 @@
346 324
347 325 if ( ! empty( $translations ) ) {
348 326 $this->set_translation_in_mass( 'term', $translations );
349 327 }
350 - } else {
351 - clean_term_cache( $ids, 'language' );
352 328 }
353 329 }
354 330
355 331 /**
@@ -362,53 +338,42 @@
362 338 */
363 339 public function set_translation_in_mass( $type, $translations ) {
364 340 global $wpdb;
365 341
366 - $taxonomy = $type . '_translations';
367 - $terms = array();
368 - $slugs = array();
369 - $description = array();
370 - $count = array();
371 -
372 342 foreach ( $translations as $t ) {
373 343 $term = uniqid( 'pll_' ); // the term name
374 - $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term );
375 - $slugs[] = $wpdb->prepare( '%s', $term );
376 - $description[ $term ] = maybe_serialize( $t );
344 + $terms[] = $wpdb->prepare( '( "%1$s", "%1$s" )', $term );
345 + $slugs[] = $wpdb->prepare( '"%s"', $term );
346 + $description[ $term ] = serialize( $t );
377 347 $count[ $term ] = count( $t );
378 348 }
379 349
380 350 // Insert terms
381 351 if ( ! empty( $terms ) ) {
382 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
383 - $wpdb->query( "INSERT INTO {$wpdb->terms} ( slug, name ) VALUES " . implode( ',', array_unique( $terms ) ) );
352 + $terms = array_unique( $terms );
353 + $wpdb->query( "INSERT INTO $wpdb->terms ( slug, name ) VALUES " . implode( ',', $terms ) );
384 354 }
385 355
386 356 // Get all terms with their term_id
387 - // 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();
357 + $terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug IN ( " . implode( ',', $slugs ) . " )" );
391 358
392 359 // Prepare terms taxonomy relationship
393 360 foreach ( $terms as $term ) {
394 - $term_ids[] = $term->term_id;
395 - $tts[] = $wpdb->prepare( '( %d, %s, %s, %d )', $term->term_id, $taxonomy, $description[ $term->slug ], $count[ $term->slug ] );
361 + $tts[] = $wpdb->prepare( '( %d, "%s", "%s", %d )', $term->term_id, $type . '_translations', $description[ $term->slug ], $count[ $term->slug ] );
396 362 }
397 363
398 364 // Insert term_taxonomy
399 365 if ( ! empty( $tts ) ) {
400 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
401 - $wpdb->query( "INSERT INTO {$wpdb->term_taxonomy} ( term_id, taxonomy, description, count ) VALUES " . implode( ',', array_unique( $tts ) ) );
366 + $tts = array_unique( $tts );
367 + $wpdb->query( "INSERT INTO $wpdb->term_taxonomy ( term_id, taxonomy, description, count ) VALUES " . implode( ',', $tts ) );
402 368 }
403 369
404 370 // Get all terms with term_taxonomy_id
405 - $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
406 - $trs = array();
371 + $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) );
407 372
408 373 // Prepare objects relationships
409 374 foreach ( $terms as $term ) {
410 - $t = maybe_unserialize( $term->description );
375 + $t = unserialize( $term->description );
411 376 if ( in_array( $t, $translations ) ) {
412 377 foreach ( $t as $object_id ) {
413 378 if ( ! empty( $object_id ) ) {
414 379 $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
@@ -418,72 +383,40 @@
418 383 }
419 384
420 385 // Insert term_relationships
421 386 if ( ! empty( $trs ) ) {
422 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
423 - $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
387 + $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
424 388 $trs = array_unique( $trs );
425 389 }
426 -
427 - clean_term_cache( $term_ids, $taxonomy );
428 390 }
429 391
430 392 /**
431 - * Returns untranslated posts and terms ids ( used in settings )
393 + * Returns unstranslated posts and terms ids ( used in settings )
432 394 *
433 395 * @since 0.9
434 - * @since 2.2.6 Add the $limit argument
435 396 *
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
397 + * @return array array made of an array of post ids and an array of term ids
438 398 */
439 - public function get_objects_with_no_lang( $limit = -1 ) {
440 - global $wpdb;
399 + public function get_objects_with_no_lang() {
400 + $posts = get_posts( array(
401 + 'numberposts' => -1,
402 + 'nopaging' => true,
403 + 'post_type' => $this->get_translated_post_types(),
404 + 'post_status' => 'any',
405 + 'fields' => 'ids',
406 + 'tax_query' => array( array(
407 + 'taxonomy' => 'language',
408 + 'terms' => $this->get_languages_list( array( 'fields' => 'term_id' ) ),
409 + 'operator' => 'NOT IN',
410 + ) )
411 + ) );
441 412
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 );
413 + $terms = get_terms( $this->get_translated_taxonomies(), array( 'get' => 'all', 'fields' => 'ids' ) );
414 + $groups = $this->get_languages_list( array( 'fields' => 'tl_term_id' ) );
415 + $tr_terms = get_objects_in_term( $groups, 'term_language' );
416 + $terms = array_unique( array_diff( $terms, $tr_terms ) ); // array_unique to avoid duplicates if a term is in more than one taxonomy
417 + $terms = array_map( 'intval', $terms );
452 418
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 419 /**
487 420 * Filter the list of untranslated posts ids and terms ids
488 421 *
489 422 * @since 0.9
@@ -498,22 +431,17 @@
498 431 *
499 432 * @since 0.5
500 433 *
501 434 * @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
435 + * @param string $new_slug optional, the new language slug, if not set it means the correspondant has been deleted
503 436 */
504 437 public function update_translations( $old_slug, $new_slug = '' ) {
505 438 global $wpdb;
506 439
507 - $terms = get_terms( array( 'post_translations', 'term_translations' ) );
508 - $term_ids = array();
509 - $dr = array();
510 - $dt = array();
511 - $ut = array();
440 + $terms = get_terms( array( 'post_translations', 'term_translations' ) );
512 441
513 442 foreach ( $terms as $term ) {
514 - $term_ids[ $term->taxonomy ][] = $term->term_id;
515 - $tr = maybe_unserialize( $term->description );
443 + $tr = unserialize( $term->description );
516 444 if ( ! empty( $tr[ $old_slug ] ) ) {
517 445 if ( $new_slug ) {
518 446 $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete
519 447 } else {
@@ -525,9 +453,9 @@
525 453 if ( empty( $tr ) || 1 == count( $tr ) ) {
526 454 $dt['t'][] = (int) $term->term_id;
527 455 $dt['tt'][] = (int) $term->term_taxonomy_id;
528 456 } else {
529 - $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, maybe_serialize( $tr ) );
457 + $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, serialize( $tr ) );
530 458 $ut['in'][] = (int) $term->term_id;
531 459 }
532 460 }
533 461 }
@@ -533,38 +461,32 @@
533 461 }
534 462
535 463 // Delete relationships
536 464 if ( ! empty( $dr ) ) {
537 - // PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared
538 - $wpdb->query(
539 - "DELETE FROM $wpdb->term_relationships
540 - WHERE object_id IN ( " . implode( ',', $dr['id'] ) . ' )
541 - AND term_taxonomy_id IN ( ' . implode( ',', $dr['tt'] ) . ' )'
542 - );
543 - // PHPCS:enable
465 + $wpdb->query( "
466 + DELETE FROM $wpdb->term_relationships
467 + WHERE object_id IN ( " . implode( ',', $dr['id'] ) . " )
468 + AND term_taxonomy_id IN ( " . implode( ',', $dr['tt'] ) . " )
469 + " );
544 470 }
545 471
546 472 // Delete terms
547 473 if ( ! empty( $dt ) ) {
548 - $wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $dt['t'] ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
549 - $wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ( " . implode( ',', $dt['tt'] ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
474 + $wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $dt['t'] ) . " ) " );
475 + $wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ( " . implode( ',', $dt['tt'] ) . " ) " );
550 476 }
551 477
552 478 // Update terms
553 479 if ( ! empty( $ut ) ) {
554 - // PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared
555 - $wpdb->query(
556 - "UPDATE $wpdb->term_taxonomy
557 - SET description = ( CASE term_id " . implode( ' ', $ut['case'] ) . ' END )
558 - WHERE term_id IN ( ' . implode( ',', $ut['in'] ) . ' )'
559 - );
560 - // PHPCS:enable
480 + $wpdb->query( "
481 + UPDATE $wpdb->term_taxonomy
482 + SET description = ( CASE term_id " . implode( ' ', $ut['case'] ) . " END )
483 + WHERE term_id IN ( " . implode( ',', $ut['in'] ) . " )
484 + " );
561 485 }
562 486
563 - if ( ! empty( $term_ids ) ) {
564 - foreach ( $term_ids as $taxonomy => $ids ) {
565 - clean_term_cache( $ids, $taxonomy );
566 - }
487 + foreach ( $terms as $term ) {
488 + clean_term_cache( $term->term_id, $term->taxonomy );
567 489 }
568 490 }
569 491
570 492 /**
@@ -578,10 +500,8 @@
578 500 public function update_default_lang( $slug ) {
579 501 // The nav menus stored in theme locations should be in the default language
580 502 $theme = get_stylesheet();
581 503 if ( ! empty( $this->options['nav_menus'][ $theme ] ) ) {
582 - $menus = array();
583 -
584 504 foreach ( $this->options['nav_menus'][ $theme ] as $key => $loc ) {
585 505 $menus[ $key ] = empty( $loc[ $slug ] ) ? 0 : $loc[ $slug ];
586 506 }
587 507 set_theme_mod( 'nav_menu_locations', $menus );