| @@ -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 ) ); |
| @@ -211,17 +207,13 @@ | ||
| 211 | 207 | } |
| 212 | 208 | |
| 213 | 209 | // Translations |
| 214 | 210 | 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(); | |
| 211 | + $table = $type . 'meta'; | |
| 212 | + $terms = $slugs = $tts = $trs = array(); | |
| 221 | 213 | |
| 222 | 214 | // Get all translated objects |
| 223 | - // PHPCS:ignore WordPress.DB.PreparedSQL | |
| 215 | + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 224 | 216 | $objects = $wpdb->get_col( "SELECT DISTINCT meta_value FROM {$wpdb->$table} WHERE meta_key = '_translations'" ); |
| 225 | 217 | |
| 226 | 218 | if ( empty( $objects ) ) { |
| 227 | 219 | continue; |
| @@ -230,10 +222,10 @@ | ||
| 230 | 222 | foreach ( $objects as $obj ) { |
| 231 | 223 | $term = uniqid( 'pll_' ); // The term name |
| 232 | 224 | $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term ); |
| 233 | 225 | $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 ); | |
| 226 | + $translations = maybe_unserialize( maybe_unserialize( $obj ) ); // 2 unserialize due to an old storage bug | |
| 227 | + $description[ $term ] = serialize( $translations ); | |
| 236 | 228 | } |
| 237 | 229 | |
| 238 | 230 | $terms = array_unique( $terms ); |
| 239 | 231 | |
| @@ -264,9 +256,9 @@ | ||
| 264 | 256 | $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) ); |
| 265 | 257 | |
| 266 | 258 | // Prepare objects relationships |
| 267 | 259 | foreach ( $terms as $term ) { |
| 268 | - $translations = maybe_unserialize( $term->description ); | |
| 260 | + $translations = unserialize( $term->description ); | |
| 269 | 261 | foreach ( $translations as $object_id ) { |
| 270 | 262 | if ( ! empty( $object_id ) ) { |
| 271 | 263 | $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id ); |
| 272 | 264 | } |
| @@ -314,10 +306,8 @@ | ||
| 314 | 306 | // Old version < 1.1 |
| 315 | 307 | // Multilingal locations and switcher item were stored in a dedicated option |
| 316 | 308 | if ( version_compare( $this->options['version'], '1.1', '<' ) ) { |
| 317 | 309 | if ( $menu_lang = get_option( 'polylang_nav_menus' ) ) { |
| 318 | - $locations = array(); | |
| 319 | - | |
| 320 | 310 | foreach ( $menu_lang as $location => $arr ) { |
| 321 | 311 | if ( ! in_array( $location, array_keys( get_registered_nav_menus() ) ) ) { |
| 322 | 312 | continue; |
| 323 | 313 | } |
| @@ -364,9 +354,9 @@ | ||
| 364 | 354 | // If old version < 1.2 |
| 365 | 355 | // Clean the WP option as it was a bad idea to pollute it |
| 366 | 356 | if ( version_compare( $this->options['version'], '1.2', '<' ) ) { |
| 367 | 357 | foreach ( $menus as $loc => $menu ) { |
| 368 | - if ( strpos( $loc, '#' ) ) { | |
| 358 | + if ( $pos = strpos( $loc, '#' ) ) { | |
| 369 | 359 | unset( $menus[ $loc ] ); |
| 370 | 360 | } |
| 371 | 361 | } |
| 372 | 362 | |
| @@ -527,10 +517,8 @@ | ||
| 527 | 517 | if ( ! $translations ) { |
| 528 | 518 | return; |
| 529 | 519 | } |
| 530 | 520 | |
| 531 | - $translations_to_load = array(); | |
| 532 | - | |
| 533 | 521 | foreach ( $translations as $translation ) { |
| 534 | 522 | if ( in_array( $translation['language'], $languages ) ) { |
| 535 | 523 | $translation['type'] = 'core'; |
| 536 | 524 | $translations_to_load[] = (object) $translation; |
| @@ -560,9 +548,9 @@ | ||
| 560 | 548 | * @since 1.8 |
| 561 | 549 | */ |
| 562 | 550 | protected function upgrade_1_8() { |
| 563 | 551 | // Adds the flag code in languages stored in DB |
| 564 | - $languages = include POLYLANG_DIR . '/settings/languages.php'; | |
| 552 | + include PLL_SETTINGS_INC . '/languages.php'; | |
| 565 | 553 | |
| 566 | 554 | $terms = get_terms( 'language', array( 'hide_empty' => 0 ) ); |
| 567 | 555 | |
| 568 | 556 | foreach ( $terms as $lang ) { |
| @@ -568,9 +556,9 @@ | ||
| 568 | 556 | foreach ( $terms as $lang ) { |
| 569 | 557 | $description = maybe_unserialize( $lang->description ); |
| 570 | 558 | if ( isset( $languages[ $description['locale'] ] ) ) { |
| 571 | 559 | $description['flag_code'] = $languages[ $description['locale'] ]['flag']; |
| 572 | - $description = maybe_serialize( $description ); | |
| 560 | + $description = serialize( $description ); | |
| 573 | 561 | wp_update_term( (int) $lang->term_id, 'language', array( 'description' => $description ) ); |
| 574 | 562 | } |
| 575 | 563 | } |
| 576 | 564 | |
| @@ -600,9 +588,9 @@ | ||
| 600 | 588 | $meta = get_post_meta( $mo_id, '_pll_strings_translations', true ); |
| 601 | 589 | |
| 602 | 590 | if ( empty( $meta ) ) { |
| 603 | 591 | $post = get_post( $mo_id, OBJECT ); |
| 604 | - $strings = maybe_unserialize( $post->post_content ); | |
| 592 | + $strings = unserialize( $post->post_content ); | |
| 605 | 593 | if ( is_array( $strings ) ) { |
| 606 | 594 | update_post_meta( $mo_id, '_pll_strings_translations', $strings ); |
| 607 | 595 | } |
| 608 | 596 | } |
| @@ -609,42 +597,15 @@ | ||
| 609 | 597 | } |
| 610 | 598 | } |
| 611 | 599 | |
| 612 | 600 | /** |
| 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 | |
| 601 | + * Upgrades if the previous version is < 2.3 | |
| 616 | 602 | * |
| 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 | |
| 603 | + * Deletes language cache due to 'redirect_lang' option removed for subdomains and multiple domains in 2.2 | |
| 604 | + * and W3C and Facebook locales added to PLL_Language objects in 2.3 | |
| 639 | 605 | * |
| 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 | |
| 606 | + * @since 2.3 | |
| 646 | 607 | */ |
| 647 | - protected function upgrade_2_8() { | |
| 608 | + protected function upgrade_2_3() { | |
| 648 | 609 | delete_transient( 'pll_languages_list' ); |
| 649 | 610 | } |
| 650 | 611 | } |