Polylang - Version 1.7.2

Version Description

(2015-03-23) =

  • fix: comments are filtered for posts in a post type not managed by Polylang
  • fix: translated static front page don't work when setting PLL_CACHE_HOME_URL to false (introduced in 1.7)
  • fix: the query for taxonomies on custom post types is broken (when adding the language code to the url)
Download this release

Release Info

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

Code changes from version 1.7.1 to 1.7.2

frontend/choose-lang.php CHANGED
@@ -188,7 +188,7 @@ abstract class PLL_Choose_Lang {
188
  */
189
  protected function set_home_query_var() {
190
  if ($this->page_on_front)
191
- set_query_var('page_id', $this->curlang->page_on_front);
192
  else
193
  $this->set_lang_query_var($GLOBALS['wp_query'], $this->curlang);
194
  }
@@ -221,14 +221,10 @@ abstract class PLL_Choose_Lang {
221
  // redirect the language page to the homepage when using a static front page
222
  if ($this->options['redirect_lang'] && $this->page_on_front && (count($query->query) == 1 || (is_paged() && count($query->query) == 2)) && is_tax('language')) {
223
  $this->set_language($this->model->get_language(get_query_var('lang')));
224
- if ($page_id = $this->curlang->page_on_front) {
225
- $query->set('page_id', $page_id);
226
- $query->is_singular = $query->is_page = true;
227
- $query->is_archive = $query->is_tax = false;
228
- unset($query->queried_object); // reset queried object
229
- }
230
- // else : the static front page is not translated
231
- // let's things as is and the list of posts in the current language will be displayed
232
  }
233
 
234
  // takes care of paged front page
188
  */
189
  protected function set_home_query_var() {
190
  if ($this->page_on_front)
191
+ set_query_var('page_id', $this->page_on_front);
192
  else
193
  $this->set_lang_query_var($GLOBALS['wp_query'], $this->curlang);
194
  }
221
  // redirect the language page to the homepage when using a static front page
222
  if ($this->options['redirect_lang'] && $this->page_on_front && (count($query->query) == 1 || (is_paged() && count($query->query) == 2)) && is_tax('language')) {
223
  $this->set_language($this->model->get_language(get_query_var('lang')));
224
+ $query->set('page_id', $this->page_on_front);
225
+ $query->is_singular = $query->is_page = true;
226
+ $query->is_archive = $query->is_tax = false;
227
+ unset($query->queried_object); // reset queried object
 
 
 
 
228
  }
229
 
230
  // takes care of paged front page
frontend/frontend-filters.php CHANGED
@@ -20,8 +20,8 @@ class PLL_Frontend_Filters extends PLL_Filters{
20
  add_filter('locale', array(&$this, 'get_locale'));
21
 
22
  // translates page for posts and page on front
23
- add_filter('option_page_on_front', array(&$this, 'translate_page_on_front'));
24
- add_filter('option_page_for_posts', array(&$this, 'translate_page_for_posts'));
25
 
26
  // filter sticky posts by current language
27
  add_filter('option_sticky_posts', array(&$this, 'option_sticky_posts'));
@@ -74,32 +74,6 @@ class PLL_Frontend_Filters extends PLL_Filters{
74
  return $this->curlang->locale;
75
  }
76
 
77
- /*
78
- * translates page on front
79
- *
80
- * @since 1.7
81
- *
82
- * @param int $v page on front page id
83
- * @return int
84
- */
85
- public function translate_page_on_front($v) {
86
- // returns the current page if there is no translation to avoid ugly notices
87
- return isset($this->curlang->page_on_front) ? $this->curlang->page_on_front : $v;
88
- }
89
-
90
- /*
91
- * translates page for posts
92
- *
93
- * @since 1.7
94
- *
95
- * @param int $v page for posts page id
96
- * @return int
97
- */
98
- public function translate_page_for_posts($v) {
99
- // returns the current page if there is no translation to avoid ugly notices
100
- return isset($this->curlang->page_for_posts) ? $this->curlang->page_for_posts : $v;
101
- }
102
-
103
  /*
104
  * filters sticky posts by current language
105
  *
20
  add_filter('locale', array(&$this, 'get_locale'));
21
 
22
  // translates page for posts and page on front
23
+ add_filter('option_page_on_front', 'pll_get_post');
24
+ add_filter('option_page_for_posts', 'pll_get_post');
25
 
26
  // filter sticky posts by current language
27
  add_filter('option_sticky_posts', array(&$this, 'option_sticky_posts'));
74
  return $this->curlang->locale;
75
  }
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  /*
78
  * filters sticky posts by current language
79
  *
frontend/frontend-links.php CHANGED
@@ -25,6 +25,7 @@ class PLL_Frontend_Links extends PLL_Links {
25
  $this->cache = new PLL_Cache();
26
 
27
  add_action('pll_language_defined', array(&$this, 'pll_language_defined'));
 
28
  }
29
 
30
  /*
@@ -200,7 +201,7 @@ class PLL_Frontend_Links extends PLL_Links {
200
  * @return string modified link
201
  */
202
  public function page_link($link, $id) {
203
- if ($this->page_on_front && ($lang = $this->model->get_post_language($id)) && $id == $lang->page_on_front)
204
  return $lang->home_url;
205
 
206
  return $link;
@@ -236,7 +237,7 @@ class PLL_Frontend_Links extends PLL_Links {
236
  */
237
  public function redirect_canonical($redirect_url, $requested_url) {
238
  global $wp_query;
239
- if (is_page() && !is_feed() && isset($wp_query->queried_object) && $wp_query->queried_object->ID == $this->curlang->page_on_front) {
240
  return is_paged() ? $this->links_model->add_paged_to_link($this->get_home_url(), $wp_query->query_vars['page']) : $this->get_home_url();
241
  }
242
 
@@ -342,7 +343,7 @@ class PLL_Frontend_Links extends PLL_Links {
342
 
343
  // page
344
  elseif (is_page() && ($id = $this->model->get_post($queried_object_id, $language)) && $this->current_user_can_read($id))
345
- $url = $hide && $id == $language->page_on_front ? $this->links_model->home : get_page_link($id);
346
 
347
  elseif (is_search()) {
348
  $url = $this->get_archive_url($language);
@@ -471,7 +472,7 @@ class PLL_Frontend_Links extends PLL_Links {
471
  return;
472
 
473
  // don't redirect if we are on a static front page
474
- if ($this->options['redirect_lang'] && isset($this->curlang->page_on_front) && is_page($this->curlang->page_on_front))
475
  return;
476
 
477
  if (empty($requested_url))
25
  $this->cache = new PLL_Cache();
26
 
27
  add_action('pll_language_defined', array(&$this, 'pll_language_defined'));
28
+ add_action('pll_language_defined', array(&$this, 'init_page_on_front_cache')); // translate page on front and page for posts
29
  }
30
 
31
  /*
201
  * @return string modified link
202
  */
203
  public function page_link($link, $id) {
204
+ if ($this->page_on_front && ($lang = $this->model->get_post_language($id)) && in_array($id, $this->model->get_translations('post', $this->page_on_front)))
205
  return $lang->home_url;
206
 
207
  return $link;
237
  */
238
  public function redirect_canonical($redirect_url, $requested_url) {
239
  global $wp_query;
240
+ if (is_page() && !is_feed() && isset($wp_query->queried_object) && $wp_query->queried_object->ID == $this->page_on_front) {
241
  return is_paged() ? $this->links_model->add_paged_to_link($this->get_home_url(), $wp_query->query_vars['page']) : $this->get_home_url();
242
  }
243
 
343
 
344
  // page
345
  elseif (is_page() && ($id = $this->model->get_post($queried_object_id, $language)) && $this->current_user_can_read($id))
346
+ $url = $hide && $queried_object_id == $this->page_on_front ? $this->links_model->home : get_page_link($id);
347
 
348
  elseif (is_search()) {
349
  $url = $this->get_archive_url($language);
472
  return;
473
 
474
  // don't redirect if we are on a static front page
475
+ if ($this->options['redirect_lang'] && isset($this->page_on_front) && is_page($this->page_on_front))
476
  return;
477
 
478
  if (empty($requested_url))
frontend/frontend.php CHANGED
@@ -92,11 +92,6 @@ class PLL_Frontend extends PLL_Base {
92
 
93
  // modifies query vars when the language is queried
94
  if (!empty($qv['lang'])) {
95
- // remove pages query when the language is set unless we do a search
96
- // take care not to break the single page query!
97
- if (empty($qv['post_type']) && !$query->is_search && !$query->is_page)
98
- $query->set('post_type', 'post');
99
-
100
  if (isset($query->tax_query->queried_terms)) {
101
  $tax_query_in_and = wp_list_filter( $query->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' );
102
  $queried_taxonomies = array_keys( $tax_query_in_and );
@@ -105,6 +100,11 @@ class PLL_Frontend extends PLL_Base {
105
  $taxonomies = array_diff($queried_taxonomies , array('language', 'category', 'post_tag'));
106
  }
107
 
 
 
 
 
 
108
  // unset the is_archive flag for language pages to prevent loading the archive template
109
  // keep archive flag for comment feed otherwise the language filter does not work
110
  if (empty($taxonomies) && !$query->is_comment_feed && !$query->is_post_type_archive && !$query->is_date && !$query->is_author && !$query->is_category && !$query->is_tag)
92
 
93
  // modifies query vars when the language is queried
94
  if (!empty($qv['lang'])) {
 
 
 
 
 
95
  if (isset($query->tax_query->queried_terms)) {
96
  $tax_query_in_and = wp_list_filter( $query->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' );
97
  $queried_taxonomies = array_keys( $tax_query_in_and );
100
  $taxonomies = array_diff($queried_taxonomies , array('language', 'category', 'post_tag'));
101
  }
102
 
103
+ // remove pages query when the language is set unless we do a search
104
+ // take care not to break the single page and taxonomies queries!
105
+ if (empty($qv['post_type']) && !$query->is_search && !$query->is_page && empty($taxonomies))
106
+ $query->set('post_type', 'post');
107
+
108
  // unset the is_archive flag for language pages to prevent loading the archive template
109
  // keep archive flag for comment feed otherwise the language filter does not work
110
  if (empty($taxonomies) && !$query->is_comment_feed && !$query->is_post_type_archive && !$query->is_date && !$query->is_author && !$query->is_category && !$query->is_tag)
include/filters.php CHANGED
@@ -44,6 +44,16 @@ class PLL_Filters {
44
  public function comments_clauses($clauses, $query) {
45
  global $wpdb;
46
 
 
 
 
 
 
 
 
 
 
 
47
  $lang = empty($query->query_vars['lang']) ? $this->curlang : $this->model->get_language($query->query_vars['lang']);
48
 
49
  if (!empty($lang)) {
44
  public function comments_clauses($clauses, $query) {
45
  global $wpdb;
46
 
47
+ // don't filter comments if comment ids or post ids are specified
48
+ $plucked = wp_array_slice_assoc( $query->query_vars, array( 'comment__in', 'parent', 'post_id', 'post__in', 'post_parent' ) );
49
+ $fields = array_filter( $plucked );
50
+ if (!empty($fields))
51
+ return $clauses;
52
+
53
+ // don't filter comments if a non translated post type is specified
54
+ if (!empty($query->query_vars['post_type']) && !$this->model->is_translated_post_type($query->query_vars['post_type']))
55
+ return $clauses;
56
+
57
  $lang = empty($query->query_vars['lang']) ? $this->curlang : $this->model->get_language($query->query_vars['lang']);
58
 
59
  if (!empty($lang)) {
include/language.php CHANGED
@@ -36,7 +36,6 @@ class PLL_Language {
36
  public $locale, $is_rtl;
37
  public $flag_url, $flag;
38
  public $home_url, $search_url;
39
- public $page_on_front = 0, $page_for_posts = 0;
40
  public $host, $mo_id;
41
 
42
  /*
@@ -129,7 +128,6 @@ class PLL_Language {
129
 
130
  /*
131
  * set home_url and search_url properties
132
- * set page_on_front and page_for_posts too
133
  *
134
  * @since 1.3
135
  */
@@ -152,13 +150,6 @@ class PLL_Language {
152
 
153
  else
154
  $this->home_url = $this->search_url;
155
-
156
- // page on front and page for posts
157
- // FIXME here for convenience but should be moved outside
158
- if ('page' == get_option('show_on_front')) {
159
- $this->page_on_front = $polylang->model->get_post(get_option('page_on_front'), $this);
160
- $this->page_for_posts = $polylang->model->get_post(get_option('page_for_posts'), $this);
161
- }
162
  }
163
 
164
  /*
36
  public $locale, $is_rtl;
37
  public $flag_url, $flag;
38
  public $home_url, $search_url;
 
39
  public $host, $mo_id;
40
 
41
  /*
128
 
129
  /*
130
  * set home_url and search_url properties
 
131
  *
132
  * @since 1.3
133
  */
150
 
151
  else
152
  $this->home_url = $this->search_url;
 
 
 
 
 
 
 
153
  }
154
 
155
  /*
include/links-directory.php CHANGED
@@ -176,12 +176,13 @@ class PLL_Links_Directory extends PLL_Links_Permalinks {
176
  $cpts = $cpts ? '#post_type=('.implode('|', $cpts).')#' : '';
177
 
178
  foreach ($rules as $key => $rule) {
179
- // special case for translated post types and taxonomies to allow canonical redirection
 
180
  if ($this->options['force_lang'] && in_array($filter, array_merge($this->model->get_translated_post_types(), $this->model->get_translated_taxonomies()))) {
181
  if (isset($slug))
182
  $newrules[$slug.str_replace($wp_rewrite->root, '', $key)] = str_replace(
183
- array('[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]', '?'),
184
- array('[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '?lang=$matches[1]&'),
185
  $rule
186
  ); // should be enough!
187
 
176
  $cpts = $cpts ? '#post_type=('.implode('|', $cpts).')#' : '';
177
 
178
  foreach ($rules as $key => $rule) {
179
+ // we don't need the lang parameter for post types and taxonomies
180
+ // moreover adding it would create issues for pages and taxonomies
181
  if ($this->options['force_lang'] && in_array($filter, array_merge($this->model->get_translated_post_types(), $this->model->get_translated_taxonomies()))) {
182
  if (isset($slug))
183
  $newrules[$slug.str_replace($wp_rewrite->root, '', $key)] = str_replace(
184
+ array('[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]'),
185
+ array('[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]'),
186
  $rule
187
  ); // should be enough!
188
 
install/upgrade.php CHANGED
@@ -88,7 +88,7 @@ class PLL_Upgrade {
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', '1.3', '1.4', '1.4.1', '1.4.4', '1.5', '1.6', '1.7') as $version)
92
  if (version_compare($this->options['version'], $version, '<'))
93
  call_user_func(array(&$this, 'upgrade_' . str_replace('.', '_', $version)));
94
 
@@ -496,15 +496,15 @@ class PLL_Upgrade {
496
  $upgrader = new Language_Pack_Upgrader(new Automatic_Upgrader_Skin);
497
  $upgrader->bulk_upgrade($translations_to_load, array('clear_update_cache' => false));
498
  }
499
- }
500
-
501
  /*
502
- * upgrades if the previous version is < 1.7
503
- * deletes language cache (due to flag properties added)
504
- *
505
- * @since 1.7
506
  */
507
- protected function upgrade_1_7() {
508
- delete_transient('pll_languages_list');
 
509
  }
510
  }
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', '1.3', '1.4', '1.4.1', '1.4.4', '1.5', '1.6', '1.7.2') as $version)
92
  if (version_compare($this->options['version'], $version, '<'))
93
  call_user_func(array(&$this, 'upgrade_' . str_replace('.', '_', $version)));
94
 
496
  $upgrader = new Language_Pack_Upgrader(new Automatic_Upgrader_Skin);
497
  $upgrader->bulk_upgrade($translations_to_load, array('clear_update_cache' => false));
498
  }
499
+ }
500
+
501
  /*
502
+ * upgrades if the previous version is < 1.7.2
503
+ *
504
+ * @since 1.7.2
 
505
  */
506
+ protected function upgrade_1_7_2() {
507
+ delete_transient('pll_languages_list'); // deletes language cache (due to flag properties added in 1.7 and page on front removed in 1.7.2)
508
+ flush_rewrite_rules(); // flush rewrite rules due to custom taxonomy rewrite rule bug fix
509
  }
510
  }
polylang.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://polylang.wordpress.com/
5
- Version: 1.7.1
6
  Author: Frédéric Demarle
7
  Description: Adds multilingual capability to WordPress
8
  Text Domain: polylang
@@ -33,7 +33,7 @@ Domain Path: /languages
33
  if (!function_exists('add_action'))
34
  exit();
35
 
36
- define('POLYLANG_VERSION', '1.7.1');
37
  define('PLL_MIN_WP_VERSION', '3.8');
38
 
39
  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.7.2
6
  Author: Frédéric Demarle
7
  Description: Adds multilingual capability to WordPress
8
  Text Domain: polylang
33
  if (!function_exists('add_action'))
34
  exit();
35
 
36
+ define('POLYLANG_VERSION', '1.7.2');
37
  define('PLL_MIN_WP_VERSION', '3.8');
38
 
39
  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.8
6
  Tested up to: 4.1
7
- Stable tag: 1.7.1
8
  License: GPLv2 or later
9
 
10
  Polylang adds multilingual content management support to WordPress.
@@ -67,6 +67,12 @@ See http://polylang.wordpress.com/documentation/contribute/
67
 
68
  == Changelog ==
69
 
 
 
 
 
 
 
70
  = 1.7.1 (2015-03-20) =
71
 
72
  * fix: wrong redirection when using a static front page and replacing the page name by the language code (introduced in 1.7)
4
  Tags: multilingual, bilingual, translate, translation, language, multilanguage, international, localization
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
+ Stable tag: 1.7.2
8
  License: GPLv2 or later
9
 
10
  Polylang adds multilingual content management support to WordPress.
67
 
68
  == Changelog ==
69
 
70
+ = 1.7.2 (2015-03-23) =
71
+
72
+ * fix: comments are filtered for posts in a post type not managed by Polylang
73
+ * fix: translated static front page don't work when setting PLL_CACHE_HOME_URL to false (introduced in 1.7)
74
+ * fix: the query for taxonomies on custom post types is broken (when adding the language code to the url)
75
+
76
  = 1.7.1 (2015-03-20) =
77
 
78
  * fix: wrong redirection when using a static front page and replacing the page name by the language code (introduced in 1.7)