Polylang - Version 1.2.3

Version Description

Polylang 1.2 introduced major internal changes. More than ever, make a database backup before upgrading from 1.1.6 or older! If you are using a version older than 0.8, please ugrade to 0.9.8 before ugrading to 1.2.3

=

Download this release

Release Info

Developer Chouby
Plugin Icon 128x128 Polylang
Version 1.2.3
Comparing to
See all releases

Code changes from version 1.2.2 to 1.2.3

admin/admin-model.php CHANGED
@@ -124,11 +124,13 @@ class PLL_Admin_Model extends PLL_Model {
124
  }
125
 
126
  // delete menus locations
127
- $locations = get_theme_mod('nav_menu_locations');
128
- foreach ($locations as $loc => $menu)
129
- if (false !== strpos($loc, '#' . $lang->slug))
130
- unset($locations[$loc]);
131
- set_theme_mod('nav_menu_locations', $locations);
 
 
132
 
133
  // delete users options
134
  foreach (get_users(array('fields' => 'ID')) as $user_id) {
@@ -194,7 +196,7 @@ class PLL_Admin_Model extends PLL_Model {
194
  $slug = $args['slug'];
195
  $old_slug = $lang->slug;
196
 
197
- // FIXME should do this in an action 'edit_term' to prevent translations to break when sharing a term with nav_menu
198
  if ($old_slug != $slug) {
199
  // update the language slug in translations
200
  $this->update_translations($old_slug, $slug);
@@ -208,12 +210,17 @@ class PLL_Admin_Model extends PLL_Model {
208
  }
209
 
210
  // update menus locations
211
- $locations = get_theme_mod('nav_menu_locations');
212
- foreach ($locations as $loc => $menu) {
213
- $loc = str_replace('#' . $old_slug, '#' . $slug, $loc);
214
- $new_locations[$loc] = $menu;
 
 
 
 
 
 
215
  }
216
- set_theme_mod('nav_menu_locations', $new_locations);
217
 
218
  // update domains
219
  if (!empty($this->options['domains'][$old_slug])) {
124
  }
125
 
126
  // delete menus locations
127
+ if (!empty($this->options['nav_menus'])) {
128
+ foreach ($this->options['nav_menus'] as $theme => $locations) {
129
+ foreach ($locations as $location => $languages) {
130
+ unset($this->options['nav_menus'][$theme][$location][$lang->slug]);
131
+ }
132
+ }
133
+ }
134
 
135
  // delete users options
136
  foreach (get_users(array('fields' => 'ID')) as $user_id) {
196
  $slug = $args['slug'];
197
  $old_slug = $lang->slug;
198
 
199
+ // FIXME should do this in an action 'edit_term' to prevent translations to break when sharing a term with nav_menu?
200
  if ($old_slug != $slug) {
201
  // update the language slug in translations
202
  $this->update_translations($old_slug, $slug);
210
  }
211
 
212
  // update menus locations
213
+ if (!empty($this->options['nav_menus'])) {
214
+ foreach ($this->options['nav_menus'] as $theme => $locations) {
215
+ foreach ($locations as $location => $languages) {
216
+ if (!empty($this->options['nav_menus'][$theme][$location][$old_slug])) {
217
+ $this->options['nav_menus'][$theme][$location][$slug] = $this->options['nav_menus'][$theme][$location][$old_slug];
218
+ unset($this->options['nav_menus'][$theme][$location][$old_slug]);
219
+ }
220
+
221
+ }
222
+ }
223
  }
 
224
 
225
  // update domains
226
  if (!empty($this->options['domains'][$old_slug])) {
admin/admin-nav-menu.php CHANGED
@@ -15,7 +15,9 @@ class PLL_Admin_Nav_Menu {
15
  * @param object $model instance of PLL_Model
16
  */
17
  public function __construct(&$model) {
18
- $this->model = $model;
 
 
19
 
20
  // integration in the WP menu interface
21
  add_action('admin_init', array(&$this, 'admin_init')); // after Polylang upgrade
@@ -39,7 +41,7 @@ class PLL_Admin_Nav_Menu {
39
  add_filter('wp_get_nav_menu_items', array(&$this, 'translate_switcher_title'));
40
 
41
  // translation of menus based on chosen locations
42
- add_filter('pre_update_option_theme_mods_' . get_option( 'stylesheet' ), array($this, 'update_nav_menu_locations'));
43
  add_filter('theme_mod_nav_menu_locations', array($this, 'nav_menu_locations'), 20);
44
 
45
  // filter _wp_auto_add_pages_to_menu by language
@@ -196,20 +198,14 @@ class PLL_Admin_Nav_Menu {
196
  // extract language and menu from locations
197
  foreach ($mods['nav_menu_locations'] as $loc => $menu) {
198
  if ($pos = strpos($loc, '___')) {
199
- $arr[substr($loc, 0, $pos)][substr($loc, $pos+3)] = $menu;
200
  unset($mods['nav_menu_locations'][$loc]); // remove temporary locations before database update
201
  }
202
  else
203
- $arr[$loc][$default] = $menu;
204
  }
205
 
206
- // assign menus language and translations
207
- foreach ($arr as $loc => $translations) {
208
- foreach ($translations as $lang=>$menu) {
209
- $this->model->set_term_language($menu, $lang);
210
- $this->model->save_translations('term', $menu, $translations);
211
- }
212
- }
213
  }
214
  return $mods;
215
  }
@@ -226,11 +222,12 @@ class PLL_Admin_Nav_Menu {
226
  if (is_array($menus)) {
227
  foreach ($menus as $loc => $menu) {
228
  foreach ($this->model->get_languages_list() as $lang) {
229
- if (pll_default_language() != $lang->slug && $id = $this->model->get_term($menu, $lang))
230
- $menus[$loc . '___' . $lang->slug] = $id;
231
  }
232
  }
233
  }
 
234
  return $menus;
235
  }
236
 
15
  * @param object $model instance of PLL_Model
16
  */
17
  public function __construct(&$model) {
18
+ $this->model = &$model;
19
+ $this->options = &$model->options;
20
+ $this->theme = get_option( 'stylesheet' );
21
 
22
  // integration in the WP menu interface
23
  add_action('admin_init', array(&$this, 'admin_init')); // after Polylang upgrade
41
  add_filter('wp_get_nav_menu_items', array(&$this, 'translate_switcher_title'));
42
 
43
  // translation of menus based on chosen locations
44
+ add_filter('pre_update_option_theme_mods_' . $this->theme, array($this, 'update_nav_menu_locations'));
45
  add_filter('theme_mod_nav_menu_locations', array($this, 'nav_menu_locations'), 20);
46
 
47
  // filter _wp_auto_add_pages_to_menu by language
198
  // extract language and menu from locations
199
  foreach ($mods['nav_menu_locations'] as $loc => $menu) {
200
  if ($pos = strpos($loc, '___')) {
201
+ $this->options['nav_menus'][$this->theme][substr($loc, 0, $pos)][substr($loc, $pos+3)] = $menu;
202
  unset($mods['nav_menu_locations'][$loc]); // remove temporary locations before database update
203
  }
204
  else
205
+ $this->options['nav_menus'][$this->theme][$loc][$default] = $menu;
206
  }
207
 
208
+ update_option('polylang', $this->options);
 
 
 
 
 
 
209
  }
210
  return $mods;
211
  }
222
  if (is_array($menus)) {
223
  foreach ($menus as $loc => $menu) {
224
  foreach ($this->model->get_languages_list() as $lang) {
225
+ if (pll_default_language() != $lang->slug && !empty($this->options['nav_menus'][$this->theme][$loc][$lang->slug]))
226
+ $menus[$loc . '___' . $lang->slug] = $this->options['nav_menus'][$this->theme][$loc][$lang->slug];
227
  }
228
  }
229
  }
230
+
231
  return $menus;
232
  }
233
 
admin/admin.php CHANGED
@@ -53,22 +53,11 @@ class PLL_Admin extends PLL_Base {
53
  if (!$this->model->get_languages_list())
54
  return;
55
 
56
- // admin language filter
57
- if (!defined('DOING_AJAX') && !empty($_GET['lang']) && !is_numeric($_GET['lang']))
58
- update_user_meta(get_current_user_id(), 'pll_filter_content', ($lang = $this->model->get_language($_GET['lang'])) ? $lang->slug : '');
59
-
60
- // set preferred language for use in filters
61
- $this->pref_lang = $this->model->get_language(($lg = get_user_meta(get_current_user_id(), 'pll_filter_content', true)) ? $lg : $this->options['default_lang']);
62
- $this->pref_lang = apply_filters('pll_admin_preferred_language', $this->pref_lang);
63
-
64
  // filter admin language for users
 
 
65
  add_filter('locale', array(&$this, 'get_locale'));
66
 
67
- // inform that the admin language has been set
68
- $curlang = $this->model->get_language(get_locale());
69
- $GLOBALS['text_direction'] = $curlang->is_rtl ? 'rtl' : 'ltr'; // force text direction according to language setting
70
- do_action('pll_language_defined', $curlang->slug, $curlang);
71
-
72
  // adds the languages in admin bar
73
  // FIXME: OK for WP 3.2 and newer (the admin bar is not displayed on admin side for WP 3.1)
74
  add_action('admin_bar_menu', array(&$this, 'admin_bar_menu'), 100); // 100 determines the position
@@ -141,6 +130,26 @@ class PLL_Admin extends PLL_Base {
141
  printf('<p style="margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">%s</p>', $r->upgrade_notice);
142
  }
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  /*
145
  * get the locale based on user preference
146
  *
53
  if (!$this->model->get_languages_list())
54
  return;
55
 
 
 
 
 
 
 
 
 
56
  // filter admin language for users
57
+ // we must not call user info before WordPress defines user roles in wp-settings.php
58
+ add_filter('setup_theme', array(&$this, 'init_user'));
59
  add_filter('locale', array(&$this, 'get_locale'));
60
 
 
 
 
 
 
61
  // adds the languages in admin bar
62
  // FIXME: OK for WP 3.2 and newer (the admin bar is not displayed on admin side for WP 3.1)
63
  add_action('admin_bar_menu', array(&$this, 'admin_bar_menu'), 100); // 100 determines the position
130
  printf('<p style="margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">%s</p>', $r->upgrade_notice);
131
  }
132
 
133
+ /*
134
+ * defines the backend language and the admin language filter based on user preferences
135
+ *
136
+ * @since 1.2.3
137
+ */
138
+ public function init_user() {
139
+ // admin language filter
140
+ if (!defined('DOING_AJAX') && !empty($_GET['lang']) && !is_numeric($_GET['lang']))
141
+ update_user_meta(get_current_user_id(), 'pll_filter_content', ($lang = $this->model->get_language($_GET['lang'])) ? $lang->slug : '');
142
+
143
+ // set preferred language for use in filters
144
+ $this->pref_lang = $this->model->get_language(($lg = get_user_meta(get_current_user_id(), 'pll_filter_content', true)) ? $lg : $this->options['default_lang']);
145
+ $this->pref_lang = apply_filters('pll_admin_preferred_language', $this->pref_lang);
146
+
147
+ // inform that the admin language has been set
148
+ $curlang = $this->model->get_language(get_locale());
149
+ $GLOBALS['text_direction'] = $curlang->is_rtl ? 'rtl' : 'ltr'; // force text direction according to language setting
150
+ do_action('pll_language_defined', $curlang->slug, $curlang);
151
+ }
152
+
153
  /*
154
  * get the locale based on user preference
155
  *
frontend/frontend-filters.php CHANGED
@@ -119,8 +119,9 @@ class PLL_Frontend_Filters {
119
  public function option_sticky_posts($posts) {
120
  if ($this->curlang && !empty($posts)) {
121
  update_object_term_cache($posts, 'post'); // to avoid queries in foreach
122
- foreach ($posts as $key=>$post_id) {
123
- if ($this->model->get_post_language($post_id)->term_id != $this->curlang->term_id)
 
124
  unset($posts[$key]);
125
  }
126
  }
119
  public function option_sticky_posts($posts) {
120
  if ($this->curlang && !empty($posts)) {
121
  update_object_term_cache($posts, 'post'); // to avoid queries in foreach
122
+ foreach ($posts as $key => $post_id) {
123
+ $lang = $this->model->get_post_language($post_id);
124
+ if (empty($lang) || $lang->term_id != $this->curlang->term_id)
125
  unset($posts[$key]);
126
  }
127
  }
frontend/frontend-nav-menu.php CHANGED
@@ -12,7 +12,10 @@ class PLL_Frontend_Nav_Menu {
12
  *
13
  * @since 1.2
14
  */
15
- public function __construct() {
 
 
 
16
  // split the language switcher menu item in several language menu items
17
  add_filter('wp_get_nav_menu_items', array(&$this, 'wp_get_nav_menu_items'));
18
  add_filter('wp_nav_menu_objects', array(&$this, 'wp_nav_menu_objects'));
@@ -136,9 +139,12 @@ class PLL_Frontend_Nav_Menu {
136
  */
137
  public function nav_menu_locations($menus) {
138
  if (is_array($menus))
139
- foreach ($menus as $loc => $menu)
140
- if ($id = pll_get_term($menu))
141
- $menus[$loc] = $id;
 
 
 
142
 
143
  return $menus;
144
  }
@@ -150,19 +156,17 @@ class PLL_Frontend_Nav_Menu {
150
  */
151
  public function customizer_locations() {
152
  $customized = json_decode($_POST['customized']);
153
- $curlang = pll_current_language();
154
 
155
- if (is_array($customized)) {
156
  foreach ($customized as $key => $c) {
157
  if (false !== strpos($key, 'nav_menu_locations[')) {
158
  $loc = substr(trim($key, ']'), 19);
159
- if (($pos = strpos($loc, '___')) && substr($loc, $pos+3) == $curlang) {
160
  $loc = 'nav_menu_locations[' . substr($loc, 0, $pos) . ']';
161
  $customized->$loc = $c;
162
  }
163
  }
164
  }
165
-
166
  $_POST['customized'] = json_encode($customized);
167
  }
168
  }
12
  *
13
  * @since 1.2
14
  */
15
+ public function __construct($options, $curlang) {
16
+ $this->options = &$options;
17
+ $this->curlang = &$curlang;
18
+
19
  // split the language switcher menu item in several language menu items
20
  add_filter('wp_get_nav_menu_items', array(&$this, 'wp_get_nav_menu_items'));
21
  add_filter('wp_nav_menu_objects', array(&$this, 'wp_nav_menu_objects'));
139
  */
140
  public function nav_menu_locations($menus) {
141
  if (is_array($menus))
142
+ $theme = get_option('stylesheet');
143
+
144
+ foreach ($menus as $loc => $menu) {
145
+ if (!empty($this->options['nav_menus'][$theme][$loc][$this->curlang->slug]))
146
+ $menus[$loc] = $this->options['nav_menus'][$theme][$loc][$this->curlang->slug];
147
+ }
148
 
149
  return $menus;
150
  }
156
  */
157
  public function customizer_locations() {
158
  $customized = json_decode($_POST['customized']);
 
159
 
160
+ if (is_object($customized)) {
161
  foreach ($customized as $key => $c) {
162
  if (false !== strpos($key, 'nav_menu_locations[')) {
163
  $loc = substr(trim($key, ']'), 19);
164
+ if (($pos = strpos($loc, '___')) && substr($loc, $pos+3) == $this->curlang->slug) {
165
  $loc = 'nav_menu_locations[' . substr($loc, 0, $pos) . ']';
166
  $customized->$loc = $c;
167
  }
168
  }
169
  }
 
170
  $_POST['customized'] = json_encode($customized);
171
  }
172
  }
frontend/frontend.php CHANGED
@@ -61,7 +61,7 @@ class PLL_Frontend extends PLL_Base{
61
  $this->filters_search = new PLL_Frontend_Filters_Search($this->links);
62
 
63
  // nav menu
64
- $this->nav_menu = new PLL_Frontend_Nav_Menu();
65
  }
66
 
67
  /*
61
  $this->filters_search = new PLL_Frontend_Filters_Search($this->links);
62
 
63
  // nav menu
64
+ $this->nav_menu = new PLL_Frontend_Nav_Menu($this->options, $curlang);
65
  }
66
 
67
  /*
include/model.php CHANGED
@@ -517,7 +517,10 @@ class PLL_Model {
517
  if (!empty($this->options['media_support']))
518
  $post_types['attachement'] = 'attachment';
519
 
520
- return apply_filters('pll_get_post_types', array_merge($post_types, $this->options['post_types']) , false);
 
 
 
521
  }
522
 
523
  /*
@@ -565,8 +568,12 @@ class PLL_Model {
565
  * @return array array of taxonomy names for which Polylang manages languages and translations
566
  */
567
  protected function get_taxonomies() {
568
- $taxonomies = array('category' => 'category', 'post_tag' => 'post_tag', 'nav_menu' => 'nav_menu');
569
- return apply_filters('pll_get_taxonomies', array_merge($taxonomies, $this->options['taxonomies']), false);
 
 
 
 
570
  }
571
 
572
  /*
517
  if (!empty($this->options['media_support']))
518
  $post_types['attachement'] = 'attachment';
519
 
520
+ if (is_array($this->options['post_types']))
521
+ $post_types = array_merge($post_types, $this->options['post_types']);
522
+
523
+ return apply_filters('pll_get_post_types', $post_types , false);
524
  }
525
 
526
  /*
568
  * @return array array of taxonomy names for which Polylang manages languages and translations
569
  */
570
  protected function get_taxonomies() {
571
+ $taxonomies = array('category' => 'category', 'post_tag' => 'post_tag');
572
+
573
+ if (is_array($this->options['taxonomies']))
574
+ $taxonomies = array_merge($taxonomies, $this->options['taxonomies']);
575
+
576
+ return apply_filters('pll_get_taxonomies', $taxonomies, false);
577
  }
578
 
579
  /*
include/upgrade.php CHANGED
@@ -49,6 +49,7 @@ class PLL_Upgrade {
49
  /*
50
  * check if we the previous version is not too old
51
  * upgrades if OK
 
52
  *
53
  * @since 1.2
54
  *
@@ -59,7 +60,7 @@ class PLL_Upgrade {
59
  if (version_compare($this->options['version'], '0.8', '<'))
60
  return false;
61
 
62
- $this->_upgrade();
63
  return true;
64
  }
65
 
@@ -86,8 +87,8 @@ class PLL_Upgrade {
86
  *
87
  * @since 1.2
88
  */
89
- protected function _upgrade() {
90
- foreach (array('0.9', '1.0', '1.1', '1.2', '1.2.1') as $version)
91
  if (version_compare($this->options['version'], $version, '<'))
92
  call_user_func(array(&$this, 'upgrade_' . str_replace('.', '_', $version)));
93
 
@@ -116,19 +117,6 @@ class PLL_Upgrade {
116
  // split the synchronization options in 1.0
117
  $this->options['sync'] = empty($this->options['sync']) ? array() : array_keys(PLL_Settings::list_metas_to_sync());
118
 
119
- add_action('wp_loaded', array(&$this, 'wp_loaded_upgrade_1_0')); // once post types and taxonomies are set
120
-
121
- if (did_action('wp_loaded'))
122
- $this->wp_loaded_upgrade_1_0();
123
- }
124
-
125
- /*
126
- * upgrades if the previous version is < 1.0
127
- * actions that need to be taken after all post types and taxonomies are known
128
- *
129
- * @since 1.2
130
- */
131
- public function wp_loaded_upgrade_1_0() {
132
  // set default values for post types and taxonomies to translate
133
  $this->options['post_types'] = array_values(get_post_types(array('_builtin' => false, 'show_ui => true')));
134
  $this->options['taxonomies'] = array_values(get_taxonomies(array('_builtin' => false, 'show_ui => true')));
@@ -156,40 +144,6 @@ class PLL_Upgrade {
156
  $this->options['widgets'] = $widgets;
157
  delete_option('polylang_widgets');
158
  }
159
-
160
- // update nav menus
161
- if ($menu_lang = get_option('polylang_nav_menus')) {
162
-
163
- foreach ($menu_lang as $location => $arr) {
164
- if (!in_array($location, array_keys(get_registered_nav_menus())))
165
- continue;
166
-
167
- $switch_options = array_slice($arr, -5, 5);
168
- $translations = array_diff_key($arr, $switch_options);
169
- $has_switcher = array_shift($switch_options);
170
-
171
- $languages = get_terms('language', array('hide_empty' => 0)); // don't use get_languages_list which can't work with the old model
172
- foreach ($languages as $lang) {
173
- $menu_locations[$location.(pll_default_language() == $lang->slug ? '' : '#' . $lang->slug)] = empty($translations[$lang->slug]) ? 0 : $translations[$lang->slug];
174
-
175
- // create the menu items
176
- if (!empty($has_switcher)) {
177
- $menu_item_db_id = wp_update_nav_menu_item($translations[$lang->slug], 0, array(
178
- 'menu-item-title' => __('Language switcher', 'polylang'),
179
- 'menu-item-url' => '#pll_switcher',
180
- 'menu-item-status' => 'publish'
181
- ));
182
-
183
- update_post_meta($menu_item_db_id, '_pll_menu_item', $switch_options);
184
- }
185
- }
186
- }
187
-
188
- if (!empty($menu_locations))
189
- set_theme_mod('nav_menu_locations', $menu_locations);
190
-
191
- delete_option('polylang_nav_menus');
192
- }
193
  }
194
 
195
  /*
@@ -293,34 +247,8 @@ class PLL_Upgrade {
293
  $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES " . implode(',', $trs));
294
  }
295
 
296
- // it was a bad idea to pollute WP option with our custom nav menu locations
297
- $menus = get_theme_mod('nav_menu_locations');
298
- if (is_array($menus)) {
299
- $default = $this->options['default_lang'];
300
- $arr = array();
301
-
302
- foreach ($menus as $loc => $menu) {
303
- if ($pos = strpos($loc, '#')) {
304
- $arr[substr($loc, 0, $pos)][substr($loc, $pos+1)] = $menu;
305
- unset($menus[$loc]);
306
- }
307
- else
308
- $arr[$loc][$default] = $menu;
309
- }
310
-
311
- $model = new PLL_Admin_Model($this->options);
312
- $model->clean_languages_cache();
313
-
314
- // assign menus language and translations
315
- foreach ($arr as $loc => $translations) {
316
- foreach ($translations as $lang=>$menu) {
317
- $model->set_term_language($menu, $lang);
318
- $model->save_translations('term', $menu, $translations);
319
- }
320
- }
321
-
322
- set_theme_mod('nav_menu_locations', $menus);
323
- }
324
  }
325
 
326
  /*
@@ -329,21 +257,6 @@ class PLL_Upgrade {
329
  * @since 1.2.1
330
  */
331
  protected function upgrade_1_2_1() {
332
- $action = is_admin() ? 'admin_init' : 'wp_loaded'; // admin_init for wp-ecommerce
333
-
334
- add_action($action, array(&$this, 'wp_loaded_upgrade_1_2_1')); // once wp-rewrite is available
335
-
336
- if (did_action($action))
337
- $this->wp_loaded_upgrade_1_2_1();
338
- }
339
-
340
- /*
341
- * upgrades if the previous version is < 1.2.1
342
- * actions that need to be taken after $wp_rewrite is available
343
- *
344
- * @since 1.2.1
345
- */
346
- public function wp_loaded_upgrade_1_2_1() {
347
  // strings translations
348
  foreach(get_terms('language', array('hide_empty' => 0)) as $lang) {
349
  if ($strings = get_option('polylang_mo'.$lang->term_id)) {
@@ -355,6 +268,79 @@ class PLL_Upgrade {
355
  }
356
  }
357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  /*
359
  * upgrades if the previous version is < 1.3
360
  * FIXME don't delete old data in 1.2, just in case...
49
  /*
50
  * check if we the previous version is not too old
51
  * upgrades if OK
52
+ * /!\ never start any upgrade before admin_init as it is likely to conflict with some other plugins
53
  *
54
  * @since 1.2
55
  *
60
  if (version_compare($this->options['version'], '0.8', '<'))
61
  return false;
62
 
63
+ add_action('admin_init', array(&$this, '_upgrade'));
64
  return true;
65
  }
66
 
87
  *
88
  * @since 1.2
89
  */
90
+ public function _upgrade() {
91
+ foreach (array('0.9', '1.0', '1.1', '1.2', '1.2.1', '1.2.3') as $version)
92
  if (version_compare($this->options['version'], $version, '<'))
93
  call_user_func(array(&$this, 'upgrade_' . str_replace('.', '_', $version)));
94
 
117
  // split the synchronization options in 1.0
118
  $this->options['sync'] = empty($this->options['sync']) ? array() : array_keys(PLL_Settings::list_metas_to_sync());
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  // set default values for post types and taxonomies to translate
121
  $this->options['post_types'] = array_values(get_post_types(array('_builtin' => false, 'show_ui => true')));
122
  $this->options['taxonomies'] = array_values(get_taxonomies(array('_builtin' => false, 'show_ui => true')));
144
  $this->options['widgets'] = $widgets;
145
  delete_option('polylang_widgets');
146
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  }
148
 
149
  /*
247
  $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES " . implode(',', $trs));
248
  }
249
 
250
+ // upgrade of string translations is now in upgrade_1_2_1
251
+ // upgrade of nav menus is now in upgrade_1_2_3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  }
253
 
254
  /*
257
  * @since 1.2.1
258
  */
259
  protected function upgrade_1_2_1() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  // strings translations
261
  foreach(get_terms('language', array('hide_empty' => 0)) as $lang) {
262
  if ($strings = get_option('polylang_mo'.$lang->term_id)) {
268
  }
269
  }
270
 
271
+ /*
272
+ * upgrades if the previous version is < 1.2.3
273
+ * uprades multilingual menus depending on the old version due to multiple changes in menus management
274
+ *
275
+ * @since 1.2.3
276
+ */
277
+ public function upgrade_1_2_3() {
278
+ // old version < 1.1
279
+ // multilingal locations and switcher item were stored in a dedicated option
280
+ if (version_compare($this->options['version'], '1.1', '<')) {
281
+ if ($menu_lang = get_option('polylang_nav_menus')) {
282
+ foreach ($menu_lang as $location => $arr) {
283
+ if (!in_array($location, array_keys(get_registered_nav_menus())))
284
+ continue;
285
+
286
+ $switch_options = array_slice($arr, -5, 5);
287
+ $translations = array_diff_key($arr, $switch_options);
288
+ $has_switcher = array_shift($switch_options);
289
+
290
+ foreach (get_terms('language', array('hide_empty' => 0)) as $lang) {
291
+ // move nav menus locations
292
+ if (!empty($translations[$lang->slug]))
293
+ $locations[$location][$lang->slug] = $translations[$lang->slug];
294
+
295
+ // create the menu items for the language switcher
296
+ if (!empty($has_switcher)) {
297
+ $menu_item_db_id = wp_update_nav_menu_item($translations[$lang->slug], 0, array(
298
+ 'menu-item-title' => __('Language switcher', 'polylang'),
299
+ 'menu-item-url' => '#pll_switcher',
300
+ 'menu-item-status' => 'publish'
301
+ ));
302
+
303
+ update_post_meta($menu_item_db_id, '_pll_menu_item', $switch_options);
304
+ }
305
+ }
306
+ }
307
+
308
+ if (!empty($locations))
309
+ $this->options['nav_menus'][get_option('stylesheet')] = $locations;
310
+
311
+ delete_option('polylang_nav_menus');
312
+ }
313
+
314
+ }
315
+
316
+ elseif (empty($this->options['nav_menus'])) {
317
+ $menus = get_theme_mod('nav_menu_locations');
318
+
319
+ if (is_array($menus)) {
320
+ // if old version < 1.2
321
+ // clean the WP option as it was a bad idea to pollute it
322
+ if (version_compare($this->options['version'], '1.2', '<')) {
323
+ foreach ($menus as $loc => $menu) {
324
+ if ($pos = strpos($loc, '#'))
325
+ unset($menus[$loc]);
326
+ }
327
+
328
+ set_theme_mod('nav_menu_locations', $menus);
329
+ }
330
+
331
+ // get the multilingual locations
332
+ foreach ($menus as $loc => $menu) {
333
+ foreach (get_terms('language', array('hide_empty' => 0)) as $lang) {
334
+ $arr[$loc][$lang->slug] = pll_get_term($menu, $lang);
335
+ }
336
+ }
337
+
338
+ if (!empty($arr))
339
+ $this->options['nav_menus'][get_option('stylesheet')] = $arr;
340
+ }
341
+ }
342
+ }
343
+
344
  /*
345
  * upgrades if the previous version is < 1.3
346
  * FIXME don't delete old data in 1.2, just in case...
include/wpml-compat.php CHANGED
@@ -5,6 +5,8 @@
5
 
6
  /*
7
  * defines two WPML constants once the language has been defined
 
 
8
  *
9
  * @since 0.9.5
10
  */
5
 
6
  /*
7
  * defines two WPML constants once the language has been defined
8
+ * the compatibility with WPML is not perfect on admin side as the constants are defined
9
+ * in 'setup_theme' by Polylang (based on user info) and 'plugins_loaded' by WPML (based on cookie)
10
  *
11
  * @since 0.9.5
12
  */
polylang.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://polylang.wordpress.com/
5
- Version: 1.2.2
6
  Author: Frédéric Demarle
7
  Description: Adds multilingual capability to WordPress
8
  Text Domain: polylang
@@ -29,7 +29,7 @@ Domain Path: /languages
29
  *
30
  */
31
 
32
- define('POLYLANG_VERSION', '1.2.2');
33
  define('PLL_MIN_WP_VERSION', '3.1');
34
 
35
  define('POLYLANG_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://polylang.wordpress.com/
5
+ Version: 1.2.3
6
  Author: Frédéric Demarle
7
  Description: Adds multilingual capability to WordPress
8
  Text Domain: polylang
29
  *
30
  */
31
 
32
+ define('POLYLANG_VERSION', '1.2.3');
33
  define('PLL_MIN_WP_VERSION', '3.1');
34
 
35
  define('POLYLANG_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: multilingual, bilingual, translate, translation, language, multilanguage, international, localization
5
  Requires at least: 3.1
6
  Tested up to: 3.7.1
7
- Stable tag: 1.2.2
8
  License: GPLv2 or later
9
 
10
  Polylang adds multilingual content management support to WordPress.
@@ -63,21 +63,28 @@ See http://polylang.wordpress.com/documentation/contribute/
63
 
64
  == Upgrade Notice ==
65
 
66
- = 1.2.2 =
67
- Polylang 1.2 introduces major internal changes. More than ever, make a database backup before upgrading! If you are using a version older than 0.8, please ugrade to 0.9.8 before ugrading to 1.2
68
 
69
  == Changelog ==
70
 
 
 
 
 
 
 
 
71
  = 1.2.2 (2013-11-14) =
72
 
73
  * Updated Polish translation thanks to [Bartosz](http://www.dfactory.eu/)
74
- * delay strings translations upgrade from 'wp_loaded' to 'admin_init' to avoid fatal error when wp-ecommerce is active
75
  * Remove Jetpack infinite scroll compatibility code as it seems useless with new Polylang 1.2 code structure
76
  * Bug correction: fatal error when doing ajax on frontend
77
  * Bug correction: ICL_LANGUAGE_CODE incorrectly defined when doing ajax on frontend
78
  * Bug correction: ['current_lang'] and ['no-translation'] indexes disappeared from pll_the_languages raw output
79
  * Bug correction: invalid argument supplied for foreach() in /polylang/include/mo.php on line 57
80
- * Bug correction: cookie may not correctly set
81
  * Bug correction: languages columns may not be displayed in custom post types and custom taxonomies tables
82
 
83
  = 1.2.1 (2013-11-11) =
4
  Tags: multilingual, bilingual, translate, translation, language, multilanguage, international, localization
5
  Requires at least: 3.1
6
  Tested up to: 3.7.1
7
+ Stable tag: 1.2.3
8
  License: GPLv2 or later
9
 
10
  Polylang adds multilingual content management support to WordPress.
63
 
64
  == Upgrade Notice ==
65
 
66
+ = 1.2.3 =
67
+ Polylang 1.2 introduced major internal changes. More than ever, make a database backup before upgrading from 1.1.6 or older! If you are using a version older than 0.8, please ugrade to 0.9.8 before ugrading to 1.2.3
68
 
69
  == Changelog ==
70
 
71
+ = 1.2.3 (2013-11-17) =
72
+
73
+ * Avoid fatal error when ugrading with Nextgen Gallery active
74
+ * Bug correction: menus locations of non default language are lost at theme deactivation
75
+ * Bug correction: impossible to set menus locations of non default language in some specific cases
76
+ * Bug correction: bbpress admin is broken
77
+
78
  = 1.2.2 (2013-11-14) =
79
 
80
  * Updated Polish translation thanks to [Bartosz](http://www.dfactory.eu/)
81
+ * Delay strings translations upgrade from 'wp_loaded' to 'admin_init' to avoid fatal error when wp-ecommerce is active
82
  * Remove Jetpack infinite scroll compatibility code as it seems useless with new Polylang 1.2 code structure
83
  * Bug correction: fatal error when doing ajax on frontend
84
  * Bug correction: ICL_LANGUAGE_CODE incorrectly defined when doing ajax on frontend
85
  * Bug correction: ['current_lang'] and ['no-translation'] indexes disappeared from pll_the_languages raw output
86
  * Bug correction: invalid argument supplied for foreach() in /polylang/include/mo.php on line 57
87
+ * Bug correction: cookie may not be correctly set
88
  * Bug correction: languages columns may not be displayed in custom post types and custom taxonomies tables
89
 
90
  = 1.2.1 (2013-11-11) =