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 +37 -122 2.9.12.0.12 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 *
@@ -14,10 +11,8 @@
14 11 /**
15 12 * Constructor
16 13 *
17 14 * @since 1.2
18 - *
19 - * @param array $options Polylang options
20 15 */
21 16 public function __construct( &$options ) {
22 17 $this->options = &$options;
23 18 }
@@ -30,9 +25,9 @@
30 25 public function can_activate() {
31 26 if ( ! $this->can_upgrade() ) {
32 27 ob_start();
33 28 $this->admin_notices(); // FIXME the error message is displayed two times
34 - die( ob_get_contents() ); // phpcs:ignore WordPress.Security.EscapeOutput
29 + die( ob_get_contents() );
35 30 }
36 31 }
37 32
38 33 /**
@@ -72,17 +67,17 @@
72 67 *
73 68 * @since 1.0
74 69 */
75 70 public function admin_notices() {
76 - load_plugin_textdomain( 'polylang' );
71 + load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' );
77 72 printf(
78 73 '<div class="error"><p>%s</p><p>%s</p></div>',
79 74 esc_html__( 'Polylang has been deactivated because you upgraded from a too old version.', 'polylang' ),
80 75 sprintf(
81 - /* translators: %1$s and %2$s are Polylang version numbers */
82 - 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' ),
83 78 '<strong>0.9.8</strong>',
84 - POLYLANG_VERSION // phpcs:ignore WordPress.Security.EscapeOutput
79 + POLYLANG_VERSION
85 80 )
86 81 );
87 82 }
88 83
@@ -91,9 +86,9 @@
91 86 *
92 87 * @since 1.2
93 88 */
94 89 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.1' ) 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 ) {
96 91 if ( version_compare( $this->options['version'], $version, '<' ) ) {
97 92 call_user_func( array( $this, 'upgrade_' . str_replace( '.', '_', $version ) ) );
98 93 }
99 94 }
@@ -145,9 +140,9 @@
145 140 protected function upgrade_1_1() {
146 141 // Update strings register with icl_register_string
147 142 $strings = get_option( 'polylang_wpml_strings' );
148 143 if ( $strings ) {
149 - foreach ( array_keys( $strings ) as $key ) {
144 + foreach ( $strings as $key => $string ) {
150 145 $strings[ $key ]['icl'] = 1;
151 146 }
152 147 update_option( 'polylang_wpml_strings', $strings );
153 148 }
@@ -168,9 +163,9 @@
168 163 $this->options['domains'] = array(); // Option added in 1.2
169 164
170 165 // Need to register the taxonomies
171 166 foreach ( array( 'language', 'term_language', 'post_translations', 'term_translations' ) as $taxonomy ) {
172 - 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 ) );
173 168 }
174 169
175 170 // Abort if the db upgrade has already been done previously
176 171 if ( get_terms( 'term_language', array( 'hide_empty' => 0 ) ) ) {
@@ -181,15 +176,14 @@
181 176
182 177 // Upgrade old model based on metas to new model based on taxonomies
183 178 global $wpdb;
184 179 $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();
180 + $languages = get_terms( 'language', array( 'hide_empty' => 0 ) ); // Don't use get_languages_list which can't work with the old model
187 181
188 182 foreach ( $languages as $lang ) {
189 183 // First update language with new storage for locale and text direction
190 184 $text_direction = get_metadata( 'term', $lang->term_id, '_rtl', true );
191 - $desc = maybe_serialize( array( 'locale' => $lang->description, 'rtl' => $text_direction ) );
185 + $desc = serialize( array( 'locale' => $lang->description, 'rtl' => $text_direction ) );
192 186 wp_update_term( (int) $lang->term_id, 'language', array( 'description' => $desc ) );
193 187
194 188 // Add language to new 'term_language' taxonomy
195 189 $term_lang = wp_insert_term( $lang->name, 'term_language', array( 'slug' => 'pll_' . $lang->slug ) );
@@ -196,9 +190,9 @@
196 190 $lang_tt_ids[ $lang->term_id ] = $term_lang['term_taxonomy_id']; // Keep the term taxonomy id for future
197 191 }
198 192
199 193 // Get all terms with a language defined
200 - $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'" );
201 195 foreach ( $terms as $key => $term ) {
202 196 $terms[ $key ] = $wpdb->prepare( '( %d, %d )', $term->term_id, $lang_tt_ids[ $term->meta_value ] );
203 197 }
204 198
@@ -205,23 +199,17 @@
205 199 $terms = array_unique( $terms );
206 200
207 201 // Assign language to each term
208 202 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 ) );
203 + $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $terms ) );
211 204 }
212 205
213 206 // Translations
214 207 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();
208 + $table = $type . 'meta';
209 + $terms = $slugs = $tts = $trs = array();
221 210
222 211 // Get all translated objects
223 - // PHPCS:ignore WordPress.DB.PreparedSQL
224 212 $objects = $wpdb->get_col( "SELECT DISTINCT meta_value FROM {$wpdb->$table} WHERE meta_key = '_translations'" );
225 213
226 214 if ( empty( $objects ) ) {
227 215 continue;
@@ -228,12 +216,12 @@
228 216 }
229 217
230 218 foreach ( $objects as $obj ) {
231 219 $term = uniqid( 'pll_' ); // The term name
232 - $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term );
233 - $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 );
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 );
236 224 }
237 225
238 226 $terms = array_unique( $terms );
239 227
@@ -238,19 +226,17 @@
238 226 $terms = array_unique( $terms );
239 227
240 228 // Insert terms
241 229 if ( ! empty( $terms ) ) {
242 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
243 - $wpdb->query( "INSERT INTO {$wpdb->terms} ( slug, name ) VALUES " . implode( ',', $terms ) );
230 + $wpdb->query( "INSERT INTO $wpdb->terms ( slug, name ) VALUES " . implode( ',', $terms ) );
244 231 }
245 232
246 233 // Get all terms with their term_id
247 - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
248 - $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 ) . " )" );
249 235
250 236 // Prepare terms taxonomy relationship
251 237 foreach ( $terms as $term ) {
252 - $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 ] );
253 239 }
254 240
255 241 $tts = array_unique( $tts );
256 242
@@ -255,10 +241,9 @@
255 241 $tts = array_unique( $tts );
256 242
257 243 // Insert term_taxonomy
258 244 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 ) );
245 + $wpdb->query( "INSERT INTO $wpdb->term_taxonomy ( term_id, taxonomy, description ) VALUES " . implode( ',', $tts ) );
261 246 }
262 247
263 248 // Get all terms with term_taxonomy_id
264 249 $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) );
@@ -264,9 +249,9 @@
264 249 $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) );
265 250
266 251 // Prepare objects relationships
267 252 foreach ( $terms as $term ) {
268 - $translations = maybe_unserialize( $term->description );
253 + $translations = unserialize( $term->description );
269 254 foreach ( $translations as $object_id ) {
270 255 if ( ! empty( $object_id ) ) {
271 256 $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
272 257 }
@@ -276,10 +261,9 @@
276 261 $trs = array_unique( $trs );
277 262
278 263 // Insert term_relationships
279 264 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 ) );
265 + $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
282 266 }
283 267 }
284 268
285 269 // Upgrade of string translations is now in upgrade_1_2_1
@@ -314,10 +298,8 @@
314 298 // Old version < 1.1
315 299 // Multilingal locations and switcher item were stored in a dedicated option
316 300 if ( version_compare( $this->options['version'], '1.1', '<' ) ) {
317 301 if ( $menu_lang = get_option( 'polylang_nav_menus' ) ) {
318 - $locations = array();
319 -
320 302 foreach ( $menu_lang as $location => $arr ) {
321 303 if ( ! in_array( $location, array_keys( get_registered_nav_menus() ) ) ) {
322 304 continue;
323 305 }
@@ -333,17 +315,13 @@
333 315 }
334 316
335 317 // Create the menu items for the language switcher
336 318 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 - );
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 + ) );
346 324
347 325 update_post_meta( $menu_item_db_id, '_pll_menu_item', $switch_options );
348 326 }
349 327 }
@@ -364,9 +342,9 @@
364 342 // If old version < 1.2
365 343 // Clean the WP option as it was a bad idea to pollute it
366 344 if ( version_compare( $this->options['version'], '1.2', '<' ) ) {
367 345 foreach ( $menus as $loc => $menu ) {
368 - if ( strpos( $loc, '#' ) ) {
346 + if ( $pos = strpos( $loc, '#' ) ) {
369 347 unset( $menus[ $loc ] );
370 348 }
371 349 }
372 350
@@ -507,9 +485,9 @@
507 485 * Rewritten because wp_download_language_pack checks the existence of .mo and I need to download .po
508 486 *
509 487 * @since 1.6
510 488 */
511 - public static function download_language_packs() {
489 + static function download_language_packs() {
512 490 $languages = pll_languages_list( array( 'fields' => 'locale' ) );
513 491
514 492 // Prevents upgrade if the .po file is already here. Let WP manage the upgrades :)
515 493 foreach ( $languages as $key => $locale ) {
@@ -521,16 +499,14 @@
521 499 if ( empty( $languages ) ) {
522 500 return;
523 501 }
524 502
525 - require_once ABSPATH . 'wp-admin/includes/translation-install.php';
503 + require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
526 504 $translations = wp_get_available_translations();
527 505 if ( ! $translations ) {
528 506 return;
529 507 }
530 508
531 - $translations_to_load = array();
532 -
533 509 foreach ( $translations as $translation ) {
534 510 if ( in_array( $translation['language'], $languages ) ) {
535 511 $translation['type'] = 'core';
536 512 $translations_to_load[] = (object) $translation;
@@ -537,10 +513,10 @@
537 513 }
538 514 }
539 515
540 516 if ( ! empty( $translations_to_load ) ) {
541 - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
542 - $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 );
543 519 $upgrader->bulk_upgrade( $translations_to_load, array( 'clear_update_cache' => false ) );
544 520 }
545 521 }
546 522
@@ -560,9 +536,9 @@
560 536 * @since 1.8
561 537 */
562 538 protected function upgrade_1_8() {
563 539 // Adds the flag code in languages stored in DB
564 - $languages = include POLYLANG_DIR . '/settings/languages.php';
540 + include( PLL_SETTINGS_INC . '/languages.php' );
565 541
566 542 $terms = get_terms( 'language', array( 'hide_empty' => 0 ) );
567 543
568 544 foreach ( $terms as $lang ) {
@@ -567,10 +543,10 @@
567 543
568 544 foreach ( $terms as $lang ) {
569 545 $description = maybe_unserialize( $lang->description );
570 546 if ( isset( $languages[ $description['locale'] ] ) ) {
571 - $description['flag_code'] = $languages[ $description['locale'] ]['flag'];
572 - $description = maybe_serialize( $description );
547 + $description['flag_code'] = $languages[ $description['locale'] ][4];
548 + $description = serialize( $description );
573 549 wp_update_term( (int) $lang->term_id, 'language', array( 'description' => $description ) );
574 550 }
575 551 }
576 552
@@ -585,67 +561,6 @@
585 561 */
586 562 protected function upgrade_2_0_8() {
587 563 global $wpdb;
588 564 $wpdb->update( $wpdb->usermeta, array( 'meta_key' => 'locale' ), array( 'meta_key' => 'user_lang' ) );
589 - }
590 -
591 - /**
592 - * Upgrades if the previous version is < 2.1
593 - * Moves strings translations from polylang_mo post_content to post meta _pll_strings_translations
594 - *
595 - * @since 2.1
596 - */
597 - protected function upgrade_2_1() {
598 - foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) {
599 - $mo_id = PLL_MO::get_id( $lang );
600 - $meta = get_post_meta( $mo_id, '_pll_strings_translations', true );
601 -
602 - if ( empty( $meta ) ) {
603 - $post = get_post( $mo_id, OBJECT );
604 - $strings = maybe_unserialize( $post->post_content );
605 - if ( is_array( $strings ) ) {
606 - update_post_meta( $mo_id, '_pll_strings_translations', $strings );
607 - }
608 - }
609 - }
610 - }
611 -
612 - /**
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
616 - *
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.1
639 - *
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 - * - bug of flags url returning html fixed in 2.8.1
645 - *
646 - * @since 2.8.1
647 - */
648 - protected function upgrade_2_8_1() {
649 - delete_transient( 'pll_languages_list' );
650 565 }
651 566 }