TranslatePress – Translate Multilingual sites - Version 1.6.9

Version Description

  • Fixed a conflict with Contact Form 7 plugin
  • Fixed some broken html issues caused by a custom trp wrap. Some Revolution Slider plugin issues are fixed by this.
  • Optimized some queries regarding search indexing to fix some performance problems. It should help with some Revolution Slider plugin performance issues.
  • Fixed an issue with textarea in Advanced Options
  • Exclude links from "Force language in custom links" by adding their selector in Settings -> Advanced -> Exclude selectors from translation
  • Fixed force custom links in default language when add-subdirectory is set to yes and default language is not first language
  • Better handling of href links with spaces
Download this release

Release Info

Developer madalin.ungureanu
Plugin Icon 128x128 TranslatePress – Translate Multilingual sites
Version 1.6.9
Comparing to
See all releases

Code changes from version 1.6.8 to 1.6.9

class-translate-press.php CHANGED
@@ -53,7 +53,7 @@ class TRP_Translate_Press{
53
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
54
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
55
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
56
- define( 'TRP_PLUGIN_VERSION', '1.6.8' );
57
 
58
  wp_cache_add_non_persistent_groups(array('trp'));
59
 
53
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
54
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
55
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
56
+ define( 'TRP_PLUGIN_VERSION', '1.6.9' );
57
 
58
  wp_cache_add_non_persistent_groups(array('trp'));
59
 
includes/class-advanced-tab.php CHANGED
@@ -394,7 +394,7 @@ class TRP_Advanced_Tab {
394
  foreach ( $adv_option[ $setting['name'] ][ $first_column ] as $index => $value ) {
395
  $html .= "<tr class='trp-list-entry'>";
396
  foreach ( $setting['columns'] as $column => $column_name ) {
397
- $html .= "<td><textarea name='trp_advanced_settings[" . $setting['name'] . "][" . $column . "][]'>" . $adv_option[ $setting['name'] ][ $column ][ $index ] . "</textarea></td>";
398
  }
399
  $html .= "<td><span class='trp-adst-remove-element' data-confirm-message='" . __('Are you sure you want to remove this item?', 'translatepress-multilingual') . "'>" . __( 'Remove', 'translatepress-multilingual' ) . "</span></td>";
400
  $html .= "</tr>";
394
  foreach ( $adv_option[ $setting['name'] ][ $first_column ] as $index => $value ) {
395
  $html .= "<tr class='trp-list-entry'>";
396
  foreach ( $setting['columns'] as $column => $column_name ) {
397
+ $html .= "<td><textarea name='trp_advanced_settings[" . $setting['name'] . "][" . $column . "][]'>" . htmlspecialchars($adv_option[ $setting['name'] ][ $column ][ $index ], ENT_QUOTES) . "</textarea></td>";
398
  }
399
  $html .= "<td><span class='trp-adst-remove-element' data-confirm-message='" . __('Are you sure you want to remove this item?', 'translatepress-multilingual') . "'>" . __( 'Remove', 'translatepress-multilingual' ) . "</span></td>";
400
  $html .= "</tr>";
includes/class-translation-render.php CHANGED
@@ -39,7 +39,9 @@ class TRP_Translation_Render{
39
  else {
40
  mb_http_output("UTF-8");
41
  if ( $TRP_LANGUAGE == $this->settings['default-language'] && !trp_is_translation_editor() ) {
42
- ob_start(array($this, 'clear_trp_tags'), 4096);//on default language when we are not in editor we just need to clear any trp tags that could still be present
 
 
43
  } else {
44
  ob_start(array($this, 'translate_page'));//everywhere else translate the page
45
  }
@@ -621,8 +623,6 @@ class TRP_Translation_Render{
621
  }
622
  //set up general links variables
623
  $home_url = home_url();
624
- $admin_url = admin_url();
625
- $wp_login_url = wp_login_url();
626
 
627
  $node_accessors = $this->get_node_accessors();
628
  foreach( $node_accessors as $node_accessor_key => $node_accessor ){
@@ -681,11 +681,20 @@ class TRP_Translation_Render{
681
  }
682
  }
683
  if( !empty( $strings_in_post_content ) ){
684
- $original_string_ids = $this->trp_query->get_original_string_ids($strings_in_post_content['strings']);
685
 
686
- if( !empty( $original_string_ids ) ){
687
- //there is a correlation between the two arrays
688
- $this->trp_query->set_original_string_meta_post_id( $original_string_ids, $strings_in_post_content['post_ids'] );
 
 
 
 
 
 
 
 
 
 
689
  }
690
  }
691
  }
@@ -750,23 +759,58 @@ class TRP_Translation_Render{
750
  }
751
  }
752
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
753
 
754
  // force custom links to have the correct language
755
  foreach( $html->find('a[href!="#"]') as $a_href) {
756
  $a_href->href = apply_filters( 'trp_href_from_translated_page', $a_href->href, $this->settings['default-language'] );
757
 
758
- $url = $a_href->href;
759
 
760
  $url = $this->maybe_is_local_url($url, $home_url);
761
 
762
  $is_external_link = $this->is_external_link( $url, $home_url );
763
  $is_admin_link = $this->is_admin_link($url, $admin_url, $wp_login_url);
764
 
765
- if( $preview_mode && ! $is_external_link ){
766
- $a_href->setAttribute( 'data-trp-original-href', $url );
767
- }
768
 
769
- if ( $TRP_LANGUAGE != $this->settings['default-language'] && $this->settings['force-language-to-custom-links'] == 'yes' && !$is_external_link && $this->url_converter->get_lang_from_url_string( $url ) == null && !$is_admin_link && strpos($url, '#TRPLINKPROCESSED') === false ){
 
 
 
 
 
 
 
 
770
  $a_href->href = apply_filters( 'trp_force_custom_links', $this->url_converter->get_url_for_language( $TRP_LANGUAGE, $url ), $url, $TRP_LANGUAGE, $a_href );
771
  $url = $a_href->href;
772
  }
@@ -802,19 +846,14 @@ class TRP_Translation_Render{
802
  foreach ( $html->find('link') as $link ){
803
  $link->href = str_replace('#TRPLINKPROCESSED', '', $link->href);
804
  }
 
 
805
 
806
- // Append an html table containing the errors
807
- $trp_editor_notices = apply_filters( 'trp_editor_notices', $trp_editor_notices );
808
- if ( trp_is_translation_editor('preview') && $trp_editor_notices != '' ){
809
- $body = $html->find('body', 0 );
810
- $body->innertext = '<div data-no-translation class="trp-editor-notices">' . $trp_editor_notices . "</div>" . $body->innertext;
811
- }
812
- $final_html = $html->save();
813
-
814
- /* perform preg replace on the remaining trp-gettext tags */
815
- $final_html = $this->remove_trp_html_tags( $final_html );
816
-
817
- return apply_filters( 'trp_translated_html', $final_html, $TRP_LANGUAGE, $language_code, $preview_mode );
818
  }
819
 
820
  /*
@@ -935,13 +974,25 @@ class TRP_Translation_Render{
935
  }
936
  }
937
 
 
 
 
 
 
 
938
  /**
939
  * Function that should be called only on the default language and when we are not in the editor mode and it is designed as a fallback to clear
940
  * any trp gettext tags that we added and for some reason show up although they should not
941
  * @param $output
942
  * @return mixed
943
  */
944
- function clear_trp_tags( $output ){
 
 
 
 
 
 
945
  return TRP_Translation_Manager::strip_gettext_tags($output);
946
  }
947
 
@@ -1319,7 +1370,7 @@ class TRP_Translation_Render{
1319
  'showdynamiccontentbeforetranslation' => apply_filters( 'trp_show_dynamic_content_before_translation', false ),
1320
  'skip_strings_from_dynamic_translation' => apply_filters( 'trp_skip_strings_from_dynamic_translation', array() ),
1321
  'skip_strings_from_dynamic_translation_for_substrings' => apply_filters( 'trp_skip_strings_from_dynamic_translation_for_substrings', array( 'href' => array('amazon-adsystem', 'googleads', 'g.doubleclick') ) ),
1322
- 'duplicate_detections_allowed' => apply_filters( 'trp_duplicate_detections_allowed', 20 )
1323
  );
1324
  }
1325
 
@@ -1544,13 +1595,23 @@ class TRP_Translation_Render{
1544
  return $translated;
1545
  }
1546
 
1547
-
 
 
 
 
 
 
1548
  function wrap_with_post_id( $content, $id = null ){
1549
- global $post, $TRP_LANGUAGE;
1550
 
1551
  if( empty($post->ID) )
1552
  return $content;
1553
 
 
 
 
 
1554
  //for the_tile filter we have an $id and we can compare it with the post we are on ..to avoid wrapping titles in menus for example
1555
  if( !is_null( $id ) && $id !== $post->ID ){
1556
  return $content;
@@ -1558,7 +1619,7 @@ class TRP_Translation_Render{
1558
 
1559
  if ( $TRP_LANGUAGE !== $this->settings['default-language'] ) {
1560
  if ( is_singular() && !empty($post->ID)) {
1561
- $content = '<trp-post-container data-trp-post-id="' . $post->ID . '">' . $content . '</trp-post-container>';
1562
  }
1563
  }
1564
 
39
  else {
40
  mb_http_output("UTF-8");
41
  if ( $TRP_LANGUAGE == $this->settings['default-language'] && !trp_is_translation_editor() ) {
42
+ // on default language when we are not in editor we just need to clear any trp tags that could still be present and handle links for special situation
43
+ $chunk_size = ($this->handle_custom_links_for_default_language() ) ? null : 4096;
44
+ ob_start(array( $this, 'render_default_language' ), $chunk_size);
45
  } else {
46
  ob_start(array($this, 'translate_page'));//everywhere else translate the page
47
  }
623
  }
624
  //set up general links variables
625
  $home_url = home_url();
 
 
626
 
627
  $node_accessors = $this->get_node_accessors();
628
  foreach( $node_accessors as $node_accessor_key => $node_accessor ){
681
  }
682
  }
683
  if( !empty( $strings_in_post_content ) ){
 
684
 
685
+ //try to do this only once a day to decrease query load
686
+ $current_permalink = get_permalink();
687
+ $set_meta_for_this_url = get_transient('processed_original_string_meta_post_id_for_' . hash('md4', $current_permalink));
688
+ if( $set_meta_for_this_url === false ){
689
+
690
+ $original_string_ids = $this->trp_query->get_original_string_ids($strings_in_post_content['strings']);
691
+
692
+ if( !empty( $original_string_ids ) ){
693
+ //there is a correlation between the two arrays
694
+ $this->trp_query->set_original_string_meta_post_id( $original_string_ids, $strings_in_post_content['post_ids'] );
695
+ }
696
+
697
+ set_transient('processed_original_string_meta_post_id_for_' . hash('md4', $current_permalink), 'done', 60*60*24 );
698
  }
699
  }
700
  }
759
  }
760
  }
761
 
762
+ $html = $this->handle_custom_links_and_forms( $html );
763
+
764
+ // Append an html table containing the errors
765
+ $trp_editor_notices = apply_filters( 'trp_editor_notices', $trp_editor_notices );
766
+ if ( trp_is_translation_editor('preview') && $trp_editor_notices != '' ){
767
+ $body = $html->find('body', 0 );
768
+ $body->innertext = '<div data-no-translation class="trp-editor-notices">' . $trp_editor_notices . "</div>" . $body->innertext;
769
+ }
770
+ $final_html = $html->save();
771
+
772
+ /* perform preg replace on the remaining trp-gettext tags */
773
+ $final_html = $this->remove_trp_html_tags( $final_html );
774
+
775
+ return apply_filters( 'trp_translated_html', $final_html, $TRP_LANGUAGE, $language_code, $preview_mode );
776
+ }
777
+
778
+ public function handle_custom_links_and_forms( $html ){
779
+ global $TRP_LANGUAGE;
780
+ $preview_mode = isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview';
781
+ $home_url = home_url();
782
+ $admin_url = admin_url();
783
+ $wp_login_url = wp_login_url();
784
+ $no_translate_attribute = 'data-no-translation';
785
+ if ( ! $this->url_converter ) {
786
+ $trp = TRP_Translate_Press::get_trp_instance();
787
+ $this->url_converter = $trp->get_component('url_converter');
788
+ }
789
 
790
  // force custom links to have the correct language
791
  foreach( $html->find('a[href!="#"]') as $a_href) {
792
  $a_href->href = apply_filters( 'trp_href_from_translated_page', $a_href->href, $this->settings['default-language'] );
793
 
794
+ $url = trim($a_href->href);
795
 
796
  $url = $this->maybe_is_local_url($url, $home_url);
797
 
798
  $is_external_link = $this->is_external_link( $url, $home_url );
799
  $is_admin_link = $this->is_admin_link($url, $admin_url, $wp_login_url);
800
 
801
+ if( $preview_mode && ! $is_external_link ){
802
+ $a_href->setAttribute( 'data-trp-original-href', $url );
803
+ }
804
 
805
+ if (
806
+ ( $TRP_LANGUAGE != $this->settings['default-language'] || $this->settings['add-subdirectory-to-default-language'] == 'yes' ) &&
807
+ $this->settings['force-language-to-custom-links'] == 'yes' &&
808
+ !$is_external_link &&
809
+ $this->url_converter->get_lang_from_url_string( $url ) == null &&
810
+ !$is_admin_link &&
811
+ strpos($url, '#TRPLINKPROCESSED') === false &&
812
+ !$this->has_ancestor_attribute( $a_href, $no_translate_attribute )
813
+ ){
814
  $a_href->href = apply_filters( 'trp_force_custom_links', $this->url_converter->get_url_for_language( $TRP_LANGUAGE, $url ), $url, $TRP_LANGUAGE, $a_href );
815
  $url = $a_href->href;
816
  }
846
  foreach ( $html->find('link') as $link ){
847
  $link->href = str_replace('#TRPLINKPROCESSED', '', $link->href);
848
  }
849
+ return $html;
850
+ }
851
 
852
+ public function is_first_language_not_default_language(){
853
+ return ( isset( $this->settings['add-subdirectory-to-default-language'] ) &&
854
+ $this->settings['add-subdirectory-to-default-language'] == 'yes' &&
855
+ isset( $this->settings['publish-languages'][0] ) &&
856
+ $this->settings['default-language'] != $this->settings['publish-languages'][0] );
 
 
 
 
 
 
 
857
  }
858
 
859
  /*
974
  }
975
  }
976
 
977
+ public function handle_custom_links_for_default_language(){
978
+ return ( $this->settings['force-language-to-custom-links'] == 'yes' &&
979
+ $this->is_first_language_not_default_language() &&
980
+ apply_filters('trp_handle_custom_links_and_forms_in_default_language', true ) );
981
+ }
982
+
983
  /**
984
  * Function that should be called only on the default language and when we are not in the editor mode and it is designed as a fallback to clear
985
  * any trp gettext tags that we added and for some reason show up although they should not
986
  * @param $output
987
  * @return mixed
988
  */
989
+ public function render_default_language( $output ){
990
+ if ( $this->handle_custom_links_for_default_language() ) {
991
+ $html = TranslatePress\str_get_html( $output, true, true, TRP_DEFAULT_TARGET_CHARSET, false, TRP_DEFAULT_BR_TEXT, TRP_DEFAULT_SPAN_TEXT );
992
+ $html = $this->handle_custom_links_and_forms($html);
993
+ $output = $html->save();
994
+ }
995
+
996
  return TRP_Translation_Manager::strip_gettext_tags($output);
997
  }
998
 
1370
  'showdynamiccontentbeforetranslation' => apply_filters( 'trp_show_dynamic_content_before_translation', false ),
1371
  'skip_strings_from_dynamic_translation' => apply_filters( 'trp_skip_strings_from_dynamic_translation', array() ),
1372
  'skip_strings_from_dynamic_translation_for_substrings' => apply_filters( 'trp_skip_strings_from_dynamic_translation_for_substrings', array( 'href' => array('amazon-adsystem', 'googleads', 'g.doubleclick') ) ),
1373
+ 'duplicate_detections_allowed' => apply_filters( 'trp_duplicate_detections_allowed', 100 )
1374
  );
1375
  }
1376
 
1595
  return $translated;
1596
  }
1597
 
1598
+ /**
1599
+ * Function that wraps the post title and the post content in a custom trp wrap trp-post-container so we can know in
1600
+ * the function translate_page() if a string is part of the content of a post so we can store a meta that gives the string context
1601
+ * @param $content
1602
+ * @param null $id
1603
+ * @return string
1604
+ */
1605
  function wrap_with_post_id( $content, $id = null ){
1606
+ global $post, $TRP_LANGUAGE, $wp_query;
1607
 
1608
  if( empty($post->ID) )
1609
  return $content;
1610
 
1611
+ //we try to wrap only the actual content of the post and not when the filters are executed in SEO plugins for example
1612
+ if( !$wp_query->in_the_loop || !is_main_query() )
1613
+ return $content;
1614
+
1615
  //for the_tile filter we have an $id and we can compare it with the post we are on ..to avoid wrapping titles in menus for example
1616
  if( !is_null( $id ) && $id !== $post->ID ){
1617
  return $content;
1619
 
1620
  if ( $TRP_LANGUAGE !== $this->settings['default-language'] ) {
1621
  if ( is_singular() && !empty($post->ID)) {
1622
+ $content = "<trp-post-container data-trp-post-id='" . $post->ID . "'>" . $content . "</trp-post-container>";//changed " to ' to not break cases when the filter is applied inside an html attribute (title for example)
1623
  }
1624
  }
1625
 
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site using a visual front-end translation editor, with full support for WooCommerce and site builders.
6
- Version: 1.6.8
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site using a visual front-end translation editor, with full support for WooCommerce and site builders.
6
+ Version: 1.6.9
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
languages/translatepress-multilingual.pot CHANGED
@@ -605,31 +605,31 @@ msgstr ""
605
  msgid "<strong>Warning:</strong> Some strings have possibly incorrectly encoded characters. This may result in breaking the queries, rendering the page untranslated in live mode. Consider revising the following strings or their method of outputting."
606
  msgstr ""
607
 
608
- #: ../translatepress/includes/class-translation-render.php:145
609
  msgid "Description"
610
  msgstr ""
611
 
612
- #: ../translatepress/includes/class-translation-render.php:151
613
  msgid "OG Title"
614
  msgstr ""
615
 
616
- #: ../translatepress/includes/class-translation-render.php:157
617
  msgid "OG Site Name"
618
  msgstr ""
619
 
620
- #: ../translatepress/includes/class-translation-render.php:163
621
  msgid "OG Description"
622
  msgstr ""
623
 
624
- #: ../translatepress/includes/class-translation-render.php:169
625
  msgid "Twitter Title"
626
  msgstr ""
627
 
628
- #: ../translatepress/includes/class-translation-render.php:175
629
  msgid "Twitter Description"
630
  msgstr ""
631
 
632
- #: ../translatepress/includes/class-translation-render.php:179
633
  msgid "Page Title"
634
  msgstr ""
635
 
605
  msgid "<strong>Warning:</strong> Some strings have possibly incorrectly encoded characters. This may result in breaking the queries, rendering the page untranslated in live mode. Consider revising the following strings or their method of outputting."
606
  msgstr ""
607
 
608
+ #: ../translatepress/includes/class-translation-render.php:147
609
  msgid "Description"
610
  msgstr ""
611
 
612
+ #: ../translatepress/includes/class-translation-render.php:153
613
  msgid "OG Title"
614
  msgstr ""
615
 
616
+ #: ../translatepress/includes/class-translation-render.php:159
617
  msgid "OG Site Name"
618
  msgstr ""
619
 
620
+ #: ../translatepress/includes/class-translation-render.php:165
621
  msgid "OG Description"
622
  msgstr ""
623
 
624
+ #: ../translatepress/includes/class-translation-render.php:171
625
  msgid "Twitter Title"
626
  msgstr ""
627
 
628
+ #: ../translatepress/includes/class-translation-render.php:177
629
  msgid "Twitter Description"
630
  msgstr ""
631
 
632
+ #: ../translatepress/includes/class-translation-render.php:181
633
  msgid "Page Title"
634
  msgstr ""
635
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: translate, translation, multilingual, automatic translation, bilingual, fr
5
  Requires at least: 3.1.0
6
  Tested up to: 5.3.2
7
  Requires PHP: 5.6.20
8
- Stable tag: 1.6.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -143,6 +143,15 @@ For more information please check out [TranslatePress - Multilingual plugin docu
143
 
144
 
145
  == Changelog ==
 
 
 
 
 
 
 
 
 
146
  = 1.6.8 =
147
  * Added support for All In One SEO
148
  * Added compatibility with Peepso double slashing translated links
5
  Requires at least: 3.1.0
6
  Tested up to: 5.3.2
7
  Requires PHP: 5.6.20
8
+ Stable tag: 1.6.9
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
143
 
144
 
145
  == Changelog ==
146
+ = 1.6.9 =
147
+ * Fixed a conflict with Contact Form 7 plugin
148
+ * Fixed some broken html issues caused by a custom trp wrap. Some Revolution Slider plugin issues are fixed by this.
149
+ * Optimized some queries regarding search indexing to fix some performance problems. It should help with some Revolution Slider plugin performance issues.
150
+ * Fixed an issue with textarea in Advanced Options
151
+ * Exclude links from "Force language in custom links" by adding their selector in Settings -> Advanced -> Exclude selectors from translation
152
+ * Fixed force custom links in default language when add-subdirectory is set to yes and default language is not first language
153
+ * Better handling of href links with spaces
154
+
155
  = 1.6.8 =
156
  * Added support for All In One SEO
157
  * Added compatibility with Peepso double slashing translated links