PluginProbe
Polylang / 2.3
Polylang v2.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 | install/upgrade.php +34 -83 2.82.3 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages Polylang upgrades
8 5 *
@@ -30,9 +27,9 @@
30 27 public function can_activate() {
31 28 if ( ! $this->can_upgrade() ) {
32 29 ob_start();
33 30 $this->admin_notices(); // FIXME the error message is displayed two times
34 - die( ob_get_contents() ); // phpcs:ignore WordPress.Security.EscapeOutput
31 + die( ob_get_contents() );
35 32 }
36 33 }
37 34
38 35 /**
@@ -72,17 +69,17 @@
72 69 *
73 70 * @since 1.0
74 71 */
75 72 public function admin_notices() {
76 - load_plugin_textdomain( 'polylang' );
73 + load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' );
77 74 printf(
78 75 '<div class="error"><p>%s</p><p>%s</p></div>',
79 76 esc_html__( 'Polylang has been deactivated because you upgraded from a too old version.', 'polylang' ),
80 77 sprintf(
81 78 /* translators: %1$s and %2$s are Polylang version numbers */
82 - esc_html__( 'Before upgrading to %2$s, please upgrade to %1$s.', 'polylang' ),
79 + esc_html__( 'Please upgrade first to %1$s before ugrading to %2$s.', 'polylang' ),
83 80 '<strong>0.9.8</strong>',
84 - POLYLANG_VERSION // phpcs:ignore WordPress.Security.EscapeOutput
81 + POLYLANG_VERSION
85 82 )
86 83 );
87 84 }
88 85
@@ -91,9 +88,9 @@
91 88 *
92 89 * @since 1.2
93 90 */
94 91 public function _upgrade() {
95 - foreach ( array( '0.9', '1.0', '1.1', '1.2', '1.2.1', '1.2.3', '1.3', '1.4', '1.4.1', '1.4.4', '1.5', '1.6', '1.7.4', '1.8', '2.0.8', '2.1', '2.7', '2.8' ) as $version ) {
92 + foreach ( array( '0.9', '1.0', '1.1', '1.2', '1.2.1', '1.2.3', '1.3', '1.4', '1.4.1', '1.4.4', '1.5', '1.6', '1.7.4', '1.8', '2.0.8', '2.1', '2.3' ) as $version ) {
96 93 if ( version_compare( $this->options['version'], $version, '<' ) ) {
97 94 call_user_func( array( $this, 'upgrade_' . str_replace( '.', '_', $version ) ) );
98 95 }
99 96 }
@@ -145,9 +142,9 @@
145 142 protected function upgrade_1_1() {
146 143 // Update strings register with icl_register_string
147 144 $strings = get_option( 'polylang_wpml_strings' );
148 145 if ( $strings ) {
149 - foreach ( array_keys( $strings ) as $key ) {
146 + foreach ( $strings as $key => $string ) {
150 147 $strings[ $key ]['icl'] = 1;
151 148 }
152 149 update_option( 'polylang_wpml_strings', $strings );
153 150 }
@@ -181,15 +178,14 @@
181 178
182 179 // Upgrade old model based on metas to new model based on taxonomies
183 180 global $wpdb;
184 181 $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // Registers the termmeta table in wpdb
185 - $languages = get_terms( 'language', array( 'hide_empty' => 0 ) ); // Don't use get_languages_list which can't work with the old model
186 - $lang_tt_ids = array();
182 + $languages = get_terms( 'language', array( 'hide_empty' => 0 ) ); // Don't use get_languages_list which can't work with the old model
187 183
188 184 foreach ( $languages as $lang ) {
189 185 // First update language with new storage for locale and text direction
190 186 $text_direction = get_metadata( 'term', $lang->term_id, '_rtl', true );
191 - $desc = maybe_serialize( array( 'locale' => $lang->description, 'rtl' => $text_direction ) );
187 + $desc = serialize( array( 'locale' => $lang->description, 'rtl' => $text_direction ) );
192 188 wp_update_term( (int) $lang->term_id, 'language', array( 'description' => $desc ) );
193 189
194 190 // Add language to new 'term_language' taxonomy
195 191 $term_lang = wp_insert_term( $lang->name, 'term_language', array( 'slug' => 'pll_' . $lang->slug ) );
@@ -196,9 +192,9 @@
196 192 $lang_tt_ids[ $lang->term_id ] = $term_lang['term_taxonomy_id']; // Keep the term taxonomy id for future
197 193 }
198 194
199 195 // Get all terms with a language defined
200 - $terms = $wpdb->get_results( "SELECT term_id, meta_value FROM {$wpdb->termmeta} WHERE meta_key = '_language'" );
196 + $terms = $wpdb->get_results( "SELECT term_id, meta_value FROM $wpdb->termmeta WHERE meta_key = '_language'" );
201 197 foreach ( $terms as $key => $term ) {
202 198 $terms[ $key ] = $wpdb->prepare( '( %d, %d )', $term->term_id, $lang_tt_ids[ $term->meta_value ] );
203 199 }
204 200
@@ -205,23 +201,17 @@
205 201 $terms = array_unique( $terms );
206 202
207 203 // Assign language to each term
208 204 if ( ! empty( $terms ) ) {
209 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
210 - $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $terms ) );
205 + $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $terms ) );
211 206 }
212 207
213 208 // Translations
214 209 foreach ( array( 'post', 'term' ) as $type ) {
215 - $table = $type . 'meta';
216 - $terms = array();
217 - $slugs = array();
218 - $tts = array();
219 - $trs = array();
220 - $description = array();
210 + $table = $type . 'meta';
211 + $terms = $slugs = $tts = $trs = array();
221 212
222 213 // Get all translated objects
223 - // PHPCS:ignore WordPress.DB.PreparedSQL
224 214 $objects = $wpdb->get_col( "SELECT DISTINCT meta_value FROM {$wpdb->$table} WHERE meta_key = '_translations'" );
225 215
226 216 if ( empty( $objects ) ) {
227 217 continue;
@@ -230,10 +220,10 @@
230 220 foreach ( $objects as $obj ) {
231 221 $term = uniqid( 'pll_' ); // The term name
232 222 $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term );
233 223 $slugs[] = $wpdb->prepare( '%s', $term );
234 - $translations = maybe_unserialize( maybe_unserialize( $obj ) ); // 2 maybe_unserialize due to an old storage bug
235 - $description[ $term ] = maybe_serialize( $translations );
224 + $translations = maybe_unserialize( maybe_unserialize( $obj ) ); // 2 unserialize due to an old storage bug
225 + $description[ $term ] = serialize( $translations );
236 226 }
237 227
238 228 $terms = array_unique( $terms );
239 229
@@ -238,14 +228,12 @@
238 228 $terms = array_unique( $terms );
239 229
240 230 // Insert terms
241 231 if ( ! empty( $terms ) ) {
242 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
243 - $wpdb->query( "INSERT INTO {$wpdb->terms} ( slug, name ) VALUES " . implode( ',', $terms ) );
232 + $wpdb->query( "INSERT INTO $wpdb->terms ( slug, name ) VALUES " . implode( ',', $terms ) );
244 233 }
245 234
246 235 // Get all terms with their term_id
247 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
248 236 $terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
249 237
250 238 // Prepare terms taxonomy relationship
251 239 foreach ( $terms as $term ) {
@@ -255,10 +243,9 @@
255 243 $tts = array_unique( $tts );
256 244
257 245 // Insert term_taxonomy
258 246 if ( ! empty( $tts ) ) {
259 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
260 - $wpdb->query( "INSERT INTO {$wpdb->term_taxonomy} ( term_id, taxonomy, description ) VALUES " . implode( ',', $tts ) );
247 + $wpdb->query( "INSERT INTO $wpdb->term_taxonomy ( term_id, taxonomy, description ) VALUES " . implode( ',', $tts ) );
261 248 }
262 249
263 250 // Get all terms with term_taxonomy_id
264 251 $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) );
@@ -264,9 +251,9 @@
264 251 $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) );
265 252
266 253 // Prepare objects relationships
267 254 foreach ( $terms as $term ) {
268 - $translations = maybe_unserialize( $term->description );
255 + $translations = unserialize( $term->description );
269 256 foreach ( $translations as $object_id ) {
270 257 if ( ! empty( $object_id ) ) {
271 258 $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
272 259 }
@@ -276,10 +263,9 @@
276 263 $trs = array_unique( $trs );
277 264
278 265 // Insert term_relationships
279 266 if ( ! empty( $trs ) ) {
280 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
281 - $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
267 + $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
282 268 }
283 269 }
284 270
285 271 // Upgrade of string translations is now in upgrade_1_2_1
@@ -314,10 +300,8 @@
314 300 // Old version < 1.1
315 301 // Multilingal locations and switcher item were stored in a dedicated option
316 302 if ( version_compare( $this->options['version'], '1.1', '<' ) ) {
317 303 if ( $menu_lang = get_option( 'polylang_nav_menus' ) ) {
318 - $locations = array();
319 -
320 304 foreach ( $menu_lang as $location => $arr ) {
321 305 if ( ! in_array( $location, array_keys( get_registered_nav_menus() ) ) ) {
322 306 continue;
323 307 }
@@ -333,17 +317,13 @@
333 317 }
334 318
335 319 // Create the menu items for the language switcher
336 320 if ( ! empty( $has_switcher ) ) {
337 - $menu_item_db_id = wp_update_nav_menu_item(
338 - $translations[ $lang->slug ],
339 - 0,
340 - array(
341 - 'menu-item-title' => __( 'Language switcher', 'polylang' ),
342 - 'menu-item-url' => '#pll_switcher',
343 - 'menu-item-status' => 'publish',
344 - )
345 - );
321 + $menu_item_db_id = wp_update_nav_menu_item( $translations[ $lang->slug ], 0, array(
322 + 'menu-item-title' => __( 'Language switcher', 'polylang' ),
323 + 'menu-item-url' => '#pll_switcher',
324 + 'menu-item-status' => 'publish',
325 + ) );
346 326
347 327 update_post_meta( $menu_item_db_id, '_pll_menu_item', $switch_options );
348 328 }
349 329 }
@@ -364,9 +344,9 @@
364 344 // If old version < 1.2
365 345 // Clean the WP option as it was a bad idea to pollute it
366 346 if ( version_compare( $this->options['version'], '1.2', '<' ) ) {
367 347 foreach ( $menus as $loc => $menu ) {
368 - if ( strpos( $loc, '#' ) ) {
348 + if ( $pos = strpos( $loc, '#' ) ) {
369 349 unset( $menus[ $loc ] );
370 350 }
371 351 }
372 352
@@ -507,9 +487,9 @@
507 487 * Rewritten because wp_download_language_pack checks the existence of .mo and I need to download .po
508 488 *
509 489 * @since 1.6
510 490 */
511 - public static function download_language_packs() {
491 + static function download_language_packs() {
512 492 $languages = pll_languages_list( array( 'fields' => 'locale' ) );
513 493
514 494 // Prevents upgrade if the .po file is already here. Let WP manage the upgrades :)
515 495 foreach ( $languages as $key => $locale ) {
@@ -527,10 +507,8 @@
527 507 if ( ! $translations ) {
528 508 return;
529 509 }
530 510
531 - $translations_to_load = array();
532 -
533 511 foreach ( $translations as $translation ) {
534 512 if ( in_array( $translation['language'], $languages ) ) {
535 513 $translation['type'] = 'core';
536 514 $translations_to_load[] = (object) $translation;
@@ -538,9 +516,9 @@
538 516 }
539 517
540 518 if ( ! empty( $translations_to_load ) ) {
541 519 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
542 - $upgrader = new Language_Pack_Upgrader( new Automatic_Upgrader_Skin() );
520 + $upgrader = new Language_Pack_Upgrader( new Automatic_Upgrader_Skin );
543 521 $upgrader->bulk_upgrade( $translations_to_load, array( 'clear_update_cache' => false ) );
544 522 }
545 523 }
546 524
@@ -560,9 +538,9 @@
560 538 * @since 1.8
561 539 */
562 540 protected function upgrade_1_8() {
563 541 // Adds the flag code in languages stored in DB
564 - $languages = include POLYLANG_DIR . '/settings/languages.php';
542 + include PLL_SETTINGS_INC . '/languages.php';
565 543
566 544 $terms = get_terms( 'language', array( 'hide_empty' => 0 ) );
567 545
568 546 foreach ( $terms as $lang ) {
@@ -568,9 +546,9 @@
568 546 foreach ( $terms as $lang ) {
569 547 $description = maybe_unserialize( $lang->description );
570 548 if ( isset( $languages[ $description['locale'] ] ) ) {
571 549 $description['flag_code'] = $languages[ $description['locale'] ]['flag'];
572 - $description = maybe_serialize( $description );
550 + $description = serialize( $description );
573 551 wp_update_term( (int) $lang->term_id, 'language', array( 'description' => $description ) );
574 552 }
575 553 }
576 554
@@ -600,9 +578,9 @@
600 578 $meta = get_post_meta( $mo_id, '_pll_strings_translations', true );
601 579
602 580 if ( empty( $meta ) ) {
603 581 $post = get_post( $mo_id, OBJECT );
604 - $strings = maybe_unserialize( $post->post_content );
582 + $strings = unserialize( $post->post_content );
605 583 if ( is_array( $strings ) ) {
606 584 update_post_meta( $mo_id, '_pll_strings_translations', $strings );
607 585 }
608 586 }
@@ -609,42 +587,15 @@
609 587 }
610 588 }
611 589
612 590 /**
613 - * Upgrades if the previous version is < 2.7
614 - * Replace numeric keys by hashes in WPML registered strings
615 - * Dismiss the wizard notice for existing sites
591 + * Upgrades if the previous version is < 2.3
616 592 *
617 - * @since 2.7
618 - */
619 - protected function upgrade_2_7() {
620 - $strings = get_option( 'polylang_wpml_strings' );
621 - if ( is_array( $strings ) ) {
622 - $new_strings = array();
623 -
624 - foreach ( $strings as $string ) {
625 - $context = $string['context'];
626 - $name = $string['name'];
627 -
628 - $key = md5( "$context | $name" );
629 - $new_strings[ $key ] = $string;
630 - }
631 - update_option( 'polylang_wpml_strings', $new_strings );
632 - }
633 -
634 - PLL_Admin_Notices::dismiss( 'wizard' );
635 - }
636 -
637 - /**
638 - * Upgrades if the previous version is < 2.8
593 + * Deletes language cache due to 'redirect_lang' option removed for subdomains and multiple domains in 2.2
594 + * and W3C and Facebook locales added to PLL_Language objects in 2.3
639 595 *
640 - * Deletes language cache due to:
641 - * - 'redirect_lang' option removed for subdomains and multiple domains in 2.2
642 - * - W3C and Facebook locales added to PLL_Language objects in 2.3
643 - * - flags moved to a different directory in Polylang Pro 2.8
644 - *
645 - * @since 2.8
596 + * @since 2.3
646 597 */
647 - protected function upgrade_2_8() {
598 + protected function upgrade_2_3() {
648 599 delete_transient( 'pll_languages_list' );
649 600 }
650 601 }