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