Polylang - Version 0.8.7

Version Description

(2012-06-10) =

  • Add the possibility to load Polylang API for ajax requests on frontend
  • Add ta_LK to predefined languages list
  • Bug correction: search form is broken when using a static front page
  • Bug correction: admin bar search does not work
  • Tests done with WordPress 3.4 RC2
Download this release

Release Info

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

Code changes from version 0.8.6 to 0.8.7

doc/documentation-en.odt CHANGED
Binary file
doc/documentation-en.pdf CHANGED
Binary file
include/core.php CHANGED
@@ -60,7 +60,8 @@ class Polylang_Core extends Polylang_base {
60
  add_filter('redirect_canonical', array(&$this, 'redirect_canonical'), 10, 2);
61
 
62
  // adds javascript at the end of the document
63
- add_action('wp_print_footer_scripts', array(&$this, 'wp_print_footer_scripts'));
 
64
 
65
  // adds the language information in the search form
66
  // low priority in case the search form is created using the same filter as described in http://codex.wordpress.org/Function_Reference/get_search_form
@@ -277,8 +278,11 @@ class Polylang_Core extends Polylang_base {
277
  $query->set('lang', $this->curlang->slug);
278
  }
279
  // redirect to the home page in the right language
280
- else {
281
- wp_redirect($this->get_home_url($this->curlang));
 
 
 
282
  exit;
283
  }
284
  }
@@ -422,32 +426,39 @@ class Polylang_Core extends Polylang_base {
422
  function wp_print_footer_scripts() {
423
  // modifies the search form since filtering get_search_form won't work if the template uses searchform.php or the search form is hardcoded
424
  // don't use directly e[0] just in case there is somewhere else an element named 's'
425
- // check before if the hidden input has not already been introduced by get_search_form
426
  // thanks to AndyDeGroo for improving the code for compatility with old browsers
427
  // http://wordpress.org/support/topic/development-of-polylang-version-08?replies=6#post-2645559
428
- if (!$this->search_form_filter) {
429
- $lang = esc_js($this->curlang->slug);
430
- $js = "e = document.getElementsByName('s');
431
- for (i = 0; i < e.length; i++) {
432
- if (e[i].tagName.toUpperCase() == 'INPUT') {
 
 
 
 
 
 
 
 
433
  var ih = document.createElement('input');
434
  ih.type = 'hidden';
435
  ih.name = 'lang';
436
  ih.value = '$lang';
437
  e[i].parentNode.appendChild(ih);
438
  }
439
- }";
440
- echo "<script type='text/javascript'>" .$js. "</script>";
441
- }
442
  }
443
 
444
  // adds the language information in the search form
445
  // does not work if searchform.php is used or if the search form is hardcoded in another template file
446
  function get_search_form($form) {
447
- if ($form) {
448
- $this->search_form_filter = true;
449
  $form = str_replace('</form>', '<input type="hidden" name="lang" value="'.esc_attr($this->curlang->slug).'" /></form>', $form);
450
- }
451
  return $form;
452
  }
453
 
@@ -616,9 +627,11 @@ class Polylang_Core extends Polylang_base {
616
 
617
  $theme = get_theme_root();
618
  foreach (debug_backtrace() as $trace) {
 
 
 
 
619
  $ok = $trace['function'] == 'wp_nav_menu' ||
620
- // search form when using pretty permalinks
621
- ($trace['function'] == 'get_search_form' || (isset($trace['file']) && strpos($trace['file'], 'searchform.php'))) ||
622
  // direct call from the theme
623
  // FIXME is test of searchform.php necessary now ?
624
  (isset($trace['file']) && !strpos($trace['file'], 'searchform.php') && strpos($trace['file'], $theme) !== false &&
@@ -632,7 +645,7 @@ class Polylang_Core extends Polylang_base {
632
  }
633
 
634
  // returns the home url in the right language
635
- function get_home_url($language = '') {
636
  if ($language == '')
637
  $language = $this->curlang;
638
 
@@ -640,7 +653,8 @@ class Polylang_Core extends Polylang_base {
640
  return trailingslashit($this->home);
641
 
642
  // a static page is used as front page : /!\ don't use get_page_link to avoid infinite loop
643
- if ($this->page_on_front && $id = $this->get_post($this->page_on_front, $language))
 
644
  return $this->page_link('', $id);
645
 
646
  return get_term_link($language, 'language');
60
  add_filter('redirect_canonical', array(&$this, 'redirect_canonical'), 10, 2);
61
 
62
  // adds javascript at the end of the document
63
+ // must add it *after* the admin bar rendering
64
+ add_action('wp_footer', array(&$this, 'wp_print_footer_scripts'), 2000);
65
 
66
  // adds the language information in the search form
67
  // low priority in case the search form is created using the same filter as described in http://codex.wordpress.org/Function_Reference/get_search_form
278
  $query->set('lang', $this->curlang->slug);
279
  }
280
  // redirect to the home page in the right language
281
+ // test to avoid crash if get_home_url returns something wrong
282
+ // FIXME why this happens? http://wordpress.org/support/topic/polylang-crashes-1
283
+ // FIXME should it be an option ?
284
+ elseif (is_string($redirect = $this->get_home_url($this->curlang))) {
285
+ wp_redirect($redirect);
286
  exit;
287
  }
288
  }
426
  function wp_print_footer_scripts() {
427
  // modifies the search form since filtering get_search_form won't work if the template uses searchform.php or the search form is hardcoded
428
  // don't use directly e[0] just in case there is somewhere else an element named 's'
429
+ // check before if the hidden input has not already been introduced by get_search_form (FIXME: is there a way to improve this ?
430
  // thanks to AndyDeGroo for improving the code for compatility with old browsers
431
  // http://wordpress.org/support/topic/development-of-polylang-version-08?replies=6#post-2645559
432
+
433
+ $lang = esc_js($this->curlang->slug);
434
+ $js = "e = document.getElementsByName('s');
435
+ for (i = 0; i < e.length; i++) {
436
+ if (e[i].tagName.toUpperCase() == 'INPUT') {
437
+ s = e[i].parentNode.parentNode.children;
438
+ l = 0;
439
+ for (j = 0; j < s.length; j++) {
440
+ if (s[j].name == 'lang') {
441
+ l = 1;
442
+ }
443
+ }
444
+ if ( l == 0) {
445
  var ih = document.createElement('input');
446
  ih.type = 'hidden';
447
  ih.name = 'lang';
448
  ih.value = '$lang';
449
  e[i].parentNode.appendChild(ih);
450
  }
451
+ }
452
+ }";
453
+ echo "<script type='text/javascript'>" .$js. "</script>";
454
  }
455
 
456
  // adds the language information in the search form
457
  // does not work if searchform.php is used or if the search form is hardcoded in another template file
458
  function get_search_form($form) {
459
+ if ($form)
 
460
  $form = str_replace('</form>', '<input type="hidden" name="lang" value="'.esc_attr($this->curlang->slug).'" /></form>', $form);
461
+
462
  return $form;
463
  }
464
 
627
 
628
  $theme = get_theme_root();
629
  foreach (debug_backtrace() as $trace) {
630
+ // search form when using pretty permalinks
631
+ if (in_array($trace['function'], array ('get_search_form', 'wp_admin_bar_search_menu')) || (isset($trace['file']) && strpos($trace['file'], 'searchform.php')))
632
+ return $this->get_home_url($this->curlang, true);
633
+
634
  $ok = $trace['function'] == 'wp_nav_menu' ||
 
 
635
  // direct call from the theme
636
  // FIXME is test of searchform.php necessary now ?
637
  (isset($trace['file']) && !strpos($trace['file'], 'searchform.php') && strpos($trace['file'], $theme) !== false &&
645
  }
646
 
647
  // returns the home url in the right language
648
+ function get_home_url($language = '', $search = false) {
649
  if ($language == '')
650
  $language = $this->curlang;
651
 
653
  return trailingslashit($this->home);
654
 
655
  // a static page is used as front page : /!\ don't use get_page_link to avoid infinite loop
656
+ // don't use this for search form
657
+ if (!$search && $this->page_on_front && $id = $this->get_post($this->page_on_front, $language))
658
  return $this->page_link('', $id);
659
 
660
  return get_term_link($language, 'language');
include/languages-form.php CHANGED
@@ -57,7 +57,7 @@ if (isset($_GET['error'])) {?>
57
  <div class="form-field">
58
  <label for="lang_list"><?php _e('Choose a language', 'polylang');?></label>
59
  <select name="lang_list" id="lang_list">
60
- <option value=""></option>';<?php
61
  include(PLL_INC.'/languages.php');
62
  foreach ($languages as $lg) {
63
  printf('<option value="%1$s-%2$s-%3$s">%4$s - %2$s</option>'."\n", esc_attr($lg[0]), esc_attr($lg[1]), isset($lg[3]) ? '1' : '0' , esc_html($lg[2]));
57
  <div class="form-field">
58
  <label for="lang_list"><?php _e('Choose a language', 'polylang');?></label>
59
  <select name="lang_list" id="lang_list">
60
+ <option value=""></option><?php
61
  include(PLL_INC.'/languages.php');
62
  foreach ($languages as $lg) {
63
  printf('<option value="%1$s-%2$s-%3$s">%4$s - %2$s</option>'."\n", esc_attr($lg[0]), esc_attr($lg[1]), isset($lg[3]) ? '1' : '0' , esc_html($lg[2]));
include/languages.php CHANGED
@@ -53,6 +53,7 @@ $languages = array(
53
  array('sq', 'sq', 'Shqip'),
54
  array('sr', 'sr_RS', 'Српски језик'),
55
  array('sv', 'sv_SE', 'Svenska'),
 
56
  array('th', 'th', 'ไทย'),
57
  array('tr', 'tr_TR', 'Türkçe'),
58
  array('ug', 'ug_CN', 'Uyƣurqə'),
53
  array('sq', 'sq', 'Shqip'),
54
  array('sr', 'sr_RS', 'Српски језик'),
55
  array('sv', 'sv_SE', 'Svenska'),
56
+ array('ta', 'ta_LK', 'தமிழ்'),
57
  array('th', 'th', 'ไทย'),
58
  array('tr', 'tr_TR', 'Türkçe'),
59
  array('ug', 'ug_CN', 'Uyƣurqə'),
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.6
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.6');
28
  define('PLL_MIN_WP_VERSION', '3.1');
29
 
30
  define('POLYLANG_DIR', dirname(__FILE__)); // our directory
@@ -87,7 +87,8 @@ class Polylang extends Polylang_Base {
87
  require_once(PLL_INC.'/admin.php');
88
  $polylang = new Polylang_Admin();
89
  }
90
- elseif (is_admin()) {
 
91
  require_once(PLL_INC.'/admin-base.php');
92
  require_once(PLL_INC.'/admin-filters.php');
93
  $polylang = new Polylang_Admin_Filters();
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://wordpress.org/extend/plugins/polylang/
5
+ Version: 0.8.7
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.7');
28
  define('PLL_MIN_WP_VERSION', '3.1');
29
 
30
  define('POLYLANG_DIR', dirname(__FILE__)); // our directory
87
  require_once(PLL_INC.'/admin.php');
88
  $polylang = new Polylang_Admin();
89
  }
90
+ // avoid loading polylang admin filters for frontend ajax requests if 'pll_load_front' is set (thanks to g100g)
91
+ elseif (is_admin() && !(defined('DOING_AJAX') && isset($_REQUEST['pll_load_front']))) {
92
  require_once(PLL_INC.'/admin-base.php');
93
  require_once(PLL_INC.'/admin-filters.php');
94
  $polylang = new Polylang_Admin_Filters();
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.4
7
- Stable tag: 0.8.6
8
 
9
  Polylang adds multilingual content management support to WordPress.
10
 
@@ -109,6 +109,14 @@ Every suggestions are welcome.
109
 
110
  == Changelog ==
111
 
 
 
 
 
 
 
 
 
112
  = 0.8.6 (2012-05-23) =
113
 
114
  * Add the possibility to use a local config file to set options
4
  Tags: multilingual, bilingual, translate, translation, language, multilanguage, i18n, international, l10n, localization
5
  Requires at least: 3.1
6
  Tested up to: 3.4
7
+ Stable tag: 0.8.7
8
 
9
  Polylang adds multilingual content management support to WordPress.
10
 
109
 
110
  == Changelog ==
111
 
112
+ = 0.8.7 (2012-06-10) =
113
+
114
+ * Add the possibility to load Polylang API for ajax requests on frontend
115
+ * Add ta_LK to predefined languages list
116
+ * Bug correction: search form is broken when using a static front page
117
+ * Bug correction: admin bar search does not work
118
+ * Tests done with WordPress 3.4 RC2
119
+
120
  = 0.8.6 (2012-05-23) =
121
 
122
  * Add the possibility to use a local config file to set options