Polylang - Version 0.8.2

Version Description

  • Add Italian translation contributed by Luca Barbetti
  • Improve performance on admin side
  • Comment status and ping status are now copied when adding a new translation
  • Deprecated API function 'pll_is_front_page' as it is now useless
  • Bug correction: Wrong translation url for taxonomies when adding the language information to all urls
  • Bug correction: "translation" of search page does not work if the site is only made of pages
  • Bug correction: wrong language permalink structure introduced in 0.8.1
  • Bug correction: wrong language set when clicking on "add new" translation in edit category and edit tags panels
  • Bug correction: site does not display if no languages are set
  • Bug correction: get_author_posts_url is 404
  • Bug correction: homepage is 404 when using a static front page and adding the language information to all urls
Download this release

Release Info

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

Code changes from version 0.8.1 to 0.8.2

doc/documentation-en.odt CHANGED
Binary file
doc/documentation-en.pdf CHANGED
Binary file
include/admin-base.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // functions common to all admin panels
4
+ class Polylang_Admin_Base extends Polylang_Base {
5
+ function __construct() {
6
+ parent::__construct();
7
+
8
+ // filter admin language for users
9
+ add_filter('locale', array(&$this, 'get_locale'));
10
+
11
+ // additionnal filters and actions
12
+ add_action('admin_init', array(&$this, 'admin_init_base'));
13
+
14
+ // adds the link to the languages panel in the wordpress admin menu
15
+ add_action('admin_menu', array(&$this, 'add_menus'));
16
+
17
+ // setup js scripts andd css styles
18
+ add_action('admin_enqueue_scripts', array(&$this,'admin_enqueue_scripts'));
19
+ }
20
+
21
+ // returns the locale based on user preference
22
+ function get_locale($locale) {
23
+ // get_current_user_id uses wp_get_current_user which may not be available the first time(s) get_locale is called
24
+ return function_exists('wp_get_current_user') && ($loc = get_user_meta(get_current_user_id(), 'user_lang', 'true')) ? $loc : $locale;
25
+ }
26
+
27
+ // set text direction if the user set its own language
28
+ function admin_init_base() {
29
+ global $wpdb, $wp_locale;
30
+ $lang_id = $wpdb->get_var($wpdb->prepare("SELECT t.term_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id
31
+ WHERE tt.taxonomy = 'language' AND tt.description = %s LIMIT 1", get_locale())); // no function exists to get term by description
32
+ if ($lang_id)
33
+ $wp_locale->text_direction = get_metadata('term', $lang_id, '_rtl', true) ? 'rtl' : 'ltr';
34
+ }
35
+
36
+ // adds the link to the languages panel in the wordpress admin menu
37
+ function add_menus() {
38
+ add_submenu_page('options-general.php', __('Languages', 'polylang'), __('Languages', 'polylang'), 'manage_options', 'mlang', array(&$this, 'languages_page'));
39
+
40
+ // adds the about box the languages admin panel
41
+ // test of $_GET['tab'] avoids displaying the automatically generated screen options on other tabs
42
+ if (PLL_DISPLAY_ABOUT && isset($_GET['page']) && $_GET['page'] == 'mlang' && (!isset($_GET['tab']) || $_GET['tab'] == 'lang'))
43
+ add_meta_box('pll_about_box', __('About Polylang', 'polylang'), array(&$this,'about'), 'settings_page_mlang', 'normal', 'high');
44
+ }
45
+
46
+ // setup js scripts & css styles (only on the relevant pages)
47
+ function admin_enqueue_scripts() {
48
+ $screen = get_current_screen();
49
+
50
+ // FIXME keep the script in header to be sure it is loaded before post.js otherwise a non filtered tag cloud appears in tag cloud metabox
51
+ if ($screen->base == 'settings_page_mlang' || $screen->base == 'post' || $screen->base == 'edit-tags')
52
+ wp_enqueue_script('polylang_admin', POLYLANG_URL .'/js/admin.js', array('jquery', 'wp-ajax-response'), POLYLANG_VERSION);
53
+
54
+ if ($screen->base == 'settings_page_mlang' || $screen->base == 'post' || $screen->base == 'edit-tags' || $screen->base == 'edit')
55
+ wp_enqueue_style('polylang_admin', POLYLANG_URL .'/css/admin.css', array(), POLYLANG_VERSION);
56
+
57
+ if ($screen->base == 'settings_page_mlang') {
58
+ wp_enqueue_script('postbox');
59
+ }
60
+ }
61
+
62
+ // downloads mofiles
63
+ function download_mo($locale, $upgrade = false) {
64
+ global $wp_version;
65
+ $mofile = WP_LANG_DIR."/$locale.mo";
66
+
67
+ // does file exists ?
68
+ if ((file_exists($mofile) && !$upgrade) || $locale == 'en_US')
69
+ return true;
70
+
71
+ // does language directory exists ?
72
+ if (!is_dir(WP_LANG_DIR)) {
73
+ if (!@mkdir(WP_LANG_DIR))
74
+ return false;
75
+ }
76
+
77
+ // will first look in tags/ (most languages) then in branches/ (only Greek ?)
78
+ $base = 'http://svn.automattic.com/wordpress-i18n/'.$locale;
79
+ $bases = array($base.'/tags/', $base.'/branches/');
80
+
81
+ foreach ($bases as $base) {
82
+ // get all the versions available in the subdirectory
83
+ $resp = wp_remote_get($base);
84
+ if (is_wp_error($resp) || 200 != $resp['response']['code'])
85
+ continue;
86
+
87
+ preg_match_all('#>([0-9\.]+)\/#', $resp['body'], $matches);
88
+ if (empty($matches[1]))
89
+ continue;
90
+
91
+ rsort($matches[1]); // sort from newest to oldest
92
+ $versions = $matches[1];
93
+
94
+ $newest = $upgrade ? $upgrade : $wp_version;
95
+ foreach ($versions as $key=>$version) {
96
+ // will not try to download a too recent mofile
97
+ if (version_compare($version, $newest, '>'))
98
+ unset($versions[$key]);
99
+ // will not download an older version if we are upgrading
100
+ if ($upgrade && version_compare($version, $wp_version, '<='))
101
+ unset($versions[$key]);
102
+ }
103
+
104
+ $versions = array_splice($versions, 0, 5); // reduce the number of versions to test to 5
105
+ $args = array('timeout' => 30, 'stream' => true);
106
+
107
+ // try to download the file
108
+ foreach ($versions as $version) {
109
+ $resp = wp_remote_get($base."$version/messages/$locale.mo", $args + array('filename' => $mofile));
110
+ if (is_wp_error($resp) || 200 != $resp['response']['code'])
111
+ continue;
112
+
113
+ // try to download ms and continents-cities files if exist (will not return false if failed)
114
+ // with new files introduced in WP 3.4
115
+ foreach (array("ms", "continent-cities", "admin", "admin-network") as $file)
116
+ wp_remote_get($base."$version/messages/$file-$locale.mo", $args + array('filename' => WP_LANG_DIR."/$file-$locale.mo"));
117
+
118
+ // try to download theme files if exist (will not return false if failed)
119
+ // FIXME not updated when the theme is updated outside a core update
120
+ foreach (array("twentyten", "twentyeleven", "twentytwelve") as $theme)
121
+ wp_remote_get($base."$version/messages/$theme/$locale.mo", $args + array('filename' => get_theme_root()."/$theme/languages/$locale.mo"));
122
+
123
+ return true;
124
+ }
125
+ }
126
+ // we did not succeeded to download a file :(
127
+ return false;
128
+ }
129
+
130
+ // returns options available for the language switcher (menu or widget)
131
+ // FIXME do not include the dropdown in menu yet since I need to work on js
132
+ function get_switcher_options($type = 'widget', $key ='string') {
133
+ $options = array (
134
+ 'show_names' => array('string' => __('Displays language names', 'polylang'), 'default' => 1),
135
+ 'show_flags' => array('string' => __('Displays flags', 'polylang'), 'default' => 0),
136
+ 'force_home' => array('string' => __('Forces link to front page', 'polylang'), 'default' => 0),
137
+ 'hide_current' => array('string' => __('Hides the current language', 'polylang'), 'default' => 0),
138
+ );
139
+ $menu_options = array('switcher' => array('string' => __('Displays a language switcher at the end of the menu', 'polylang'), 'default' => 0));
140
+ $widget_options = array('dropdown' => array('string' => __('Displays as dropdown', 'polylang'), 'default' => 0));
141
+ $options = ($type == 'menu') ? array_merge($menu_options, $options) : array_merge($options, $widget_options);
142
+ return array_map(create_function('$v', "return \$v['$key'];"), $options);
143
+ }
144
+
145
+ // register strings for translation making sure it is not duplicate
146
+ function register_string($name, $string) {
147
+ $to_register = array('name'=> $name, 'string' => $string);
148
+ if (!in_array($to_register, $this->strings))
149
+ $this->strings[] = $to_register;
150
+ }
151
+ } // class Polylang_Admin_Base
152
+
153
+ ?>
include/admin-filters.php CHANGED
@@ -1,24 +1,27 @@
1
  <?php
2
 
3
  // all modifications of the WordPress admin ui
4
- class Polylang_Admin_Filters extends Polylang_Base {
5
 
6
  function __construct() {
7
  parent::__construct();
8
 
9
  // additionnal filters and actions
10
  add_action('admin_init', array(&$this, 'admin_init'));
11
- // setup js scripts andd css styles
12
- add_action('admin_enqueue_scripts', array(&$this,'admin_enqueue_scripts'));
13
-
14
- // filter admin language for users
15
- add_filter('locale', array(&$this, 'get_locale'));
16
 
17
  // remove the customize menu section as it is unusable with Polylang
18
  add_action('customize_register', array(&$this, 'customize_register'), 20); // since WP 3.4
19
 
20
  // refresh rewrite rules if the 'page_on_front' option is modified
21
- add_action('update_option_page_on_front', array(&$this, 'update_option_page_on_front'));
 
 
 
 
 
 
 
 
22
  }
23
 
24
  // add these actions and filters here and not in the constructor to be sure that all taxonomies are registered
@@ -88,48 +91,28 @@ class Polylang_Admin_Filters extends Polylang_Base {
88
  add_action('personal_options_update', array(&$this, 'personal_options_update'));
89
  add_action('personal_options', array(&$this, 'personal_options'));
90
 
91
- // set text direction if the user set its own language
92
- global $wpdb, $wp_locale;
93
- $lang_id = $wpdb->get_var($wpdb->prepare("SELECT t.term_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id
94
- WHERE tt.taxonomy = 'language' AND tt.description = %s LIMIT 1", get_locale())); // no function exists to get term by description
95
- if ($lang_id)
96
- $wp_locale->text_direction = get_metadata('term', $lang_id, '_rtl', true) ? 'rtl' : 'ltr';
97
-
98
  //modifies posts and terms links when needed
99
  $this->add_post_term_link_filters();
100
  }
101
 
102
- // setup js scripts & css styles (only on the relevant pages)
103
- function admin_enqueue_scripts() {
104
- $screen = get_current_screen();
 
 
105
 
106
- // FIXME keep the script in header to be sure it is loaded before post.js otherwise a non filtered tag cloud appears in tag cloud metabox
107
- if ($screen->base == 'settings_page_mlang' || $screen->base == 'post' || $screen->base == 'edit-tags')
108
- wp_enqueue_script('polylang_admin', POLYLANG_URL .'/js/admin.js', array('jquery', 'wp-ajax-response'), POLYLANG_VERSION);
109
 
110
- if ($screen->base == 'settings_page_mlang' || $screen->base == 'post' || $screen->base == 'edit-tags' || $screen->base == 'edit')
111
- wp_enqueue_style('polylang_admin', POLYLANG_URL .'/css/admin.css', array(), POLYLANG_VERSION);
112
 
113
- if ($screen->base == 'settings_page_mlang') {
114
- wp_enqueue_script('postbox');
115
- }
116
  }
117
 
118
  // adds the language and translations columns (before the comments column) in the posts and pages list table
119
  function add_post_column($columns, $post_type ='') {
120
- if ($post_type == '' || in_array($post_type, $this->post_types)) {
121
- if ($n = array_search('comments', array_keys($columns))) {
122
- $end = array_slice($columns, $n);
123
- $columns = array_slice($columns, 0, $n);
124
- }
125
-
126
- foreach ($this->get_languages_list() as $language)
127
- $columns['language_'.$language->slug] = ($flag = $this->get_flag($language)) ? $flag : esc_html($language->slug);
128
-
129
- if (isset($end))
130
- $columns = array_merge($columns, $end);
131
- }
132
- return $columns;
133
  }
134
 
135
  // fills the language and translations columns in the posts table
@@ -137,7 +120,6 @@ class Polylang_Admin_Filters extends Polylang_Base {
137
  if (false === strpos($column, 'language_') || !$this->get_post_language($post_id))
138
  return;
139
 
140
- global $post_type;
141
  $language = $this->get_language(substr($column, 9));
142
 
143
  // link to edit post (or a translation)
@@ -152,16 +134,15 @@ class Polylang_Admin_Filters extends Polylang_Base {
152
  else
153
  printf('<a class="pll_icon_add" title="%1$s" href="%2$s"></a>',
154
  __('Add new translation', 'polylang'),
155
- esc_url(admin_url('post-new.php?post_type=' . $post_type . '&from_post=' . $post_id . '&new_lang=' . $language->slug))
156
  );
157
  }
158
 
159
  // converts language term_id to slug in $query
160
  // needed to filter the posts by language with wp_dropdown_categories in restrict_manage_posts
161
  function parse_query($query) {
162
- global $pagenow;
163
  $qvars = &$query->query_vars;
164
- if ($pagenow=='edit.php' && isset($qvars['lang']) && $qvars['lang'] && is_numeric($qvars['lang']) && $lang = $this->get_language($qvars['lang']))
165
  $qvars['lang'] = $lang->slug;
166
  }
167
 
@@ -169,9 +150,8 @@ class Polylang_Admin_Filters extends Polylang_Base {
169
  function restrict_manage_posts() {
170
  global $wp_query;
171
  $screen = get_current_screen(); // since WP 3.1
172
- $languages = $this->get_languages_list();
173
 
174
- if (!empty($languages) && $screen->base == 'edit') {
175
  $qvars = $wp_query->query;
176
  wp_dropdown_categories(array(
177
  'show_option_all' => __('Show all languages', 'polylang'),
@@ -215,7 +195,6 @@ class Polylang_Admin_Filters extends Polylang_Base {
215
  global $post_ID; // obliged to use the global variable for wp_popular_terms_checklist
216
  $post_ID = $_POST['post_id'];
217
  $post_type = get_post_type($post_ID);
218
- $listlanguages = $this->get_languages_list();
219
  $lang = $this->get_language($_POST['lang']);
220
 
221
  ob_start();
@@ -327,15 +306,18 @@ class Polylang_Admin_Filters extends Polylang_Base {
327
  return $post_parent;
328
  }
329
 
330
- // copy page template and menu order if exist when using "Add new" (translation)
331
  // the hook was probably not intended for that but did not find a better one
332
  // copy the meta '_wp_page_template' in save_post is not sufficient (the dropdown list in the metabox is not updated)
333
- // We need to set $post->page_template (ans so need to wait for the availability of $post)
334
  function dbx_post_advanced() {
335
  if (isset($_GET['from_post']) && isset($_GET['new_lang'])) {
336
  global $post;
337
- $post->menu_order = get_post($_GET['from_post'])->menu_order;
338
  $post->page_template = get_post_meta($_GET['from_post'], '_wp_page_template', true);
 
 
 
 
339
  }
340
  }
341
 
@@ -458,10 +440,9 @@ class Polylang_Admin_Filters extends Polylang_Base {
458
  }
459
 
460
  // post parent
 
461
  global $wpdb;
462
  $post_parent = ($parent_id = wp_get_post_parent_id($post_id)) ? $this->get_translation('post', $parent_id, $lang) : 0;
463
-
464
- // do not udpate the translation parent if the user set a parent with no translation
465
  if (!($parent_id && !$post_parent))
466
  $wpdb->update($wpdb->posts, array('post_parent'=> $post_parent), array( 'ID' => $tr_id ));
467
  }
@@ -508,8 +489,6 @@ class Polylang_Admin_Filters extends Polylang_Base {
508
  if (isset($_POST['action']) && $_POST['action'] == 'term_lang_choice' && !isset($args['class']))
509
  return $clauses;
510
 
511
- global $post_ID;
512
-
513
  // ajax response for changing the language in the post metabox (or in the edit-tags panels)
514
  if (isset($_POST['lang']))
515
  $lang = $this->get_language($_POST['lang']);
@@ -541,10 +520,7 @@ class Polylang_Admin_Filters extends Polylang_Base {
541
  function add_term_form() {
542
  $taxonomy = $_GET['taxonomy'];
543
 
544
- if (isset($_GET['new_lang']))
545
- $lang = $this->get_language($_GET['new_lang']);
546
- else
547
- $lang = $this->get_language($this->options['default_lang']);
548
 
549
  printf("<div class='form-field'><label for='term_lang_choice'>%s</label>\n%s<p>%s</p>\n</div>",
550
  __('Language', 'polylang'),
@@ -577,21 +553,12 @@ class Polylang_Admin_Filters extends Polylang_Base {
577
  echo "</tr>\n";
578
  }
579
 
580
- // adds the language column (before the posts column) in the 'Categories' or Post Tags table
581
  function add_term_column($columns) {
582
- if (array_key_exists('posts', $columns))
583
- $end = array_pop($columns);
584
-
585
- foreach ($this->get_languages_list() as $language)
586
- $columns['language_'.$language->slug] = ($flag = $this->get_flag($language)) ? $flag : esc_html($language->slug);
587
-
588
- if (isset($end))
589
- $columns['posts'] = $end;
590
-
591
- return $columns;
592
  }
593
 
594
- // fills the language column in the 'Categories' or Post Tags table
595
  function term_column($empty, $column, $term_id) {
596
  if (false === strpos($column, 'language_') || !$this->get_term_language($term_id))
597
  return;
@@ -722,8 +689,6 @@ class Polylang_Admin_Filters extends Polylang_Base {
722
  $term_id = isset($_POST['term_id']) ? $_POST['term_id'] : null;
723
  $taxonomy = $_POST['taxonomy'];
724
 
725
- $listlanguages = $this->get_languages_list();
726
-
727
  ob_start();
728
  if ($lang && !is_wp_error($lang))
729
  include(PLL_INC.'/term-translations.php');
@@ -791,15 +756,6 @@ class Polylang_Admin_Filters extends Polylang_Base {
791
  return $instance;
792
  }
793
 
794
- // returns the locale based on user preference
795
- function get_locale($locale) {
796
- // get_current_user_id uses wp_get_current_user which may not be available the first time(s) get_locale is called
797
- if (function_exists('wp_get_current_user'))
798
- $loc = get_user_meta(get_current_user_id(), 'user_lang', 'true');
799
-
800
- return isset($loc) && $loc ? $loc : $locale;
801
- }
802
-
803
  // updates language user preference
804
  function personal_options_update($user_id) {
805
  update_user_meta($user_id, 'user_lang', $_POST['user_lang']);
@@ -814,10 +770,22 @@ class Polylang_Admin_Filters extends Polylang_Base {
814
  );
815
  }
816
 
817
- // refresh rewrite rules if the 'page_on_front' option is modified
818
- function update_option_page_on_front() {
819
- $GLOBALS['wp_rewrite']->flush_rules();
 
 
820
  }
821
- }
 
 
 
 
 
 
 
 
 
 
822
 
823
  ?>
1
  <?php
2
 
3
  // all modifications of the WordPress admin ui
4
+ class Polylang_Admin_Filters extends Polylang_Admin_Base {
5
 
6
  function __construct() {
7
  parent::__construct();
8
 
9
  // additionnal filters and actions
10
  add_action('admin_init', array(&$this, 'admin_init'));
 
 
 
 
 
11
 
12
  // remove the customize menu section as it is unusable with Polylang
13
  add_action('customize_register', array(&$this, 'customize_register'), 20); // since WP 3.4
14
 
15
  // refresh rewrite rules if the 'page_on_front' option is modified
16
+ add_action('update_option_page_on_front', array(&$this, 'flush_rewrite_rules'));
17
+
18
+ // adds a 'settings' link in the plugins table
19
+ $plugin_file = basename(POLYLANG_DIR).'/polylang.php';
20
+ add_filter('plugin_action_links_'.$plugin_file, array(&$this, 'plugin_action_links'));
21
+
22
+ // ugrades languages files after a core upgrade (timing is important)
23
+ // FIXME private action ? is there a better way to do this ?
24
+ add_action( '_core_updated_successfully', array(&$this, 'upgrade_languages'), 1); // since WP 3.3
25
  }
26
 
27
  // add these actions and filters here and not in the constructor to be sure that all taxonomies are registered
91
  add_action('personal_options_update', array(&$this, 'personal_options_update'));
92
  add_action('personal_options', array(&$this, 'personal_options'));
93
 
 
 
 
 
 
 
 
94
  //modifies posts and terms links when needed
95
  $this->add_post_term_link_filters();
96
  }
97
 
98
+ function add_column($columns, $before) {
99
+ if ($n = array_search($before, array_keys($columns))) {
100
+ $end = array_slice($columns, $n);
101
+ $columns = array_slice($columns, 0, $n);
102
+ }
103
 
104
+ foreach ($this->get_languages_list() as $language)
105
+ $columns['language_'.$language->slug] = ($flag = $this->get_flag($language)) ? $flag : esc_html($language->slug);
 
106
 
107
+ if (isset($end))
108
+ $columns = array_merge($columns, $end);
109
 
110
+ return $columns;
 
 
111
  }
112
 
113
  // adds the language and translations columns (before the comments column) in the posts and pages list table
114
  function add_post_column($columns, $post_type ='') {
115
+ return $post_type == '' || in_array($post_type, $this->post_types) ? $this->add_column($columns, 'comments') : $columns;
 
 
 
 
 
 
 
 
 
 
 
 
116
  }
117
 
118
  // fills the language and translations columns in the posts table
120
  if (false === strpos($column, 'language_') || !$this->get_post_language($post_id))
121
  return;
122
 
 
123
  $language = $this->get_language(substr($column, 9));
124
 
125
  // link to edit post (or a translation)
134
  else
135
  printf('<a class="pll_icon_add" title="%1$s" href="%2$s"></a>',
136
  __('Add new translation', 'polylang'),
137
+ esc_url(admin_url('post-new.php?post_type=' . $GLOBALS['post_type'] . '&from_post=' . $post_id . '&new_lang=' . $language->slug))
138
  );
139
  }
140
 
141
  // converts language term_id to slug in $query
142
  // needed to filter the posts by language with wp_dropdown_categories in restrict_manage_posts
143
  function parse_query($query) {
 
144
  $qvars = &$query->query_vars;
145
+ if ($GLOBALS['pagenow']=='edit.php' && isset($qvars['lang']) && $qvars['lang'] && is_numeric($qvars['lang']) && $lang = $this->get_language($qvars['lang']))
146
  $qvars['lang'] = $lang->slug;
147
  }
148
 
150
  function restrict_manage_posts() {
151
  global $wp_query;
152
  $screen = get_current_screen(); // since WP 3.1
 
153
 
154
+ if ($screen->base == 'edit') {
155
  $qvars = $wp_query->query;
156
  wp_dropdown_categories(array(
157
  'show_option_all' => __('Show all languages', 'polylang'),
195
  global $post_ID; // obliged to use the global variable for wp_popular_terms_checklist
196
  $post_ID = $_POST['post_id'];
197
  $post_type = get_post_type($post_ID);
 
198
  $lang = $this->get_language($_POST['lang']);
199
 
200
  ob_start();
306
  return $post_parent;
307
  }
308
 
309
+ // copy page template, menu order, comment and ping status when using "Add new" (translation)
310
  // the hook was probably not intended for that but did not find a better one
311
  // copy the meta '_wp_page_template' in save_post is not sufficient (the dropdown list in the metabox is not updated)
312
+ // We need to set $post->page_template (and so need to wait for the availability of $post)
313
  function dbx_post_advanced() {
314
  if (isset($_GET['from_post']) && isset($_GET['new_lang'])) {
315
  global $post;
 
316
  $post->page_template = get_post_meta($_GET['from_post'], '_wp_page_template', true);
317
+
318
+ $from_post = get_post($_GET['from_post']);
319
+ foreach (array('menu_order', 'comment_status', 'ping_status') as $property)
320
+ $post->$property = $from_post->$property;
321
  }
322
  }
323
 
440
  }
441
 
442
  // post parent
443
+ // do not udpate the translation parent if the user set a parent with no translation
444
  global $wpdb;
445
  $post_parent = ($parent_id = wp_get_post_parent_id($post_id)) ? $this->get_translation('post', $parent_id, $lang) : 0;
 
 
446
  if (!($parent_id && !$post_parent))
447
  $wpdb->update($wpdb->posts, array('post_parent'=> $post_parent), array( 'ID' => $tr_id ));
448
  }
489
  if (isset($_POST['action']) && $_POST['action'] == 'term_lang_choice' && !isset($args['class']))
490
  return $clauses;
491
 
 
 
492
  // ajax response for changing the language in the post metabox (or in the edit-tags panels)
493
  if (isset($_POST['lang']))
494
  $lang = $this->get_language($_POST['lang']);
520
  function add_term_form() {
521
  $taxonomy = $_GET['taxonomy'];
522
 
523
+ $lang = isset($_GET['new_lang']) ? $this->get_language($_GET['new_lang']) : $this->get_language($this->options['default_lang']);
 
 
 
524
 
525
  printf("<div class='form-field'><label for='term_lang_choice'>%s</label>\n%s<p>%s</p>\n</div>",
526
  __('Language', 'polylang'),
553
  echo "</tr>\n";
554
  }
555
 
556
+ // adds the language column (before the posts column) in the 'Categories' or 'Post Tags' table
557
  function add_term_column($columns) {
558
+ return $this->add_column($columns, 'posts');
 
 
 
 
 
 
 
 
 
559
  }
560
 
561
+ // fills the language column in the 'Categories' or 'Post Tags' table
562
  function term_column($empty, $column, $term_id) {
563
  if (false === strpos($column, 'language_') || !$this->get_term_language($term_id))
564
  return;
689
  $term_id = isset($_POST['term_id']) ? $_POST['term_id'] : null;
690
  $taxonomy = $_POST['taxonomy'];
691
 
 
 
692
  ob_start();
693
  if ($lang && !is_wp_error($lang))
694
  include(PLL_INC.'/term-translations.php');
756
  return $instance;
757
  }
758
 
 
 
 
 
 
 
 
 
 
759
  // updates language user preference
760
  function personal_options_update($user_id) {
761
  update_user_meta($user_id, 'user_lang', $_POST['user_lang']);
770
  );
771
  }
772
 
773
+ // adds a 'settings' link in the plugins table
774
+ function plugin_action_links($links) {
775
+ $settings_link = '<a href="admin.php?page=mlang">' . __('Settings') . '</a>';
776
+ array_unshift( $links, $settings_link );
777
+ return $links;
778
  }
779
+
780
+ // ugrades languages files after a core upgrade
781
+ function upgrade_languages($version) {
782
+ apply_filters('update_feedback', __('Upgrading language files&#8230;', 'polylang'));
783
+ foreach ($this->get_languages_list() as $language) {
784
+ if ($language->description != $_POST['locale']) // do not (re)update the language files of a localized WordPress
785
+ $this->download_mo($language->description, $version);
786
+ }
787
+ }
788
+
789
+ } // class Polylang_Admin_Filters
790
 
791
  ?>
include/admin.php CHANGED
@@ -1,41 +1,12 @@
1
  <?php
2
 
3
- require_once(PLL_INC.'/admin-filters.php');
4
  require_once(PLL_INC.'/list-table.php');
5
 
6
- // setups the Polylang admin panel and calls for other admin related classes
7
- class Polylang_Admin extends Polylang_Base {
 
8
  function __construct() {
9
  parent::__construct();
10
- new Polylang_Admin_Filters();
11
-
12
- // adds a 'settings' link in the plugins table
13
- $plugin_file = basename(POLYLANG_DIR).'/polylang.php';
14
- add_filter('plugin_action_links_'.$plugin_file, array(&$this, 'plugin_action_links'));
15
-
16
- // adds the link to the languages panel in the wordpress admin menu
17
- add_action('admin_menu', array(&$this, 'add_menus'));
18
-
19
- // ugrades languages files after a core upgrade (timing is important)
20
- // FIXME private action ? is there a better way to do this ?
21
- add_action( '_core_updated_successfully', array(&$this, 'upgrade_languages'), 1); // since WP 3.3
22
- }
23
-
24
- // adds a 'settings' link in the plugins table
25
- function plugin_action_links($links) {
26
- $settings_link = '<a href="admin.php?page=mlang">' . __('Settings') . '</a>';
27
- array_unshift( $links, $settings_link );
28
- return $links;
29
- }
30
-
31
- // adds the link to the languages panel in the wordpress admin menu
32
- function add_menus() {
33
- add_submenu_page('options-general.php', __('Languages', 'polylang'), __('Languages', 'polylang'), 'manage_options', 'mlang', array(&$this, 'languages_page'));
34
-
35
- // adds the about box the languages admin panel
36
- // test of $_GET['tab'] avoids displaying the automatically generated screen options on other tabs
37
- if (PLL_DISPLAY_ABOUT && (!isset($_GET['tab']) || $_GET['tab'] == 'lang'))
38
- add_meta_box('pll_about_box', __('About Polylang', 'polylang'), array(&$this,'about'), 'settings_page_mlang', 'normal', 'high');
39
  }
40
 
41
  // displays the about metabox
@@ -70,7 +41,6 @@ class Polylang_Admin extends Polylang_Base {
70
 
71
  // the languages panel
72
  function languages_page() {
73
- global $wp_rewrite;
74
  $options = get_option('polylang');
75
 
76
  // for nav menus form
@@ -98,7 +68,7 @@ class Polylang_Admin extends Polylang_Base {
98
  update_option('polylang', $options);
99
  }
100
 
101
- $wp_rewrite->flush_rules(); // refresh rewrite rules
102
 
103
  if (!$this->download_mo($_POST['description']))
104
  $error = 5;
@@ -157,7 +127,7 @@ class Polylang_Admin extends Polylang_Base {
157
  unset($options['default_lang']);
158
  update_option('polylang', $options);
159
 
160
- $wp_rewrite->flush_rules(); // refresh rewrite rules
161
  }
162
  }
163
  wp_redirect('admin.php?page=mlang'); // to refresh the page (possible thanks to the $_GET['noheader']=true)
@@ -218,7 +188,7 @@ class Polylang_Admin extends Polylang_Base {
218
  wp_update_term($lang_id, 'language', $args);
219
  update_metadata('term', $lang_id, '_rtl', $_POST['rtl']);
220
 
221
- $wp_rewrite->flush_rules(); // refresh rewrite rules
222
  }
223
 
224
  wp_redirect('admin.php?page=mlang'. ($error ? '&error='.$error : '') ); // to refresh the page (possible thanks to the $_GET['noheader']=true)
@@ -268,7 +238,7 @@ class Polylang_Admin extends Polylang_Base {
268
 
269
  // refresh rewrite rules in case rewrite or hide_default options have been modified
270
  // it seems useless to refresh permastruct here
271
- $wp_rewrite->flush_rules();
272
 
273
  // fills existing posts & terms with default language
274
  if (isset($_POST['fill_languages'])) {
@@ -415,98 +385,6 @@ class Polylang_Admin extends Polylang_Base {
415
  return empty($posts) && empty($terms) ? false : array('posts' => $posts, 'terms' => $terms);
416
  }
417
 
418
- // downloads mofiles
419
- function download_mo($locale, $upgrade = false) {
420
- global $wp_version;
421
- $mofile = WP_LANG_DIR."/$locale.mo";
422
-
423
- // does file exists ?
424
- if ((file_exists($mofile) && !$upgrade) || $locale == 'en_US')
425
- return true;
426
-
427
- // does language directory exists ?
428
- if (!is_dir(WP_LANG_DIR)) {
429
- if (!@mkdir(WP_LANG_DIR))
430
- return false;
431
- }
432
-
433
- // will first look in tags/ (most languages) then in branches/ (only Greek ?)
434
- $base = 'http://svn.automattic.com/wordpress-i18n/'.$locale;
435
- $bases = array($base.'/tags/', $base.'/branches/');
436
-
437
- foreach ($bases as $base) {
438
- // get all the versions available in the subdirectory
439
- $resp = wp_remote_get($base);
440
- if (is_wp_error($resp) || 200 != $resp['response']['code'])
441
- continue;
442
-
443
- preg_match_all('#>([0-9\.]+)\/#', $resp['body'], $matches);
444
- if (empty($matches[1]))
445
- continue;
446
-
447
- rsort($matches[1]); // sort from newest to oldest
448
- $versions = $matches[1];
449
-
450
- $newest = $upgrade ? $upgrade : $wp_version;
451
- foreach ($versions as $key=>$version) {
452
- // will not try to download a too recent mofile
453
- if (version_compare($version, $newest, '>'))
454
- unset($versions[$key]);
455
- // will not download an older version if we are upgrading
456
- if ($upgrade && version_compare($version, $wp_version, '<='))
457
- unset($versions[$key]);
458
- }
459
-
460
- $versions = array_splice($versions, 0, 5); // reduce the number of versions to test to 5
461
- $args = array('timeout' => 30, 'stream' => true);
462
-
463
- // try to download the file
464
- foreach ($versions as $version) {
465
- $resp = wp_remote_get($base."$version/messages/$locale.mo", $args + array('filename' => $mofile));
466
- if (is_wp_error($resp) || 200 != $resp['response']['code'])
467
- continue;
468
-
469
- // try to download ms and continents-cities files if exist (will not return false if failed)
470
- // with new files introduced in WP 3.4
471
- foreach (array("ms", "continent-cities", "admin", "admin-network") as $file)
472
- wp_remote_get($base."$version/messages/$file-$locale.mo", $args + array('filename' => WP_LANG_DIR."/$file-$locale.mo"));
473
-
474
- // try to download theme files if exist (will not return false if failed)
475
- // FIXME not updated when the theme is updated outside a core update
476
- foreach (array("twentyten", "twentyeleven", "twentytwelve") as $theme)
477
- wp_remote_get($base."$version/messages/$theme/$locale.mo", $args + array('filename' => get_theme_root()."/$theme/languages/$locale.mo"));
478
-
479
- return true;
480
- }
481
- }
482
- // we did not succeeded to download a file :(
483
- return false;
484
- }
485
-
486
- // ugrades languages files after a core upgrade
487
- function upgrade_languages($version) {
488
- apply_filters('update_feedback', __('Upgrading language files&#8230;', 'polylang'));
489
- foreach ($this->get_languages_list() as $language) {
490
- if ($language->description != $_POST['locale']) // do not (re)update the language files of a localized WordPress
491
- $this->download_mo($language->description, $version);
492
- }
493
- }
494
-
495
- // returns options available for the language switcher (menu or widget)
496
- // FIXME do not include the dropdown in menu yet since I need to work on js
497
- function get_switcher_options($type = 'widget', $key ='string') {
498
- $options = array (
499
- 'show_names' => array('string' => __('Displays language names', 'polylang'), 'default' => 1),
500
- 'show_flags' => array('string' => __('Displays flags', 'polylang'), 'default' => 0),
501
- 'force_home' => array('string' => __('Forces link to front page', 'polylang'), 'default' => 0),
502
- 'hide_current' => array('string' => __('Hides the current language', 'polylang'), 'default' => 0),
503
- );
504
- $menu_options = array('switcher' => array('string' => __('Displays a language switcher at the end of the menu', 'polylang'), 'default' => 0));
505
- $widget_options = array('dropdown' => array('string' => __('Displays as dropdown', 'polylang'), 'default' => 0));
506
- $options = ($type == 'menu') ? array_merge($menu_options, $options) : array_merge($options, $widget_options);
507
- return array_map(create_function('$v', "return \$v['$key'];"), $options);
508
- }
509
-
510
  function &get_strings() {
511
  global $wp_registered_widgets;
512
 
1
  <?php
2
 
 
3
  require_once(PLL_INC.'/list-table.php');
4
 
5
+ // setups the Polylang admin panel
6
+ class Polylang_Admin extends Polylang_Admin_Base {
7
+
8
  function __construct() {
9
  parent::__construct();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  }
11
 
12
  // displays the about metabox
41
 
42
  // the languages panel
43
  function languages_page() {
 
44
  $options = get_option('polylang');
45
 
46
  // for nav menus form
68
  update_option('polylang', $options);
69
  }
70
 
71
+ flush_rewrite_rules(); // refresh rewrite rules
72
 
73
  if (!$this->download_mo($_POST['description']))
74
  $error = 5;
127
  unset($options['default_lang']);
128
  update_option('polylang', $options);
129
 
130
+ flush_rewrite_rules(); // refresh rewrite rules
131
  }
132
  }
133
  wp_redirect('admin.php?page=mlang'); // to refresh the page (possible thanks to the $_GET['noheader']=true)
188
  wp_update_term($lang_id, 'language', $args);
189
  update_metadata('term', $lang_id, '_rtl', $_POST['rtl']);
190
 
191
+ flush_rewrite_rules(); // refresh rewrite rules
192
  }
193
 
194
  wp_redirect('admin.php?page=mlang'. ($error ? '&error='.$error : '') ); // to refresh the page (possible thanks to the $_GET['noheader']=true)
238
 
239
  // refresh rewrite rules in case rewrite or hide_default options have been modified
240
  // it seems useless to refresh permastruct here
241
+ flush_rewrite_rules();
242
 
243
  // fills existing posts & terms with default language
244
  if (isset($_POST['fill_languages'])) {
385
  return empty($posts) && empty($terms) ? false : array('posts' => $posts, 'terms' => $terms);
386
  }
387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
  function &get_strings() {
389
  global $wp_registered_widgets;
390
 
include/api.php CHANGED
@@ -26,10 +26,9 @@ function pll_get_term($term_id, $slug = false) {
26
  return isset($polylang) && $slug ? $polylang->get_term($term_id, $slug) : null;
27
  }
28
 
29
- // acts as is_front_page but knows about translated front page
30
  function pll_is_front_page() {
31
- global $polylang;
32
- return isset($polylang) ? $polylang->is_front_page() : is_front_page();
33
  }
34
 
35
  // returns the home url in the right language
@@ -41,7 +40,7 @@ function pll_home_url() {
41
  // register strings for translation in the "strings translation" panel
42
  function pll_register_string($name, $string) {
43
  global $polylang;
44
- if (isset($polylang))
45
  $polylang->register_string($name, $string);
46
  }
47
 
26
  return isset($polylang) && $slug ? $polylang->get_term($term_id, $slug) : null;
27
  }
28
 
29
+ // deprecated in 0.8.2 as it is now useless
30
  function pll_is_front_page() {
31
+ return is_front_page();
 
32
  }
33
 
34
  // returns the home url in the right language
40
  // register strings for translation in the "strings translation" panel
41
  function pll_register_string($name, $string) {
42
  global $polylang;
43
+ if (isset($polylang) && is_admin())
44
  $polylang->register_string($name, $string);
45
  }
46
 
include/base.php CHANGED
@@ -233,13 +233,6 @@ abstract class Polylang_Base {
233
  return get_posts($q);
234
  }
235
 
236
- // register strings for translation making sure it is not duplicate
237
- function register_string($name, $string) {
238
- $to_register = array('name'=> $name, 'string' => $string);
239
- if (!in_array($to_register, $this->strings))
240
- $this->strings[] = $to_register;
241
- }
242
-
243
  // export a mo object in options
244
  function mo_export($mo, $lang) {
245
  $strings = array();
233
  return get_posts($q);
234
  }
235
 
 
 
 
 
 
 
 
236
  // export a mo object in options
237
  function mo_export($mo, $lang) {
238
  $strings = array();
include/core.php CHANGED
@@ -93,12 +93,6 @@ class Polylang_Core extends Polylang_base {
93
  add_filter('bloginfo', array(&$this, 'bloginfo'), 1, 2);
94
  add_filter('get_bloginfo_rss', array(&$this, 'bloginfo'), 1, 2);
95
 
96
- // loads front page template on translated front page
97
- add_filter('template_include', array(&$this, 'template_include'));
98
-
99
- // add home class to body classes on translated frontpage
100
- add_filter('body_class', array(&$this, 'body_class'));
101
-
102
  // modifies the home url
103
  if (PLL_FILTER_HOME_URL)
104
  add_filter('home_url', array(&$this, 'home_url'));
@@ -198,42 +192,54 @@ class Polylang_Core extends Polylang_base {
198
  // as done by xili_language and here: load text domains and reinitialize wp_locale with the action 'wp'
199
  // as done by qtranslate: define the locale with the action 'plugins_loaded', but in this case, the language must be specified in the url.
200
  function load_textdomains() {
201
- // sets the current language
202
- if (!($this->curlang = $this->get_current_language()))
203
- return; // something went wrong
204
-
205
- // set a cookie to remember the language. check headers have not been sent to avoid ugly error
206
- if (!headers_sent())
207
- setcookie('wordpress_polylang', $this->curlang->slug, time() + 31536000 /* 1 year */, COOKIEPATH, COOKIE_DOMAIN);
208
-
209
- // set all our language filters and actions
210
- $this->add_language_filters();
211
 
212
  // our override_load_textdomain filter has done its job. let's remove it before calling load_textdomain
213
  remove_filter('override_load_textdomain', array(&$this, 'mofile'));
214
 
215
- // now we can load text domains with the right language
216
- $new_locale = get_locale();
217
- foreach ($this->list_textdomains as $textdomain)
218
- load_textdomain( $textdomain['domain'], str_replace($this->default_locale, $new_locale, $textdomain['mo']));
 
 
219
 
220
- // and finally load user defined strings
221
- global $l10n;
222
- $l10n['pll_string'] = $this->mo_import($this->curlang);
223
 
224
- // reinitializes wp_locale for weekdays and months, as well as for text direction
225
- global $wp_locale;
226
- $wp_locale->init();
227
- $wp_locale->text_direction = get_metadata('term', $this->curlang->term_id, '_rtl', true) ? 'rtl' : 'ltr';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
 
230
  // filters posts according to the language
231
  function pre_get_posts($query) {
 
 
 
 
232
  $qvars = $query->query_vars;
233
 
234
  // detect our exclude pages query and returns to avoid conflicts
235
  // this test should be sufficient
236
- if (isset($qvars['tax_query'][0]['taxonomy']) && $qvars['tax_query'][0]['taxonomy'] == 'language' && isset($qvars['tax_query'][0]['operator']))
 
237
  return;
238
 
239
  // homepage is requested, let's set the language
@@ -527,7 +533,7 @@ class Polylang_Core extends Polylang_base {
527
  }
528
 
529
  elseif (is_home() || is_tax('language') )
530
- $url = $hide ? $this->home : get_term_link($language, 'language');
531
 
532
  return isset($url) ? $url : null;
533
  }
@@ -584,25 +590,6 @@ class Polylang_Core extends Polylang_base {
584
  return isset($this->curlang) && $value ? $this->get_post($value, $this->curlang) : $value;
585
  }
586
 
587
- // acts as is_front_page but knows about translated front page
588
- function is_front_page() {
589
- return ('posts' == get_option('show_on_front') && is_home()) ||
590
- ('page' == get_option('show_on_front') && $this->page_on_front && is_page($this->get_post($this->page_on_front, $this->get_current_language()))) ||
591
- (is_tax('language') && !is_archive());
592
- }
593
-
594
- // loads front page template on translated front page
595
- function template_include($template) {
596
- return ($this->is_front_page() && $front_page = get_front_page_template()) ? $front_page : $template;
597
- }
598
-
599
- // add home class to body classes on translated frontpage
600
- function body_class($classes) {
601
- if ($this->is_front_page() && !is_front_page())
602
- array_unshift($classes, 'home');
603
- return $classes;
604
- }
605
-
606
  // filters the home url to get the right language
607
  function home_url($url) {
608
  if (!did_action('template_redirect') || rtrim($url,'/') != $this->home)
@@ -615,9 +602,8 @@ class Polylang_Core extends Polylang_base {
615
  (isset($trace['file']) && !strpos($trace['file'], 'searchform.php') && strpos($trace['file'], $theme) !== false &&
616
  in_array($trace['function'], array('home_url', 'bloginfo', 'get_bloginfo')) );
617
 
618
- if ($ok) {
619
  return $this->get_home_url($this->curlang);
620
- }
621
  }
622
 
623
  return $url;
@@ -633,9 +619,7 @@ class Polylang_Core extends Polylang_base {
633
 
634
  // a static page is used as front page : /!\ don't use get_page_link to avoid infinite loop
635
  if ($this->page_on_front && $id = $this->get_post($this->page_on_front, $language))
636
- return $this->options['force_lang'] && !$this->options['redirect_lang'] && $GLOBALS['wp_rewrite']->using_permalinks() ?
637
- $this->add_language_to_link($this->page_link('', $id), $this->curlang) :
638
- $this->page_link('', $id);
639
 
640
  return get_term_link($language, 'language');
641
  }
93
  add_filter('bloginfo', array(&$this, 'bloginfo'), 1, 2);
94
  add_filter('get_bloginfo_rss', array(&$this, 'bloginfo'), 1, 2);
95
 
 
 
 
 
 
 
96
  // modifies the home url
97
  if (PLL_FILTER_HOME_URL)
98
  add_filter('home_url', array(&$this, 'home_url'));
192
  // as done by xili_language and here: load text domains and reinitialize wp_locale with the action 'wp'
193
  // as done by qtranslate: define the locale with the action 'plugins_loaded', but in this case, the language must be specified in the url.
194
  function load_textdomains() {
 
 
 
 
 
 
 
 
 
 
195
 
196
  // our override_load_textdomain filter has done its job. let's remove it before calling load_textdomain
197
  remove_filter('override_load_textdomain', array(&$this, 'mofile'));
198
 
199
+ // check there is at least one language defined and sets the current language
200
+ if ($this->get_languages_list() && $this->curlang = $this->get_current_language()) {
201
+
202
+ // set a cookie to remember the language. check headers have not been sent to avoid ugly error
203
+ if (!headers_sent())
204
+ setcookie('wordpress_polylang', $this->curlang->slug, time() + 31536000 /* 1 year */, COOKIEPATH, COOKIE_DOMAIN);
205
 
206
+ // set all our language filters and actions
207
+ $this->add_language_filters();
 
208
 
209
+ // now we can load text domains with the right language
210
+ $new_locale = get_locale();
211
+ foreach ($this->list_textdomains as $textdomain)
212
+ load_textdomain( $textdomain['domain'], str_replace($this->default_locale, $new_locale, $textdomain['mo']));
213
+
214
+ // and finally load user defined strings
215
+ global $l10n;
216
+ $l10n['pll_string'] = $this->mo_import($this->curlang);
217
+
218
+ // reinitializes wp_locale for weekdays and months, as well as for text direction
219
+ global $wp_locale;
220
+ $wp_locale->init();
221
+ $wp_locale->text_direction = get_metadata('term', $this->curlang->term_id, '_rtl', true) ? 'rtl' : 'ltr';
222
+ }
223
+
224
+ else {
225
+ // cant't work so load the text domains with WordPress default language
226
+ foreach ($this->list_textdomains as $textdomain)
227
+ load_textdomain($textdomain['domain'], $textdomain['mo']);
228
+ }
229
  }
230
 
231
  // filters posts according to the language
232
  function pre_get_posts($query) {
233
+ // don't make anything if no language has been defined yet
234
+ if(!$this->get_languages_list())
235
+ return;
236
+
237
  $qvars = $query->query_vars;
238
 
239
  // detect our exclude pages query and returns to avoid conflicts
240
  // this test should be sufficient
241
+ if (isset($qvars['tax_query'][0]['taxonomy']) && $qvars['tax_query'][0]['taxonomy'] == 'language' &&
242
+ isset($qvars['tax_query'][0]['operator']) && $qvars['tax_query'][0]['operator'] == 'NOT IN')
243
  return;
244
 
245
  // homepage is requested, let's set the language
533
  }
534
 
535
  elseif (is_home() || is_tax('language') )
536
+ $url = $this->get_home_url($language, 'language');
537
 
538
  return isset($url) ? $url : null;
539
  }
590
  return isset($this->curlang) && $value ? $this->get_post($value, $this->curlang) : $value;
591
  }
592
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  // filters the home url to get the right language
594
  function home_url($url) {
595
  if (!did_action('template_redirect') || rtrim($url,'/') != $this->home)
602
  (isset($trace['file']) && !strpos($trace['file'], 'searchform.php') && strpos($trace['file'], $theme) !== false &&
603
  in_array($trace['function'], array('home_url', 'bloginfo', 'get_bloginfo')) );
604
 
605
+ if ($ok)
606
  return $this->get_home_url($this->curlang);
 
607
  }
608
 
609
  return $url;
619
 
620
  // a static page is used as front page : /!\ don't use get_page_link to avoid infinite loop
621
  if ($this->page_on_front && $id = $this->get_post($this->page_on_front, $language))
622
+ return $this->page_link('', $id);
 
 
623
 
624
  return get_term_link($language, 'language');
625
  }
include/term-translations.php CHANGED
@@ -50,7 +50,7 @@ else {
50
  // do not display the add new link in add term form ($term_id not set !!!)
51
  if (isset($term_id))
52
  printf('<td class="tr-edit-column"><a href="%1$s">%2$s</a></td>',
53
- esc_url(admin_url(sprintf('edit-tags.php?taxonomy=%1$s&from_tag=%2$d&new_lang=%3$s', $taxonomy, $term_id, $lang->slug))),
54
  __('Add new','polylang')
55
  );
56
  }
50
  // do not display the add new link in add term form ($term_id not set !!!)
51
  if (isset($term_id))
52
  printf('<td class="tr-edit-column"><a href="%1$s">%2$s</a></td>',
53
+ esc_url(admin_url(sprintf('edit-tags.php?taxonomy=%1$s&from_tag=%2$d&new_lang=%3$s', $taxonomy, $term_id, $language->slug))),
54
  __('Add new','polylang')
55
  );
56
  }
languages/polylang-it_IT.mo ADDED
Binary file
languages/polylang-it_IT.po ADDED
@@ -0,0 +1,418 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: polylang\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2012-02-21 20:50+0100\n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: Luca Barbetti <lucabarbetti@gmail.com>\n"
8
+ "Language-Team: Luca Barbetti <lucabarbetti@gmail.com>\n"
9
+ "Language: \n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=2: nplural=n>1\n"
14
+ "X-Poedit-SourceCharset: utf-8\n"
15
+ "X-Poedit-KeywordsList: _e;__;_x\n"
16
+ "X-Poedit-Basepath: .\n"
17
+ "X-Poedit-Language: Italian\n"
18
+ "X-Poedit-Country: ITALY\n"
19
+ "X-Poedit-SearchPath-0: ..\n"
20
+ "X-Poedit-SearchPath-1: ../include\n"
21
+
22
+ #: ../polylang.php:97
23
+ #, php-format
24
+ msgid "You are using WordPress %s. Polylang requires at least WordPress %s."
25
+ msgstr "Si sta utilizzando WordPress %s. Polylang richiede almeno WordPress %s."
26
+
27
+ #: ../polylang.php:111
28
+ msgid "For some reasons, Polylang could not create a table in your database."
29
+ msgstr "Per qualche ragione, Polylang non è stato in grado di creare una tabella nel database."
30
+
31
+ #: ../polylang.php:193
32
+ msgid "Error: Restore of local flags failed!"
33
+ msgstr "Errore: Ripristino delle bandiere locali fallito!"
34
+
35
+ #: ../polylang.php:194
36
+ #, php-format
37
+ msgid "Please move your local flags from %s to %s"
38
+ msgstr "Spostare le bandiere locali da %s a %s"
39
+
40
+ #: ../include/widget.php:6
41
+ msgid "Language Switcher"
42
+ msgstr "Selettore di lingua"
43
+
44
+ #: ../include/widget.php:6
45
+ msgid "Displays a language switcher"
46
+ msgstr "Visualizza un selettore di lingua"
47
+
48
+ #: ../include/widget.php:71
49
+ msgid "Title:"
50
+ msgstr "Titolo:"
51
+
52
+ #: ../include/admin.php:26
53
+ #: ../include/admin.php:300
54
+ msgid "Settings"
55
+ msgstr "Impostazioni"
56
+
57
+ #: ../include/admin.php:33
58
+ #: ../include/admin.php:292
59
+ #: ../include/admin-filters.php:187
60
+ #: ../include/list-table.php:13
61
+ msgid "Languages"
62
+ msgstr "Lingue"
63
+
64
+ #: ../include/admin.php:38
65
+ msgid "About Polylang"
66
+ msgstr "Informazioni su Polylang"
67
+
68
+ #: ../include/admin.php:297
69
+ msgid "Menus"
70
+ msgstr "Menu"
71
+
72
+ #: ../include/admin.php:299
73
+ #: ../include/list-table.php:104
74
+ msgid "Strings translation"
75
+ msgstr "Traduzione delle stringhe"
76
+
77
+ #: ../include/admin.php:318
78
+ msgid "Enter a valid WorPress locale"
79
+ msgstr "Inserire impostazioni locali valide per WordPress"
80
+
81
+ #: ../include/admin.php:319
82
+ msgid "The language code must be 2 characters long"
83
+ msgstr "Il codice della lingua deve essere lungo 2 caratteri"
84
+
85
+ #: ../include/admin.php:320
86
+ msgid "The language code must be unique"
87
+ msgstr "Il codice della lingua deve essere unico"
88
+
89
+ #: ../include/admin.php:321
90
+ msgid "The language must have a name"
91
+ msgstr "La lingua deve avere un nome"
92
+
93
+ #: ../include/admin.php:322
94
+ msgid "The language was created, but the WordPress language file was not downloaded. Please install it manually."
95
+ msgstr "La lingua è stata creata, ma il file della lingua di WordPress non è stato scaricato. Installarlo manualmente."
96
+
97
+ #: ../include/admin.php:475
98
+ msgid "Upgrading language files&#8230;"
99
+ msgstr "Aggiornamento dei file di lingua&#8230;"
100
+
101
+ #: ../include/admin.php:486
102
+ msgid "Displays language names"
103
+ msgstr "Visualizza i nomi delle lingue"
104
+
105
+ #: ../include/admin.php:487
106
+ msgid "Displays flags"
107
+ msgstr "Visualizza le bandiere"
108
+
109
+ #: ../include/admin.php:488
110
+ msgid "Forces link to front page"
111
+ msgstr "Forza il collegamento alla prima pagina"
112
+
113
+ #: ../include/admin.php:489
114
+ msgid "Hides the current language"
115
+ msgstr "Nascondi la lingua corrente"
116
+
117
+ #: ../include/admin.php:491
118
+ msgid "Displays a language switcher at the end of the menu"
119
+ msgstr "Visualizza un selettore di lingua alla fine del menu"
120
+
121
+ #: ../include/admin.php:492
122
+ msgid "Displays as dropdown"
123
+ msgstr "Visualizza come menu a discesa"
124
+
125
+ #: ../include/admin.php:501
126
+ msgid "Site Title"
127
+ msgstr "Titolo del sito"
128
+
129
+ #: ../include/admin.php:502
130
+ msgid "Tagline"
131
+ msgstr "Motto"
132
+
133
+ #: ../include/admin.php:520
134
+ msgid "Widget title"
135
+ msgstr "Titolo del widget"
136
+
137
+ #: ../include/term-translations.php:6
138
+ #: ../include/term-translations.php:11
139
+ #: ../include/list-table.php:127
140
+ msgid "Translations"
141
+ msgstr "Traduzioni"
142
+
143
+ #: ../include/term-translations.php:15
144
+ #: ../include/admin-filters.php:537
145
+ #: ../include/admin-filters.php:554
146
+ #: ../include/list-table.php:12
147
+ #: ../include/post-translations.php:4
148
+ msgid "Language"
149
+ msgstr "Lingua"
150
+
151
+ #: ../include/term-translations.php:16
152
+ msgid "Translation"
153
+ msgstr "Traduzione"
154
+
155
+ #: ../include/term-translations.php:18
156
+ #: ../include/term-translations.php:65
157
+ #: ../include/list-table.php:26
158
+ #: ../include/post-translations.php:6
159
+ #: ../include/post-translations.php:29
160
+ msgid "Edit"
161
+ msgstr "Modifica"
162
+
163
+ #: ../include/term-translations.php:48
164
+ msgid "No untranslated term"
165
+ msgstr "Tutti i termini sono tradotti"
166
+
167
+ #: ../include/term-translations.php:54
168
+ #: ../include/post-translations.php:34
169
+ msgid "Add new"
170
+ msgstr "Aggiungi nuovo"
171
+
172
+ #: ../include/admin-filters.php:151
173
+ #: ../include/admin-filters.php:600
174
+ msgid "Add new translation"
175
+ msgstr "Aggiungi nuova traduzione"
176
+
177
+ #: ../include/admin-filters.php:174
178
+ msgid "Show all languages"
179
+ msgstr "Mostra tutte le lingue"
180
+
181
+ #: ../include/admin-filters.php:204
182
+ msgid "Page's language:"
183
+ msgstr "Lingua della pagina"
184
+
185
+ #: ../include/admin-filters.php:204
186
+ msgid "Post's language:"
187
+ msgstr "Lingua dell'articolo"
188
+
189
+ #: ../include/admin-filters.php:263
190
+ msgid "(no parent)"
191
+ msgstr "(senza genitore)"
192
+
193
+ #: ../include/admin-filters.php:539
194
+ #: ../include/admin-filters.php:557
195
+ msgid "Sets the language"
196
+ msgstr "Imposta la lingua"
197
+
198
+ #: ../include/admin-filters.php:721
199
+ msgid "None"
200
+ msgstr "Nessuno"
201
+
202
+ #: ../include/admin-filters.php:738
203
+ msgid "Theme locations and languages"
204
+ msgstr "Posizione e lingua del tema"
205
+
206
+ #: ../include/admin-filters.php:743
207
+ #, php-format
208
+ msgid "Please go to the %slanguages page%s to set theme locations and languages"
209
+ msgstr "Andare alla %spagina delle lingue%s per impostare posizione e lingua del tema"
210
+
211
+ #: ../include/admin-filters.php:754
212
+ msgid "The widget is displayed for:"
213
+ msgstr "Il widget viene visualizzato per:"
214
+
215
+ #: ../include/admin-filters.php:785
216
+ msgid "Admin language"
217
+ msgstr "Lingua degli amministratori"
218
+
219
+ #: ../include/list-table.php:27
220
+ msgid "Delete"
221
+ msgstr "Cancella"
222
+
223
+ #: ../include/list-table.php:45
224
+ #: ../include/languages-form.php:70
225
+ msgid "Full name"
226
+ msgstr "Nome completo"
227
+
228
+ #: ../include/list-table.php:46
229
+ #: ../include/languages-form.php:76
230
+ msgid "Locale"
231
+ msgstr "Impostazioni locali"
232
+
233
+ #: ../include/list-table.php:47
234
+ msgid "Code"
235
+ msgstr "Codice"
236
+
237
+ #: ../include/list-table.php:48
238
+ #: ../include/languages-form.php:98
239
+ msgid "Order"
240
+ msgstr "Ordinamento"
241
+
242
+ #: ../include/list-table.php:49
243
+ msgid "Flag"
244
+ msgstr "Bandiera"
245
+
246
+ #: ../include/list-table.php:50
247
+ msgid "Posts"
248
+ msgstr "Articoli"
249
+
250
+ #: ../include/list-table.php:105
251
+ msgid "Strings translations"
252
+ msgstr "Traduzioni delle stringhe"
253
+
254
+ #: ../include/list-table.php:125
255
+ msgid "Name"
256
+ msgstr "Nome"
257
+
258
+ #: ../include/list-table.php:126
259
+ msgid "String"
260
+ msgstr "Stringa"
261
+
262
+ #: ../include/calendar.php:106
263
+ #, php-format
264
+ msgid "%1$s %2$s"
265
+ msgstr ""
266
+
267
+ #: ../include/calendar.php:132
268
+ #: ../include/calendar.php:140
269
+ #, php-format
270
+ msgid "View posts for %1$s %2$s"
271
+ msgstr "Visualizza articoli di %1$s %2$s"
272
+
273
+ #: ../include/languages-form.php:36
274
+ msgid "Edit language"
275
+ msgstr "Modifica lingua"
276
+
277
+ #: ../include/languages-form.php:36
278
+ #: ../include/languages-form.php:103
279
+ msgid "Add new language"
280
+ msgstr "Aggiungi nuova lingua"
281
+
282
+ #: ../include/languages-form.php:58
283
+ msgid "Choose a language"
284
+ msgstr "Scegli una lingua"
285
+
286
+ #: ../include/languages-form.php:66
287
+ msgid "You can choose a language in the list or directly edit it below."
288
+ msgstr "Scegliere una lingua dall'elenco o inserirla direttamente nei campi a seguire."
289
+
290
+ #: ../include/languages-form.php:72
291
+ msgid "The name is how it is displayed on your site (for example: English)."
292
+ msgstr "Il nome come appare sul sito."
293
+
294
+ #: ../include/languages-form.php:79
295
+ msgid "Wordpress Locale for the language (for example: en_US). You will need to install the .mo file for this language."
296
+ msgstr "Impostazioni locali di Wordpress per la lingua (per esempio: en_US). è necessario installare il file .mo per questa lingua."
297
+
298
+ #: ../include/languages-form.php:83
299
+ msgid "Language code"
300
+ msgstr "Codice della lingua"
301
+
302
+ #: ../include/languages-form.php:85
303
+ msgid "2-letters ISO 639-1 language code (for example: en)"
304
+ msgstr "Codice della lingua a 2 lettere ISO 639-1 (per esempio: en)"
305
+
306
+ #: ../include/languages-form.php:89
307
+ msgid "Text direction"
308
+ msgstr "Direzione del testo"
309
+
310
+ #: ../include/languages-form.php:91
311
+ msgid "left to right"
312
+ msgstr "Da sinistra a destra"
313
+
314
+ #: ../include/languages-form.php:93
315
+ msgid "right to left"
316
+ msgstr "Da destra a sinistra"
317
+
318
+ #: ../include/languages-form.php:94
319
+ msgid "Choose the text direction for the language"
320
+ msgstr "Scegliere la direzione del testo per la lingua"
321
+
322
+ #: ../include/languages-form.php:100
323
+ msgid "Position of the language in the language switcher"
324
+ msgstr "Posizione della lingua nel selettore di lingua"
325
+
326
+ #: ../include/languages-form.php:103
327
+ msgid "Update"
328
+ msgstr "Aggiorna"
329
+
330
+ #: ../include/languages-form.php:149
331
+ msgid "Language switcher"
332
+ msgstr "Selettore di lingua"
333
+
334
+ #: ../include/languages-form.php:188
335
+ msgid "Default language"
336
+ msgstr "Lingua predefinita"
337
+
338
+ #: ../include/languages-form.php:206
339
+ msgid "There are posts, pages, categories or tags without language set. Do you want to set them all to default language ?"
340
+ msgstr "Ci sono articoli, pagine, categorie o tag per i quali la lingua non è stata impostata. Si desidera impostarla per tutti come la lingua predefinita?"
341
+
342
+ #: ../include/languages-form.php:214
343
+ msgid "Detect browser language"
344
+ msgstr "Individua la lingua del browser"
345
+
346
+ #: ../include/languages-form.php:220
347
+ msgid "When the front page is visited, set the language according to the browser preference"
348
+ msgstr "Imposta la lingua secondo le preferenze del browser quando viene visitata la pagina iniziale"
349
+
350
+ #: ../include/languages-form.php:227
351
+ msgid "URL modifications"
352
+ msgstr "modifiche dell'URL"
353
+
354
+ #: ../include/languages-form.php:233
355
+ msgid "Keep /language/ in pretty permalinks. Example:"
356
+ msgstr "Mantieni /language/ nei pretty permalinks. Esempio:"
357
+
358
+ #: ../include/languages-form.php:241
359
+ msgid "Remove /language/ in pretty permalinks. Example:"
360
+ msgstr "Rimuovi /language/ dai pretty permalinks. Esempio:"
361
+
362
+ #: ../include/languages-form.php:249
363
+ msgid "Hide URL language information for default language"
364
+ msgstr "Nascondi le informazioni relative alla lingua dall'URL per la lingua predefinita"
365
+
366
+ #: ../include/languages-form.php:256
367
+ msgid "Add language information to all URL including posts, pages, categories and post tags (not recommended)"
368
+ msgstr "Aggiungi le informazioni relative alla lingua a tutti gli URL, compresi articoli, pagine, categorie e tag (sconsigliato)"
369
+
370
+ #: ../include/languages-form.php:263
371
+ #, php-format
372
+ msgid "Redirect the language page (example: %s) to the homepage in the right language"
373
+ msgstr "Reindirizza la pagina della lingua (per esempio: %s) alla pagina iniziale della lingua giusta"
374
+
375
+ #: ../include/base.php:38
376
+ msgid "All languages"
377
+ msgstr "Tutte le lingue"
378
+
379
+ #: ../include/post-translations.php:1
380
+ msgid "ID of pages in other languages:"
381
+ msgstr "ID delle pagine in altre lingue:"
382
+
383
+ #: ../include/post-translations.php:1
384
+ msgid "ID of posts in other languages:"
385
+ msgstr "ID degli articoli in altre lingue:"
386
+
387
+ #: ../include/post-translations.php:5
388
+ msgid "Page ID"
389
+ msgstr "ID pagina"
390
+
391
+ #: ../include/post-translations.php:5
392
+ msgid "Post ID"
393
+ msgstr "ID articolo"
394
+
395
+ #: ../include/about.php:3
396
+ #, php-format
397
+ msgid "Polylang is provided with an extensive %sdocumentation%s (in English only). It includes information on how to set up your multilingual site and use it on a daily basis, a FAQ, as well as a documentation for programmers to adapt their plugins and themes."
398
+ msgstr "Polylang è completo di un'ampia %sdocumentazione%s (solamente in inglese). La documentazione comprende informazioni su come impostare un sito multilingue e come usarlo quotidianamente, un elenco di domande frequenti (FAQ), ed anche informazioni per i programmatori che volessero adattare i propri plugin e temi."
399
+
400
+ #: ../include/about.php:8
401
+ #, php-format
402
+ msgid "You will also find useful information in the %ssupport forum%s. However don't forget to make a search before posting a new topic."
403
+ msgstr "Si possono trovare informazioni utili anche nel %sforum di supporto%s. Comunque, prima di inviare una richiesta per un nuovo argomento, è sempre buona regola fare una ricerca."
404
+
405
+ #: ../include/about.php:14
406
+ #, php-format
407
+ msgid "Polylang is free of charge and is released under the same license as WordPress, the %sGPL%s."
408
+ msgstr "Polylang è gratuito ed è stato rilasciato con la stessa licenza di WordPress, la %sGPL%s."
409
+
410
+ #: ../include/about.php:18
411
+ #, php-format
412
+ msgid "If you wonder how you can help the project, just %sread this%s."
413
+ msgstr "Per sapere come poter aiutare questo progetto è sufficiente %sleggere questo%s."
414
+
415
+ #: ../include/about.php:22
416
+ msgid "Finally if you like this plugin or if it helps your business, donations to the author are greatly appreciated."
417
+ msgstr "Infine, se il plugin vi è stato utile per il vostro business, considerate la possibilità di fare una donazione a favore dell'autore."
418
+
polylang.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://wordpress.org/extend/plugins/polylang/
5
- Version: 0.8.1
6
  Author: F. Demarle
7
  Description: Adds multilingual capability to Wordpress
8
  */
@@ -24,7 +24,7 @@ Description: Adds multilingual capability to Wordpress
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
- define('POLYLANG_VERSION', '0.8.1');
28
  define('PLL_MIN_WP_VERSION', '3.1');
29
 
30
  define('POLYLANG_DIR', dirname(__FILE__)); // our directory
@@ -79,10 +79,16 @@ class Polylang extends Polylang_Base {
79
  add_action('wp_loaded', array(&$this, 'prepare_rewrite_rules'), 20); // after Polylang_base::add_post_types_taxonomies
80
 
81
  // separate admin and frontend
82
- if (is_admin()) {
 
83
  require_once(PLL_INC.'/admin.php');
84
  $polylang = new Polylang_Admin();
85
  }
 
 
 
 
 
86
  else {
87
  require_once(PLL_INC.'/core.php');
88
  $polylang = new Polylang_Core();
@@ -155,7 +161,7 @@ class Polylang extends Polylang_Base {
155
  // add our rewrite rules
156
  $this->add_post_types_taxonomies();
157
  $this->prepare_rewrite_rules();
158
- $GLOBALS['wp_rewrite']->flush_rules();
159
  return true;
160
  }
161
 
@@ -177,7 +183,7 @@ class Polylang extends Polylang_Base {
177
 
178
  // plugin deactivation
179
  function _deactivate() {
180
- $GLOBALS['wp_rewrite']->flush_rules();
181
  }
182
 
183
  // restores the local_flags directory after upgrade from version 0.5.1 or older
@@ -233,9 +239,9 @@ class Polylang extends Polylang_Base {
233
 
234
  // translation model changed in V0.5
235
  if (version_compare($options['version'], '0.5', '<')) {
236
- $ids = get_posts(array('numberposts'=>-1, 'fields' => 'ids', 'post_type'=>'any', 'post_status'=>'any'));
237
  $this->upgrade_translations('post', $ids);
238
- $ids = get_terms($this->taxonomies, array('get'=>'all', 'fields'=>'ids'));
239
  $this->upgrade_translations('term', $ids);
240
  }
241
 
@@ -250,7 +256,7 @@ class Polylang extends Polylang_Base {
250
  delete_post_meta($id, '_lang-'.$lang->slug);
251
  }
252
 
253
- $ids = get_terms($this->taxonomies, array('get'=>'all', 'fields'=>'ids'));
254
  foreach ($ids as $id) {
255
  foreach ($listlanguages as $lang)
256
  delete_metadata('term', $id, '_lang-'.$lang->slug);
@@ -273,8 +279,8 @@ class Polylang extends Polylang_Base {
273
  $options['redirect_lang'] = 0; // option introduced in 0.8
274
  }
275
 
276
- if (version_compare($options['version'], '0.8.1', '<'))
277
- $GLOBALS['wp_rewrite']->flush_rules(); // rewrite rules have been modified in 0.7.1 & 0.7.2 & 0.8 & 0.8.1
278
 
279
  $options['version'] = POLYLANG_VERSION;
280
  update_option('polylang', $options);
@@ -294,9 +300,12 @@ class Polylang extends Polylang_Base {
294
  'label' => false,
295
  'public' => false, // avoid displaying the 'like post tags text box' in the quick edit
296
  'query_var'=>'lang',
297
- 'rewrite' => array('slug' => $options['rewrite'] ? '' : 'language'), // http://www.myblog/en/ or http://www.myblog/language/en/ ?
298
  'update_count_callback' => '_update_post_term_count'));
299
 
 
 
 
 
300
  load_plugin_textdomain('polylang', false, basename(POLYLANG_DIR).'/languages'); // plugin i18n
301
  }
302
 
@@ -330,13 +339,12 @@ class Polylang extends Polylang_Base {
330
  // always make sure the default language is at the end in case the language information is hidden for default language
331
  // thanks to brbrbr http://wordpress.org/support/topic/plugin-polylang-rewrite-rules-not-correct
332
  function rewrite_rules($rules) {
333
-
334
  // suppress the rules created by WordPress for our taxonomy
335
  if (($current_filter = current_filter()) == 'language_rewrite_rules')
336
  return array();
337
 
338
  $options = get_option('polylang');
339
- $to_rewrite = array('date_rewrite_rules', 'root_rewrite_rules', 'comments_rewrite_rules', 'author_rewrite_rule', 'post_format_rewrite_rules');
340
  $newrules = array();
341
 
342
  foreach ($this->get_languages_list() as $language)
@@ -347,10 +355,12 @@ class Polylang extends Polylang_Base {
347
  $slug = $options['rewrite'] ? '('.implode('|', $languages).')/' : 'language/('.implode('|', $languages).')/';
348
 
349
  foreach ($rules as $key => $rule) {
350
- // special case for pages which do not accept adding the lang parameter
351
- if ($current_filter == 'page_rewrite_rules' && $options['force_lang']) {
 
352
  if (isset($slug))
353
- $newrules[$slug.$key] = str_replace(array('[4]', '[3]', '[2]', '[1]'), array('[5]', '[4]', '[3]', '[2]'), $rule); // hopefully it is sufficient !
 
354
 
355
  if ($options['hide_default'])
356
  $newrules[$key] = $rules[$key];
@@ -359,7 +369,7 @@ class Polylang extends Polylang_Base {
359
  }
360
 
361
  // rewrite rules filtered by language
362
- elseif (in_array($current_filter, $to_rewrite) || strpos($rule, 'post_type=') || ($current_filter != 'rewrite_rules_array' && $options['force_lang'])) {
363
  if (isset($slug))
364
  $newrules[$slug.$key] = str_replace(array('[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]', '?'),
365
  array('[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '?lang=$matches[1]&'), $rule); // hopefully it is sufficient !
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://wordpress.org/extend/plugins/polylang/
5
+ Version: 0.8.2
6
  Author: F. Demarle
7
  Description: Adds multilingual capability to Wordpress
8
  */
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
+ define('POLYLANG_VERSION', '0.8.2');
28
  define('PLL_MIN_WP_VERSION', '3.1');
29
 
30
  define('POLYLANG_DIR', dirname(__FILE__)); // our directory
79
  add_action('wp_loaded', array(&$this, 'prepare_rewrite_rules'), 20); // after Polylang_base::add_post_types_taxonomies
80
 
81
  // separate admin and frontend
82
+ if (is_admin() && isset($_GET['page']) && $_GET['page'] == 'mlang') {
83
+ require_once(PLL_INC.'/admin-base.php');
84
  require_once(PLL_INC.'/admin.php');
85
  $polylang = new Polylang_Admin();
86
  }
87
+ elseif (is_admin()) {
88
+ require_once(PLL_INC.'/admin-base.php');
89
+ require_once(PLL_INC.'/admin-filters.php');
90
+ $polylang = new Polylang_Admin_Filters();
91
+ }
92
  else {
93
  require_once(PLL_INC.'/core.php');
94
  $polylang = new Polylang_Core();
161
  // add our rewrite rules
162
  $this->add_post_types_taxonomies();
163
  $this->prepare_rewrite_rules();
164
+ flush_rewrite_rules();
165
  return true;
166
  }
167
 
183
 
184
  // plugin deactivation
185
  function _deactivate() {
186
+ flush_rewrite_rules();
187
  }
188
 
189
  // restores the local_flags directory after upgrade from version 0.5.1 or older
239
 
240
  // translation model changed in V0.5
241
  if (version_compare($options['version'], '0.5', '<')) {
242
+ $ids = get_posts(array('numberposts' => -1, 'fields' => 'ids', 'post_type' => 'any', 'post_status' => 'any'));
243
  $this->upgrade_translations('post', $ids);
244
+ $ids = get_terms($this->taxonomies, array('get' => 'all', 'fields' => 'ids'));
245
  $this->upgrade_translations('term', $ids);
246
  }
247
 
256
  delete_post_meta($id, '_lang-'.$lang->slug);
257
  }
258
 
259
+ $ids = get_terms($this->taxonomies, array('get' => 'all', 'fields' => 'ids'));
260
  foreach ($ids as $id) {
261
  foreach ($listlanguages as $lang)
262
  delete_metadata('term', $id, '_lang-'.$lang->slug);
279
  $options['redirect_lang'] = 0; // option introduced in 0.8
280
  }
281
 
282
+ if (version_compare($options['version'], '0.8.2', '<'))
283
+ flush_rewrite_rules(); // rewrite rules have been modified in 0.7.1 & 0.7.2 & 0.8 & 0.8.1 & 0.8.2
284
 
285
  $options['version'] = POLYLANG_VERSION;
286
  update_option('polylang', $options);
300
  'label' => false,
301
  'public' => false, // avoid displaying the 'like post tags text box' in the quick edit
302
  'query_var'=>'lang',
 
303
  'update_count_callback' => '_update_post_term_count'));
304
 
305
+ // optionaly removes 'language' in permalinks so that we get http://www.myblog/en/ instead of http://www.myblog/language/en/
306
+ if ($options['rewrite'])
307
+ add_permastruct('language', '%language%', array('with_front' => false));
308
+
309
  load_plugin_textdomain('polylang', false, basename(POLYLANG_DIR).'/languages'); // plugin i18n
310
  }
311
 
339
  // always make sure the default language is at the end in case the language information is hidden for default language
340
  // thanks to brbrbr http://wordpress.org/support/topic/plugin-polylang-rewrite-rules-not-correct
341
  function rewrite_rules($rules) {
 
342
  // suppress the rules created by WordPress for our taxonomy
343
  if (($current_filter = current_filter()) == 'language_rewrite_rules')
344
  return array();
345
 
346
  $options = get_option('polylang');
347
+ $always_rewrite = in_array(str_replace('_rewrite_rules', '', $current_filter), array('date', 'root', 'comments', 'author', 'post_format'));
348
  $newrules = array();
349
 
350
  foreach ($this->get_languages_list() as $language)
355
  $slug = $options['rewrite'] ? '('.implode('|', $languages).')/' : 'language/('.implode('|', $languages).')/';
356
 
357
  foreach ($rules as $key => $rule) {
358
+ // we don't need the lang parameter for post types and taxonomies
359
+ // moreover adding it would create issues for pages and taxonomies
360
+ if ($options['force_lang'] && in_array(str_replace('_rewrite_rules', '', $current_filter), array_merge($this->post_types, $this->taxonomies))) {
361
  if (isset($slug))
362
+ $newrules[$slug.$key] = str_replace(array('[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]'),
363
+ array('[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]'), $rule); // hopefully it is sufficient !
364
 
365
  if ($options['hide_default'])
366
  $newrules[$key] = $rules[$key];
369
  }
370
 
371
  // rewrite rules filtered by language
372
+ elseif ($always_rewrite || strpos($rule, 'post_type=') || ($current_filter != 'rewrite_rules_array' && $options['force_lang'])) {
373
  if (isset($slug))
374
  $newrules[$slug.$key] = str_replace(array('[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]', '?'),
375
  array('[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '?lang=$matches[1]&'), $rule); // hopefully it is sufficient !
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, i18n, international, l10n, localization
5
  Requires at least: 3.1
6
  Tested up to: 3.3.1
7
- Stable tag: 0.8.1
8
 
9
  Polylang adds multilingual content management support to WordPress.
10
 
@@ -39,6 +39,7 @@ The plugin admin interface is currently available in:
39
  * Hebrew contributed by [ArielK](http://www.arielk.net)
40
  * Polish contributed by [Peter Paciorkiewicz](http://www.paciorkiewicz.pl)
41
  * Latvian contributed by [@AndyDeGroo](http://twitter.com/AndyDeGroo)
 
42
 
43
  Special thanks to [@AndyDeGroo](http://twitter.com/AndyDeGroo) and [RavanH](http://4visions.nl/) for their help in debugging and improving Polylang !
44
 
@@ -90,7 +91,7 @@ If you wonder how you can help Polylang, here are some ideas. As you will read,
90
 
91
  = Help other users of Polylang =
92
 
93
- The [support forum](http://wordpress.org/tags/polylang?forum_id=10) is here so that users of the plugin can get help when they need it. However, I will not always available to answer questions. You don't need to be a developer to help out. Very often similar questions have been answered in the past. You can subscribe to the tag ['polylang'](http://wordpress.org/tags/polylang) (emails or RSS feed, see just below the topic list) to know when a new topic has been posted.
94
 
95
  = Report bugs =
96
 
@@ -102,7 +103,7 @@ You can subscribe to the tag ['polylang-dev'](http://wordpress.org/tags/polylang
102
 
103
  = Translate the admin interface =
104
 
105
- Polylang is already available in 9 languages. It's very easy to add a new one ! Download [poedit](http://www.poedit.net/download.php) (available for Windows, Mac OS X and Linux). Rename the file polylang.pot found in the polylang/languages directory into something like polylang-your_locale.po. Open the file with poedit and start translating (keeping strange codes such as %s, %1$s as is). Once done, just save and you will get two files polylang-your_locale.po and polylang-your_locale.mo that you can send to the author. The translation will be included with the next release.
106
 
107
  = Communicate =
108
 
@@ -114,6 +115,20 @@ Every suggestions are welcome.
114
 
115
  == Changelog ==
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  = 0.8.1 (2012-03-11) =
118
 
119
  * Add Latvian translation contributed by [@AndyDeGroo](http://twitter.com/AndyDeGroo)
4
  Tags: multilingual, bilingual, translate, translation, language, multilanguage, i18n, international, l10n, localization
5
  Requires at least: 3.1
6
  Tested up to: 3.3.1
7
+ Stable tag: 0.8.2
8
 
9
  Polylang adds multilingual content management support to WordPress.
10
 
39
  * Hebrew contributed by [ArielK](http://www.arielk.net)
40
  * Polish contributed by [Peter Paciorkiewicz](http://www.paciorkiewicz.pl)
41
  * Latvian contributed by [@AndyDeGroo](http://twitter.com/AndyDeGroo)
42
+ * Italian contributed by [Luca Barbetti](http://wordpress.org/support/profile/lucabarbetti)
43
 
44
  Special thanks to [@AndyDeGroo](http://twitter.com/AndyDeGroo) and [RavanH](http://4visions.nl/) for their help in debugging and improving Polylang !
45
 
91
 
92
  = Help other users of Polylang =
93
 
94
+ The [support forum](http://wordpress.org/tags/polylang?forum_id=10) is here so that users of the plugin can get help when they need it. However, I will not always be available to answer questions. You don't need to be a developer to help out. Very often similar questions have been answered in the past. You can subscribe to the tag ['polylang'](http://wordpress.org/tags/polylang) (emails or RSS feed, see just below the topic list) to know when a new topic has been posted.
95
 
96
  = Report bugs =
97
 
103
 
104
  = Translate the admin interface =
105
 
106
+ Polylang is already available in 10 languages. It's very easy to add a new one ! Download [poedit](http://www.poedit.net/download.php) (available for Windows, Mac OS X and Linux). Rename the file polylang.pot found in the polylang/languages directory into something like polylang-your_locale.po. Open the file with poedit and start translating (keeping strange codes such as %s, %1$s as is). Once done, just save and you will get two files polylang-your_locale.po and polylang-your_locale.mo that you can send to the author. The translation will be included with the next release.
107
 
108
  = Communicate =
109
 
115
 
116
  == Changelog ==
117
 
118
+ = 0.8.2 =
119
+
120
+ * Add Italian translation contributed by [Luca Barbetti](http://wordpress.org/support/profile/lucabarbetti)
121
+ * Improve performance on admin side
122
+ * Comment status and ping status are now copied when adding a new translation
123
+ * Deprecated API function 'pll_is_front_page' as it is now useless
124
+ * Bug correction: Wrong translation url for taxonomies when adding the language information to all urls
125
+ * Bug correction: "translation" of search page does not work if the site is only made of pages
126
+ * Bug correction: wrong language permalink structure introduced in 0.8.1
127
+ * Bug correction: wrong language set when clicking on "add new" translation in edit category and edit tags panels
128
+ * Bug correction: site does not display if no languages are set
129
+ * Bug correction: get_author_posts_url is 404
130
+ * Bug correction: homepage is 404 when using a static front page and adding the language information to all urls
131
+
132
  = 0.8.1 (2012-03-11) =
133
 
134
  * Add Latvian translation contributed by [@AndyDeGroo](http://twitter.com/AndyDeGroo)