PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
3.8.10 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 All 234 releases
← All changes | install/upgrade.php +119 -209 2.7.4 → 2.0.3 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2
3 3 /**
4 - * Manages Polylang upgrades
4 + * manages Polylang upgrades
5 5 *
6 6 * @since 1.2
7 7 */
8 8 class PLL_Upgrade {
@@ -8,13 +8,11 @@
8 8 class PLL_Upgrade {
9 9 public $options;
10 10
11 11 /**
12 - * Constructor
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 }
@@ -19,9 +17,9 @@
19 17 $this->options = &$options;
20 18 }
21 19
22 20 /**
23 - * Check if upgrade is possible otherwise die to avoid activation
21 + * check if upgrade is possible otherwise die to avoid activation
24 22 *
25 23 * @since 1.2
26 24 */
27 25 public function can_activate() {
@@ -27,14 +25,14 @@
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 /**
36 - * Upgrades if possible otherwise returns false to stop Polylang loading
34 + * upgrades if possible otherwise returns false to stop Polylang loading
37 35 *
38 36 * @since 1.2
39 37 *
40 38 * @return bool true if upgrade is possible, false otherwise
@@ -50,10 +48,10 @@
50 48 }
51 49
52 50
53 51 /**
54 - * Check if we the previous version is not too old
55 - * Upgrades if OK
52 + * check if we the previous version is not too old
53 + * upgrades if OK
56 54 * /!\ never start any upgrade before admin_init as it is likely to conflict with some other plugins
57 55 *
58 56 * @since 1.2
59 57 *
@@ -59,14 +57,14 @@
59 57 *
60 58 * @return bool true if upgrade is possible, false otherwise
61 59 */
62 60 public function can_upgrade() {
63 - // Don't manage upgrade from version < 0.8
61 + // don't manage upgrade from version < 0.8
64 62 return version_compare( $this->options['version'], '0.8', '>=' );
65 63 }
66 64
67 65 /**
68 - * Displays a notice when ugrading from a too old version
66 + * displays a notice when ugrading from a too old version
69 67 *
70 68 * @since 1.0
71 69 */
72 70 public function admin_notices() {
@@ -74,23 +72,23 @@
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
86 84 /**
87 - * Upgrades the plugin depending on the previous version
85 + * upgrades the plugin depending on the previous version
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' ) 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 }
@@ -99,58 +97,58 @@
99 97 if ( false !== $delete_pre_1_2_data && absint( $delete_pre_1_2_data ) < time() ) {
100 98 $this->delete_pre_1_2_data();
101 99 }
102 100
103 - $this->options['previous_version'] = $this->options['version']; // Remember the previous version of Polylang since v1.7.7
101 + $this->options['previous_version'] = $this->options['version']; // remember the previous version of Polylang since v1.7.7
104 102 $this->options['version'] = POLYLANG_VERSION;
105 103 update_option( 'polylang', $this->options );
106 104 }
107 105
108 106 /**
109 - * Upgrades if the previous version is < 0.9
107 + * upgrades if the previous version is < 0.9
110 108 *
111 109 * @since 1.2
112 110 */
113 111 protected function upgrade_0_9() {
114 - $this->options['sync'] = defined( 'PLL_SYNC' ) && ! PLL_SYNC ? 0 : 1; // The option replaces PLL_SYNC in 0.9
112 + $this->options['sync'] = defined( 'PLL_SYNC' ) && ! PLL_SYNC ? 0 : 1; // the option replaces PLL_SYNC in 0.9
115 113 }
116 114
117 115 /**
118 - * Upgrades if the previous version is < 1.0
116 + * upgrades if the previous version is < 1.0
119 117 *
120 118 * @since 1.2
121 119 */
122 120 protected function upgrade_1_0() {
123 - // The option replaces PLL_MEDIA_SUPPORT in 1.0
121 + // the option replaces PLL_MEDIA_SUPPORT in 1.0
124 122 $this->options['media_support'] = defined( 'PLL_MEDIA_SUPPORT' ) && ! PLL_MEDIA_SUPPORT ? 0 : 1;
125 123
126 - // Split the synchronization options in 1.0
124 + // split the synchronization options in 1.0
127 125 $this->options['sync'] = empty( $this->options['sync'] ) ? array() : array_keys( PLL_Settings_Sync::list_metas_to_sync() );
128 126
129 - // Set default values for post types and taxonomies to translate
127 + // set default values for post types and taxonomies to translate
130 128 $this->options['post_types'] = array_values( get_post_types( array( '_builtin' => false, 'show_ui' => true ) ) );
131 129 $this->options['taxonomies'] = array_values( get_taxonomies( array( '_builtin' => false, 'show_ui' => true ) ) );
132 130 update_option( 'polylang', $this->options );
133 131
134 - flush_rewrite_rules(); // Rewrite rules have been modified in 1.0
132 + flush_rewrite_rules(); // rewrite rules have been modified in 1.0
135 133 }
136 134
137 135 /**
138 - * Upgrades if the previous version is < 1.1
136 + * upgrades if the previous version is < 1.1
139 137 *
140 138 * @since 1.2
141 139 */
142 140 protected function upgrade_1_1() {
143 - // Update strings register with icl_register_string
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 }
151 149
152 - // Move polylang_widgets options
150 + // move polylang_widgets options
153 151 if ( $widgets = get_option( 'polylang_widgets' ) ) {
154 152 $this->options['widgets'] = $widgets;
155 153 delete_option( 'polylang_widgets' );
156 154 }
@@ -156,46 +154,45 @@
156 154 }
157 155 }
158 156
159 157 /**
160 - * Upgrades if the previous version is < 1.2
158 + * upgrades if the previous version is < 1.2
161 159 *
162 160 * @since 1.2
163 161 */
164 162 protected function upgrade_1_2() {
165 - $this->options['domains'] = array(); // Option added in 1.2
163 + $this->options['domains'] = array(); // option added in 1.2
166 164
167 - // Need to register the taxonomies
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 - // Abort if the db upgrade has already been done previously
170 + // abort if the db upgrade has already been done previously
173 171 if ( get_terms( 'term_language', array( 'hide_empty' => 0 ) ) ) {
174 172 return;
175 173 }
176 174
177 - set_time_limit( 0 ); // In case we upgrade a huge site
175 + set_time_limit( 0 ); // in case we upgrade a huge site
178 176
179 - // Upgrade old model based on metas to new model based on taxonomies
177 + // upgrade old model based on metas to new model based on taxonomies
180 178 global $wpdb;
181 - $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();
179 + $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
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 - // First update language with new storage for locale and text direction
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 - // Add language to new 'term_language' taxonomy
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 - $lang_tt_ids[ $lang->term_id ] = $term_lang['term_taxonomy_id']; // Keep the term taxonomy id for future
190 + $lang_tt_ids[ $lang->term_id ] = $term_lang['term_taxonomy_id']; // keep the term taxonomy id for future
194 191 }
195 192
196 - // Get all terms with a language defined
197 - $terms = $wpdb->get_results( "SELECT term_id, meta_value FROM {$wpdb->termmeta} WHERE meta_key = '_language'" );
193 + // get all terms with a language defined
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
@@ -200,25 +197,19 @@
200 197 }
201 198
202 199 $terms = array_unique( $terms );
203 200
204 - // Assign language to each term
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 - // Translations
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 - // Get all translated objects
220 - // PHPCS:ignore WordPress.DB.PreparedSQL
211 + // get all translated objects
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;
@@ -224,46 +215,43 @@
224 215 continue;
225 216 }
226 217
227 218 foreach ( $objects as $obj ) {
228 - $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 );
219 + $term = uniqid( 'pll_' ); // the term name
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
237 - // Insert terms
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 - // 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 ) . ' )' );
233 + // get all terms with their term_id
234 + $terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug IN ( " . implode( ',', $slugs ) . " )" );
246 235
247 - // Prepare terms taxonomy relationship
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
254 - // Insert term_taxonomy
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 - // Get all terms with term_taxonomy_id
248 + // get all terms with term_taxonomy_id
261 249 $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) );
262 250
263 - // Prepare objects relationships
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 }
@@ -271,26 +259,25 @@
271 259 }
272 260
273 261 $trs = array_unique( $trs );
274 262
275 - // Insert term_relationships
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 - // Upgrade of string translations is now in upgrade_1_2_1
283 - // Upgrade of nav menus is now in upgrade_1_2_3
269 + // upgrade of string translations is now in upgrade_1_2_1
270 + // upgrade of nav menus is now in upgrade_1_2_3
284 271 }
285 272
286 273 /**
287 - * Upgrades if the previous version is < 1.2.1
274 + * upgrades if the previous version is < 1.2.1
288 275 *
289 276 * @since 1.2.1
290 277 */
291 278 protected function upgrade_1_2_1() {
292 - // Strings translations
279 + // strings translations
293 280 foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) {
294 281 if ( $strings = get_option( 'polylang_mo' . $lang->term_id ) ) {
295 282 $mo = new PLL_MO();
296 283 foreach ( $strings as $msg ) {
@@ -301,20 +288,18 @@
301 288 }
302 289 }
303 290
304 291 /**
305 - * Upgrades if the previous version is < 1.2.3
306 - * Uprades multilingual menus depending on the old version due to multiple changes in menus management
292 + * upgrades if the previous version is < 1.2.3
293 + * uprades multilingual menus depending on the old version due to multiple changes in menus management
307 294 *
308 295 * @since 1.2.3
309 296 */
310 297 public function upgrade_1_2_3() {
311 - // Old version < 1.1
312 - // Multilingal locations and switcher item were stored in a dedicated option
298 + // old version < 1.1
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 }
@@ -323,24 +308,20 @@
323 308 $translations = array_diff_key( $arr, $switch_options );
324 309 $has_switcher = array_shift( $switch_options );
325 310
326 311 foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) {
327 - // Move nav menus locations
312 + // move nav menus locations
328 313 if ( ! empty( $translations[ $lang->slug ] ) ) {
329 314 $locations[ $location ][ $lang->slug ] = $translations[ $lang->slug ];
330 315 }
331 316
332 - // Create the menu items for the language switcher
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 }
@@ -357,13 +338,13 @@
357 338 elseif ( empty( $this->options['nav_menus'] ) ) {
358 339 $menus = get_theme_mod( 'nav_menu_locations' );
359 340
360 341 if ( is_array( $menus ) ) {
361 - // If old version < 1.2
362 - // Clean the WP option as it was a bad idea to pollute it
342 + // if old version < 1.2
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
@@ -369,9 +350,9 @@
369 350
370 351 set_theme_mod( 'nav_menu_locations', $menus );
371 352 }
372 353
373 - // Get the multilingual locations
354 + // get the multilingual locations
374 355 foreach ( $menus as $loc => $menu ) {
375 356 foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) {
376 357 $arr[ $loc ][ $lang->slug ] = pll_get_term( $menu, $lang );
377 358 }
@@ -384,10 +365,10 @@
384 365 }
385 366 }
386 367
387 368 /**
388 - * Upgrades if the previous version is < 1.3
389 - * Moves the user biographies in default language to the 'description' user meta
369 + * upgrades if the previous version is < 1.3
370 + * moves the user biographies in default language to the 'description' user meta
390 371 *
391 372 * @since 1.3
392 373 */
393 374 protected function upgrade_1_3() {
@@ -403,11 +384,11 @@
403 384 }
404 385 }
405 386
406 387 /**
407 - * Upgrades if the previous version is < 1.4
408 - * Sets a transient to delete old model data
409 - * Deletes language cache (due to bug correction in home urls in 1.3.1 and added mo_id in 1.4)
388 + * upgrades if the previous version is < 1.4
389 + * sets a transient to delete old model data
390 + * deletes language cache (due to bug correction in home urls in 1.3.1 and added mo_id in 1.4)
410 391 *
411 392 * @since 1.4
412 393 */
413 394 protected function upgrade_1_4() {
@@ -415,19 +396,19 @@
415 396 delete_transient( 'pll_languages_list' );
416 397 }
417 398
418 399 /**
419 - * Old data were not deleted in 1.2, just in case...
420 - * Delete them at first upgrade at least 60 days after upgrade to 1.4
400 + * old data were not deleted in 1.2, just in case...
401 + * delete them at first upgrade at least 60 days after upgrade to 1.4
421 402 *
422 403 * @since 1.4
423 404 */
424 405 protected function delete_pre_1_2_data() {
425 - // Suppress data of the old model < 1.2
406 + // suppress data of the old model < 1.2
426 407 global $wpdb;
427 408 $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb in case WP < 4.4
428 409
429 - // Do nothing if the termmeta table does not exists
410 + // do nothing if the termmeta table does not exists
430 411 if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) {
431 412 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" );
432 413 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" );
433 414 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" );
@@ -433,9 +414,9 @@
433 414 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" );
434 415 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" );
435 416 }
436 417
437 - // Delete the strings translations
418 + // delete the strings translations
438 419 $languages = get_terms( 'language', array( 'hide_empty' => false ) );
439 420 foreach ( $languages as $lang ) {
440 421 delete_option( 'polylang_mo' . $lang->term_id );
441 422 }
@@ -443,10 +424,10 @@
443 424 delete_transient( 'pll_upgrade_1_4' );
444 425 }
445 426
446 427 /**
447 - * Upgrades if the previous version is < 1.4.1
448 - * Disables the browser detection when using multiple domains
428 + * upgrades if the previous version is < 1.4.1
429 + * disables the browser detection when using multiple domains
449 430 *
450 431 * @since 1.4.1
451 432 */
452 433 protected function upgrade_1_4_1() {
@@ -455,10 +436,10 @@
455 436 }
456 437 }
457 438
458 439 /**
459 - * Upgrades if the previous version is < 1.4.4
460 - * Uprades widgets options for language filter
440 + * upgrades if the previous version is < 1.4.4
441 + * uprades widgets options for language filter
461 442 *
462 443 * @since 1.4.4
463 444 */
464 445 protected function upgrade_1_4_4() {
@@ -475,10 +456,10 @@
475 456 unset( $this->options['widgets'] );
476 457 }
477 458
478 459 /**
479 - * Upgrades if the previous version is < 1.5
480 - * Deletes language cache (due to host property added and bug on search url)
460 + * upgrades if the previous version is < 1.5
461 + * deletes language cache (due to host property added and bug on search url)
481 462 *
482 463 * @since 1.5
483 464 */
484 465 protected function upgrade_1_5() {
@@ -485,10 +466,10 @@
485 466 delete_transient( 'pll_languages_list' );
486 467 }
487 468
488 469 /**
489 - * Upgrades if the previous version is < 1.6
490 - * Upgrades core language files to get the .po file (only for WP 4.0+)
470 + * upgrades if the previous version is < 1.6
471 + * upgrades core language files to get the .po file (only for WP 4.0+)
491 472 *
492 473 * @since 1.6
493 474 */
494 475 protected function upgrade_1_6() {
@@ -497,19 +478,19 @@
497 478 }
498 479 }
499 480
500 481 /**
501 - * Downloads language packs
502 - * Intended to be used only one time (at upgrade to Polylang 1.6 or first upgrade of WP 4.0 or later)
503 - * Adapted from wp_download_language_pack
504 - * Rewritten because wp_download_language_pack checks the existence of .mo and I need to download .po
482 + * downloads language packs
483 + * intended to be used only one time (at upgrade to Polylang 1.6 or first upgrade of WP 4.0 or later)
484 + * adapted from wp_download_language_pack
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 - // Prevents upgrade if the .po file is already here. Let WP manage the upgrades :)
492 + // prevents upgrade if the .po file is already here. Let WP manage the upgrades :)
512 493 foreach ( $languages as $key => $locale ) {
513 494 if ( file_exists( WP_LANG_DIR . "/$locale.po" ) ) {
514 495 unset( $languages[ $key ] );
515 496 }
@@ -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,32 +513,32 @@
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
544 523 /**
545 - * Upgrades if the previous version is < 1.7.4
524 + * upgrades if the previous version is < 1.7.4
546 525 *
547 526 * @since 1.7.4
548 527 */
549 528 protected function upgrade_1_7_4() {
550 - delete_transient( 'pll_languages_list' ); // Deletes language cache (due to flag properties added in 1.7, page on front removed in 1.7.2, home url fixes in 1.7.4)
551 - flush_rewrite_rules(); // Flush rewrite rules due to custom taxonomy rewrite rule bug fix
529 + delete_transient( 'pll_languages_list' ); // deletes language cache (due to flag properties added in 1.7, page on front removed in 1.7.2, home url fixes in 1.7.4)
530 + flush_rewrite_rules(); // flush rewrite rules due to custom taxonomy rewrite rule bug fix
552 531 }
553 532
554 533 /**
555 - * Upgrades if the previous version is < 1.8
534 + * upgrades if the previous version is < 1.8
556 535 *
557 536 * @since 1.8
558 537 */
559 538 protected function upgrade_1_8() {
560 - // Adds the flag code in languages stored in DB
561 - $languages = include PLL_SETTINGS_INC . '/languages.php';
539 + // adds the flag code in languages stored in DB
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,82 +543,13 @@
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
574 553 delete_transient( 'pll_languages_list' );
575 - }
576 -
577 - /**
578 - * Upgrades if the previous version is < 2.0.8
579 - * Changes the user meta 'user_lang' to 'locale' to match WP 4.7 choice
580 - *
581 - * @since 2.0.8
582 - */
583 - protected function upgrade_2_0_8() {
584 - global $wpdb;
585 - $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 554 }
645 555 }