PluginProbe
Polylang / trunk
Polylang vtrunk
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 | src/install/upgrade.php +62 -21 3.8.8 → trunk View file →
@@ -29,23 +29,8 @@
29 29 $this->options = $options;
30 30 }
31 31
32 32 /**
33 - * Check if upgrade is possible otherwise die to avoid activation
34 - *
35 - * @since 1.2
36 - *
37 - * @return void
38 - */
39 - public function can_activate() {
40 - if ( ! $this->can_upgrade() ) {
41 - ob_start();
42 - $this->admin_notices(); // FIXME the error message is displayed two times
43 - die( ob_get_contents() ); // phpcs:ignore WordPress.Security.EscapeOutput
44 - }
45 - }
46 -
47 - /**
48 33 * Upgrades if possible otherwise returns false to stop Polylang loading
49 34 *
50 35 * @since 1.2
51 36 *
@@ -76,9 +61,9 @@
76 61 return version_compare( $this->options['version'], '1.8', '>=' );
77 62 }
78 63
79 64 /**
80 - * Displays a notice when upgrading from a too old version
65 + * Displays a notice when upgrading from a too old version.
81 66 *
82 67 * @since 1.0
83 68 *
84 69 * @return void
@@ -83,19 +68,25 @@
83 68 *
84 69 * @return void
85 70 */
86 71 public function admin_notices() {
87 - load_plugin_textdomain( 'polylang' );
88 - printf(
89 - '<div class="error"><p>%s</p><p>%s</p></div>',
72 + $message = sprintf(
73 + '<p>%s</p><p>%s</p>',
90 74 esc_html__( 'Polylang has been deactivated because you upgraded from a too old version.', 'polylang' ),
91 75 sprintf(
92 76 /* translators: %1$s and %2$s are Polylang version numbers */
93 77 esc_html__( 'Before upgrading to %2$s, please upgrade to %1$s.', 'polylang' ),
94 78 '<strong>2.9</strong>',
95 - POLYLANG_VERSION // phpcs:ignore WordPress.Security.EscapeOutput
79 + esc_html( POLYLANG_VERSION )
96 80 )
97 81 );
82 +
83 + $args = array(
84 + 'type' => 'error',
85 + 'paragraph_wrap' => false,
86 + );
87 +
88 + wp_admin_notice( $message, $args );
98 89 }
99 90
100 91 /**
101 92 * Upgrades the plugin depending on the previous version
@@ -111,9 +102,9 @@
111 102 * i.e. delete the transient from the options table when external object cache is used.
112 103 */
113 104 delete_transient( 'pll_languages_list' );
114 105
115 - foreach ( array( '2.0.8', '2.1', '2.7', '3.4', '3.7', '3.8' ) as $version ) {
106 + foreach ( array( '2.0.8', '2.1', '2.7', '3.4', '3.7', '3.8', '3.9' ) as $version ) {
116 107 if ( version_compare( $this->options['version'], $version, '<' ) ) {
117 108 $method_to_call = array( $this, 'upgrade_' . str_replace( '.', '_', $version ) );
118 109 if ( is_callable( $method_to_call ) ) {
119 110 call_user_func( $method_to_call );
@@ -247,8 +238,58 @@
247 238 $language_taxonomies = $options['language_taxonomies'];
248 239 }
249 240
250 241 update_option( 'pll_language_taxonomies', $language_taxonomies );
242 + }
243 +
244 + /**
245 + * Upgrades if the previous version is < 3.9.
246 + * Migrates flag codes in language terms.
247 + *
248 + * @since 3.9
249 + *
250 + * @return void
251 + */
252 + protected function upgrade_3_9() {
253 + $to_migrate = array(
254 + 'arab' => 'ar.lang',
255 + 'basque' => 'es-pv',
256 + 'catalonia' => 'es-ct',
257 + 'england' => 'gb-eng',
258 + 'esperanto' => 'eo.lang',
259 + 'galicia' => 'es-ga',
260 + 'kurdistan' => 'iq-kr',
261 + 'occitania' => 'oci.lang',
262 + 'quebec' => 'ca-qc',
263 + 'scotland' => 'gb-sct',
264 + 'tibet' => 'bo.lang',
265 + 'veneto' => 'it-34',
266 + 'wales' => 'gb-wls',
267 + );
268 +
269 + $terms = get_terms(
270 + array(
271 + 'taxonomy' => 'language',
272 + 'hide_empty' => false,
273 + )
274 + );
275 +
276 + if ( ! is_array( $terms ) ) {
277 + return;
278 + }
279 +
280 + foreach ( $terms as $term ) {
281 + $description = maybe_unserialize( $term->description );
282 + $description = is_array( $description ) ? $description : array();
283 +
284 + if ( isset( $description['flag_code'] ) && is_string( $description['flag_code'] ) && isset( $to_migrate[ $description['flag_code'] ] ) ) {
285 + $description['flag_code'] = $to_migrate[ $description['flag_code'] ];
286 + /** @var string */
287 + $description = maybe_serialize( $description );
288 +
289 + wp_update_term( $term->term_id, 'language', array( 'description' => $description ) );
290 + }
291 + }
251 292 }
252 293
253 294 /**
254 295 * Moves strings translations from post meta to term meta _pll_strings_translations.