Polylang Connect for Elementor – Templates Translation & Language Switcher - Version 2.2.0

Version Description

  • Added Elementor Pro template shortcode translation.
Download this release

Release Info

Developer pacotole
Plugin Icon 128x128 Polylang Connect for Elementor – Templates Translation & Language Switcher
Version 2.2.0
Comparing to
See all releases

Code changes from version 2.1.1 to 2.2.0

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: elementor, polylang, multilingual, language switcher, languages, templates
5
  Requires at least: 5.4
6
  Tested up to: 6.0
7
  Requires PHP: 5.6
8
- Stable tag: 2.1.1
9
  License: GPL-2.0-or-later
10
  License URI: https://opensource.org/licenses/GPL-2.0
11
 
@@ -22,6 +22,8 @@ Connect Polylang multilingual plugin with Elementor Page Builder: **Translate yo
22
  #### 📍 Template translation and show in the correct language
23
  Create translations for your Elementor templates especially for header, footer or archive templates with [**Elementor Pro Theme Builder**](https://trk.elementor.com/5l8mc0eyt38p-theme-builder) *(affiliated link)*.
24
 
 
 
25
  #### 🔄 Language Switcher
26
  A native Elementor Widget to easily build a nice and fully customizable language switcher:
27
 
@@ -195,6 +197,9 @@ There are quite a few:
195
 
196
  == Changelog ==
197
 
 
 
 
198
  = 2.1.1 =
199
  * Enable Elementor cross domain url fixes only for multidomain configurations.
200
  * Added Elementor tested headers.
5
  Requires at least: 5.4
6
  Tested up to: 6.0
7
  Requires PHP: 5.6
8
+ Stable tag: 2.2.0
9
  License: GPL-2.0-or-later
10
  License URI: https://opensource.org/licenses/GPL-2.0
11
 
22
  #### 📍 Template translation and show in the correct language
23
  Create translations for your Elementor templates especially for header, footer or archive templates with [**Elementor Pro Theme Builder**](https://trk.elementor.com/5l8mc0eyt38p-theme-builder) *(affiliated link)*.
24
 
25
+ It also works and selects the correct translation when using the `[elementor-template]` shortcode.
26
+
27
  #### 🔄 Language Switcher
28
  A native Elementor Widget to easily build a nice and fully customizable language switcher:
29
 
197
 
198
  == Changelog ==
199
 
200
+ = 2.2.0 =
201
+ * Added Elementor Pro template shortcode translation.
202
+
203
  = 2.1.1 =
204
  * Enable Elementor cross domain url fixes only for multidomain configurations.
205
  * Added Elementor tested headers.
connect-polylang-elementor.php CHANGED
@@ -8,7 +8,7 @@
8
  * Plugin Name: Polylang Connect for Elementor
9
  * Plugin URI: https://github.com/creame/connect-polylang-elementor
10
  * Description: Connect Polylang with Elementor. Display templates in the correct language, language switcher widget, language visibility conditions and dynamic tags.
11
- * Version: 2.1.1
12
  * Author: Creame
13
  * Author URI: https://crea.me/
14
  * License: GPL-2.0-or-later
@@ -33,7 +33,7 @@ defined( 'ABSPATH' ) || exit;
33
  *
34
  * @since 2.0.0
35
  */
36
- define( 'CPEL_PLUGIN_VERSION', '2.1.1' );
37
  define( 'CPEL_FILE', __FILE__ );
38
  define( 'CPEL_DIR', plugin_dir_path( CPEL_FILE ) );
39
  define( 'CPEL_BASENAME', plugin_basename( CPEL_FILE ) );
8
  * Plugin Name: Polylang Connect for Elementor
9
  * Plugin URI: https://github.com/creame/connect-polylang-elementor
10
  * Description: Connect Polylang with Elementor. Display templates in the correct language, language switcher widget, language visibility conditions and dynamic tags.
11
+ * Version: 2.2.0
12
  * Author: Creame
13
  * Author URI: https://crea.me/
14
  * License: GPL-2.0-or-later
33
  *
34
  * @since 2.0.0
35
  */
36
+ define( 'CPEL_PLUGIN_VERSION', '2.2.0' );
37
  define( 'CPEL_FILE', __FILE__ );
38
  define( 'CPEL_DIR', plugin_dir_path( CPEL_FILE ) );
39
  define( 'CPEL_BASENAME', plugin_basename( CPEL_FILE ) );
includes/connect-plugins.php CHANGED
@@ -32,6 +32,9 @@ class ConnectPlugins {
32
  add_filter( 'elementor/theme/get_location_templates/template_id', array( $this, 'template_id_translation' ) );
33
  add_filter( 'elementor/theme/get_location_templates/condition_sub_id', array( $this, 'condition_sub_id_translation' ), 10, 2 );
34
 
 
 
 
35
  // Fix home_url() for site-url Dynamic Tag and Search Form widget.
36
  add_filter( 'pll_home_url_white_list', array( $this, 'elementor_home_url_white_list' ) );
37
  add_filter( 'home_url', array( $this, 'home_url_language_dir_slash' ), 11, 2 );
@@ -184,7 +187,43 @@ class ConnectPlugins {
184
  }
185
 
186
  /**
187
- * Change Elementor template with their translation for the current lanaguage (if exists).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  *
189
  * @link https://github.com/pojome/elementor/issues/4839
190
  *
32
  add_filter( 'elementor/theme/get_location_templates/template_id', array( $this, 'template_id_translation' ) );
33
  add_filter( 'elementor/theme/get_location_templates/condition_sub_id', array( $this, 'condition_sub_id_translation' ), 10, 2 );
34
 
35
+ // Shortcode template loading.
36
+ add_filter( 'pre_do_shortcode_tag', array( $this, 'template_shortcode_translate' ), 10, 3 );
37
+
38
  // Fix home_url() for site-url Dynamic Tag and Search Form widget.
39
  add_filter( 'pll_home_url_white_list', array( $this, 'elementor_home_url_white_list' ) );
40
  add_filter( 'home_url', array( $this, 'home_url_language_dir_slash' ), 11, 2 );
187
  }
188
 
189
  /**
190
+ * Bypass Elementor template shortcode with their translation for the current language (if exists).
191
+ *
192
+ * @since 2.2.0
193
+ *
194
+ * @uses pll_get_post()
195
+ *
196
+ * @param mixed $false false or string with bypass output
197
+ * @param string $tag shortcode tag
198
+ * @param array $attr shortcode attributes
199
+ * @return false|string false or string with bypass output
200
+ */
201
+ public function template_shortcode_translate( $false, $tag, $attr ) {
202
+
203
+ if ( 'elementor-template' !== $tag ) {
204
+ return $false;
205
+ }
206
+
207
+ if ( isset( $attr['skip'] ) ) {
208
+ return $false;
209
+ }
210
+
211
+ // Translate post_id.
212
+ $attr['id'] = pll_get_post( absint( $attr['id'] ) ) ?: $attr['id'];
213
+ // Skip next call.
214
+ $attr['skip'] = 1;
215
+
216
+ $output = '';
217
+ foreach ( $attr as $key => $val ) {
218
+ $output .= " $key=\"$val\"";
219
+ }
220
+
221
+ return do_shortcode( '[elementor-template' . $output . ']' );
222
+
223
+ }
224
+
225
+ /**
226
+ * Change Elementor template with their translation for the current language (if exists).
227
  *
228
  * @link https://github.com/pojome/elementor/issues/4839
229
  *
includes/elementor-assets.php CHANGED
@@ -16,6 +16,11 @@ class ElementorAssets {
16
  protected $default_domain = '';
17
  protected $all_domains = array();
18
 
 
 
 
 
 
19
  protected function __construct() {
20
 
21
  if ( cpel_is_polylang_multidomain() ) {
@@ -49,11 +54,12 @@ class ElementorAssets {
49
  return;
50
  }
51
 
52
- $languages = pll_the_languages( array( 'raw' => true ) );
 
53
 
54
  foreach ( $languages as $language ) {
55
  $this->all_domains[] = $language['url'];
56
- if ( false !== stripos( $language['url'], $_SERVER['SERVER_NAME'] ) ) {
57
  $current_language = PLL()->model->get_language( $language['slug'] );
58
  break;
59
  }
16
  protected $default_domain = '';
17
  protected $all_domains = array();
18
 
19
+ /**
20
+ * Add actions if is multidomain
21
+ *
22
+ * @return void
23
+ */
24
  protected function __construct() {
25
 
26
  if ( cpel_is_polylang_multidomain() ) {
54
  return;
55
  }
56
 
57
+ $languages = pll_the_languages( array( 'raw' => true ) );
58
+ $server_host = parse_url( "//{$_SERVER['HTTP_HOST']}", PHP_URL_HOST );
59
 
60
  foreach ( $languages as $language ) {
61
  $this->all_domains[] = $language['url'];
62
+ if ( false !== stripos( $language['url'], $server_host ) ) {
63
  $current_language = PLL()->model->get_language( $language['slug'] );
64
  break;
65
  }