TranslatePress – Translate Multilingual sites - Version 2.2.0

Version Description

  • Fixed language slug incorrectly ending up in .htaccess in some cases
  • Fixed issue in hreflang tags when using certain custom language codes
  • Added missing Persian (Afghanistan) flag
Download this release

Release Info

Developer razvan.mo
Plugin Icon 128x128 TranslatePress – Translate Multilingual sites
Version 2.2.0
Comparing to
See all releases

Code changes from version 2.1.9 to 2.2.0

assets/images/flags/fa_AF.png ADDED
Binary file
class-translate-press.php CHANGED
@@ -33,6 +33,7 @@ class TRP_Translate_Press{
33
  protected $search;
34
  protected $install_plugins;
35
  protected $reviews;
 
36
 
37
  public $active_pro_addons = array();
38
  public static $translate_press = null;
@@ -58,7 +59,7 @@ class TRP_Translate_Press{
58
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
59
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
60
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
61
- define( 'TRP_PLUGIN_VERSION', '2.1.9' );
62
 
63
  wp_cache_add_non_persistent_groups(array('trp'));
64
 
@@ -116,6 +117,7 @@ class TRP_Translate_Press{
116
  require_once TRP_PLUGIN_DIR . 'includes/class-search.php';
117
  require_once TRP_PLUGIN_DIR . 'includes/class-install-plugins.php';
118
  require_once TRP_PLUGIN_DIR . 'includes/class-reviews.php';
 
119
  require_once TRP_PLUGIN_DIR . 'assets/lib/tp-add-ons-listing/tp-add-ons-listing.php';
120
  if ( did_action( 'elementor/loaded' ) )
121
  require_once TRP_PLUGIN_DIR . 'includes/class-elementor-language-for-blocks.php';
@@ -156,6 +158,7 @@ class TRP_Translate_Press{
156
  $this->search = new TRP_Search( $this->settings->get_settings() );
157
  $this->install_plugins = new TRP_Install_Plugins();
158
  $this->reviews = new TRP_Reviews( $this->settings->get_settings() );
 
159
  }
160
 
161
  /**
@@ -276,6 +279,8 @@ class TRP_Translate_Press{
276
  // Email Course
277
  $this->loader->add_action( 'wp_ajax_trp_dismiss_email_course', $this->settings, 'trp_dismiss_email_course' );
278
 
 
 
279
  }
280
 
281
  /**
33
  protected $search;
34
  protected $install_plugins;
35
  protected $reviews;
36
+ protected $rewrite_rules;
37
 
38
  public $active_pro_addons = array();
39
  public static $translate_press = null;
59
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
60
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
61
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
62
+ define( 'TRP_PLUGIN_VERSION', '2.2.0' );
63
 
64
  wp_cache_add_non_persistent_groups(array('trp'));
65
 
117
  require_once TRP_PLUGIN_DIR . 'includes/class-search.php';
118
  require_once TRP_PLUGIN_DIR . 'includes/class-install-plugins.php';
119
  require_once TRP_PLUGIN_DIR . 'includes/class-reviews.php';
120
+ require_once TRP_PLUGIN_DIR . 'includes/class-rewrite-rules.php';
121
  require_once TRP_PLUGIN_DIR . 'assets/lib/tp-add-ons-listing/tp-add-ons-listing.php';
122
  if ( did_action( 'elementor/loaded' ) )
123
  require_once TRP_PLUGIN_DIR . 'includes/class-elementor-language-for-blocks.php';
158
  $this->search = new TRP_Search( $this->settings->get_settings() );
159
  $this->install_plugins = new TRP_Install_Plugins();
160
  $this->reviews = new TRP_Reviews( $this->settings->get_settings() );
161
+ $this->rewrite_rules = new TRP_Rewrite_Rules( $this->settings->get_settings() );
162
  }
163
 
164
  /**
279
  // Email Course
280
  $this->loader->add_action( 'wp_ajax_trp_dismiss_email_course', $this->settings, 'trp_dismiss_email_course' );
281
 
282
+ // Filter rewrite rules for .htaccess
283
+ $this->loader->add_filter( 'mod_rewrite_rules', $this->rewrite_rules, 'trp_remove_language_param', 100 );
284
  }
285
 
286
  /**
includes/class-rewrite-rules.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class TRP_Rewrite_Rules
5
+ *
6
+ * Filters the .htaccess file to prevent language slug in URL
7
+ *
8
+ */
9
+ class TRP_Rewrite_Rules{
10
+
11
+ protected $settings;
12
+
13
+ public function __construct( $settings ){
14
+ $this->settings = $settings;
15
+ }
16
+
17
+ /**
18
+ * Remove language parameter from .htaccess in certain cases.
19
+ *
20
+ * Hooked to 'mod_rewrite_rules'
21
+ *
22
+ * @param string $htaccess_string
23
+ *
24
+ * @return string
25
+ */
26
+ public function trp_remove_language_param( $htaccess_string ) {
27
+
28
+ $url_slugs = $this->settings['url-slugs'];
29
+
30
+ foreach ( $url_slugs as $key => $value ) {
31
+ if( $this->settings['add-subdirectory-to-default-language'] == 'no' && $key == $this->settings['default-language'] ){
32
+ continue;
33
+ }
34
+ foreach ( array( '', 'index.php' ) as $base ) {
35
+ $htaccess_string = str_replace(
36
+ '/' . $value . '/' . $base,
37
+ '/' . $base,
38
+ $htaccess_string
39
+ );
40
+ }
41
+ }
42
+
43
+ return $htaccess_string;
44
+ }
45
+
46
+ }
includes/class-url-converter.php CHANGED
@@ -168,22 +168,34 @@ class TRP_Url_Converter {
168
  }
169
 
170
  $region_independent_languages = array();
171
- foreach ( $languages as $language ) {
172
- // hreflang should have - instead of _ . For example: en-EN, not en_EN like the locale
173
- $hreflang = str_replace( '_', '-', $language );
174
- $hreflang = apply_filters( 'trp_hreflang', $hreflang, $language );
175
- echo '<link rel="alternate" hreflang="' . esc_attr( $hreflang ) . '" href="' . esc_url( $this->get_url_for_language( $language ) ) . '"/>' . "\n";
176
-
177
- if ( apply_filters( 'trp_add_region_independent_hreflang_tags', true ) ) {
178
- if ( strpos( $language, '_' ) !== false ) {
179
- $language_independent_hreflang = strtok( $language, '_' );
180
- if ( !empty( $language_independent_hreflang ) && !in_array( $language_independent_hreflang, $region_independent_languages ) ) {
181
- $region_independent_languages[] = $language_independent_hreflang;
182
- echo '<link rel="alternate" hreflang="' . esc_attr( $language_independent_hreflang ) . '" href="' . esc_url( $this->get_url_for_language( $language ) ) . '"/>' . "\n";
183
- }
 
 
 
184
  }
185
  }
186
  }
 
 
 
 
 
 
 
 
 
187
 
188
  if ( isset( $this->settings['trp_advanced_settings']['enable_hreflang_xdefault'] ) && $this->settings['trp_advanced_settings']['enable_hreflang_xdefault'] != 'disabled' ) {
189
  $default_lang = $this->settings['trp_advanced_settings']['enable_hreflang_xdefault'];
168
  }
169
 
170
  $region_independent_languages = array();
171
+ $hreflang_duplicates = array();
172
+ $hreflang_duplicates_region_independent = array();
173
+ foreach ( $languages as $language ) {
174
+ // hreflang should have - instead of _ . For example: en-EN, not en_EN like the locale
175
+ $hreflang = str_replace( '_', '-', $language );
176
+ $hreflang = apply_filters( 'trp_hreflang', $hreflang, $language );
177
+ $hreflang_duplicates[] = $hreflang;
178
+ echo '<link rel="alternate" hreflang="' . esc_attr( $hreflang ) . '" href="' . esc_url( $this->get_url_for_language( $language ) ) . '"/>' . "\n";
179
+
180
+ if ( apply_filters( 'trp_add_region_independent_hreflang_tags', true ) ) {
181
+ if ( strpos( $language, '_' ) !== false ) {
182
+ $language_independent_hreflang = strtok( $language, '_' );
183
+ if ( !empty( $language_independent_hreflang ) && !in_array( $language_independent_hreflang, $region_independent_languages ) ) {
184
+ $region_independent_languages[] = $language_independent_hreflang;
185
+ $hreflang_duplicates_region_independent[$language] = '<link rel="alternate" hreflang="' . esc_attr( $language_independent_hreflang ) . '" href="' . esc_url( $this->get_url_for_language( $language ) ) . '"/>' . "\n";
186
+
187
  }
188
  }
189
  }
190
+ }
191
+
192
+ foreach ($languages as $language){
193
+ if (!in_array(strtok($language, '_'), $hreflang_duplicates)){
194
+ if(isset($hreflang_duplicates_region_independent[ $language ])) {
195
+ echo $hreflang_duplicates_region_independent[ $language ]; /* phpcs:ignore */ /* escaped inside the array */
196
+ }
197
+ }
198
+ }
199
 
200
  if ( isset( $this->settings['trp_advanced_settings']['enable_hreflang_xdefault'] ) && $this->settings['trp_advanced_settings']['enable_hreflang_xdefault'] != 'disabled' ) {
201
  $default_lang = $this->settings['trp_advanced_settings']['enable_hreflang_xdefault'];
index.php CHANGED
@@ -3,14 +3,14 @@
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: 2.1.9
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
10
  Domain Path: /languages
11
  License: GPL2
12
  WC requires at least: 2.5.0
13
- WC tested up to: 6.1
14
 
15
  == Copyright ==
16
  Copyright 2017 Cozmoslabs (www.cozmoslabs.com)
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: 2.2.0
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
10
  Domain Path: /languages
11
  License: GPL2
12
  WC requires at least: 2.5.0
13
+ WC tested up to: 6.1.1
14
 
15
  == Copyright ==
16
  Copyright 2017 Cozmoslabs (www.cozmoslabs.com)
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: cozmoslabs, razvan.mo, madalin.ungureanu, sareiodata, cristophor
3
  Donate link: https://www.translatepress.com/
4
  Tags: translate, translation, multilingual, automatic translation, bilingual, front-end translation, google translate, language
5
  Requires at least: 3.1.0
6
- Tested up to: 5.8.3
7
  Requires PHP: 5.6.20
8
- Stable tag: 2.1.9
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -140,6 +140,11 @@ For more information please check out our [documentation](https://translatepress
140
 
141
 
142
  == Changelog ==
 
 
 
 
 
143
  = 2.1.9 =
144
  * Improved database optimization tool by adding option to remove CDATA and untranslated links from TP custom tables
145
  * Fixed database optimization tool not starting in some cases
3
  Donate link: https://www.translatepress.com/
4
  Tags: translate, translation, multilingual, automatic translation, bilingual, front-end translation, google translate, language
5
  Requires at least: 3.1.0
6
+ Tested up to: 5.9
7
  Requires PHP: 5.6.20
8
+ Stable tag: 2.2.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
140
 
141
 
142
  == Changelog ==
143
+ = 2.2.0 =
144
+ * Fixed language slug incorrectly ending up in .htaccess in some cases
145
+ * Fixed issue in hreflang tags when using certain custom language codes
146
+ * Added missing Persian (Afghanistan) flag
147
+
148
  = 2.1.9 =
149
  * Improved database optimization tool by adding option to remove CDATA and untranslated links from TP custom tables
150
  * Fixed database optimization tool not starting in some cases