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

Version Description

  • 2021-04-30 =
  • Translated templates with conditions for categories/tags also works with translated categories/tags.
  • Fixed PHP notice on activation
Download this release

Release Info

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

Code changes from version 1.0.3 to 1.0.4

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: elementor, polylang, multilingual, language switcher, languages, templates
5
  Requires at least: 4.7
6
  Tested up to: 5.7
7
  Requires PHP: 5.6
8
- Stable tag: 1.0.3
9
  License: GPL-2.0-or-later
10
  License URI: https://opensource.org/licenses/GPL-2.0
11
 
@@ -220,6 +220,10 @@ There are quite a few:
220
 
221
  == Changelog ==
222
 
 
 
 
 
223
  = 1.0.3 - 2021-04-27 =
224
  * Ensure Theme Builder conditions for all languages (prev. version only saves main language conditions)
225
  * When a template is a translation override with empty conditions
5
  Requires at least: 4.7
6
  Tested up to: 5.7
7
  Requires PHP: 5.6
8
+ Stable tag: 1.0.4
9
  License: GPL-2.0-or-later
10
  License URI: https://opensource.org/licenses/GPL-2.0
11
 
220
 
221
  == Changelog ==
222
 
223
+ = 1.0.4 - 2021-04-30 =
224
+ * Translated templates with conditions for categories/tags also works with translated categories/tags.
225
+ * Fixed PHP notice on activation
226
+
227
  = 1.0.3 - 2021-04-27 =
228
  * Ensure Theme Builder conditions for all languages (prev. version only saves main language conditions)
229
  * When a template is a translation override with empty conditions
connect-polylang-elementor.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Polylang Connect for Elementor
13
  * Plugin URI: https://github.com/deckerweb/connect-polylang-elementor
14
  * Description: Connect the Polylang multilingual plugin with Elementor Page Builder: This plugin will make Elementor and Polylang show the correct language templates, especially with Elementor Pro Theme Builder. Plus: native Polylang Language Switcher Elementor widget, new Dynamic Tags, and Polylang links added to the Elementor Finder feature.
15
- * Version: 1.0.3
16
  * Author: David Decker - DECKERWEB
17
  * Author URI: https://deckerweb.de/
18
  * License: GPL-2.0-or-later
@@ -41,7 +41,7 @@ if ( ! defined( 'ABSPATH' ) ) {
41
  * @since 1.0.0
42
  */
43
  /** Plugin version */
44
- define( 'CPEL_PLUGIN_VERSION', '1.0.3' );
45
 
46
  /** File */
47
  define( 'CPEL__FILE__', __FILE__ );
12
  * Plugin Name: Polylang Connect for Elementor
13
  * Plugin URI: https://github.com/deckerweb/connect-polylang-elementor
14
  * Description: Connect the Polylang multilingual plugin with Elementor Page Builder: This plugin will make Elementor and Polylang show the correct language templates, especially with Elementor Pro Theme Builder. Plus: native Polylang Language Switcher Elementor widget, new Dynamic Tags, and Polylang links added to the Elementor Finder feature.
15
+ * Version: 1.0.4
16
  * Author: David Decker - DECKERWEB
17
  * Author URI: https://deckerweb.de/
18
  * License: GPL-2.0-or-later
41
  * @since 1.0.0
42
  */
43
  /** Plugin version */
44
+ define( 'CPEL_PLUGIN_VERSION', '1.0.4' );
45
 
46
  /** File */
47
  define( 'CPEL__FILE__', __FILE__ );
includes/admin-extras.php CHANGED
@@ -23,6 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
23
  function ddw_cpel_custom_settings_links( $cpel_links ) {
24
 
25
  $link_polylang = '';
 
26
  $templates_link = '';
27
 
28
  /** Add settings link only if user has permission */
23
  function ddw_cpel_custom_settings_links( $cpel_links ) {
24
 
25
  $link_polylang = '';
26
+ $link_elementor = '';
27
  $templates_link = '';
28
 
29
  /** Add settings link only if user has permission */
modules/connect/tweaks-polylang-elementor.php CHANGED
@@ -87,25 +87,66 @@ add_filter( 'elementor/theme/get_location_templates/template_id', 'ddw_cpel_chan
87
  * @link https://github.com/pojome/elementor/issues/4839
88
  *
89
  * @since 1.0.0
 
90
  *
91
  * @uses pll_get_post()
92
  *
 
93
  * @param int $post_id ID of the current post.
94
  * @return string Based translation, the translation ID, or the original Post ID.
95
  */
96
  function ddw_cpel_change_template_based_on_language( $post_id ) {
 
97
 
98
- if ( function_exists( 'pll_get_post' ) ) {
99
 
100
- return pll_get_post( $post_id ) ?: $post_id;
101
 
102
  }
103
 
 
 
104
  return $post_id;
105
 
106
  }
107
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  add_filter( 'get_post_metadata', 'ddw_cpel_empty_elementor_conditions_on_translations', 10, 3 );
110
  /**
111
  * Return empty conditions on secondary translations
87
  * @link https://github.com/pojome/elementor/issues/4839
88
  *
89
  * @since 1.0.0
90
+ * @since 1.0.4 save global $ddw_cpel_template_id
91
  *
92
  * @uses pll_get_post()
93
  *
94
+ * @global int $ddw_cpel_template_id used to save current template ID
95
  * @param int $post_id ID of the current post.
96
  * @return string Based translation, the translation ID, or the original Post ID.
97
  */
98
  function ddw_cpel_change_template_based_on_language( $post_id ) {
99
+ global $ddw_cpel_template_id;
100
 
101
+ if ( ddw_cpel_is_polylang_active() ) {
102
 
103
+ $post_id = pll_get_post( $post_id ) ?: $post_id;
104
 
105
  }
106
 
107
+ $ddw_cpel_template_id = $post_id;
108
+
109
  return $post_id;
110
 
111
  }
112
 
113
 
114
+ add_filter( 'elementor/theme/get_location_templates/condition_sub_id', 'ddw_cpel_change_condition_sub_id_based_on_language', 10, 2 );
115
+ /**
116
+ * Filter Elementor sub_conditions system: If is translated condition that is based
117
+ * on term or post return the translation ID of term or post.
118
+ *
119
+ * @since 1.0.4
120
+ *
121
+ * @uses pll_get_post()
122
+ * @uses pll_get_term()
123
+ *
124
+ * @global int $ddw_cpel_template_id used to get current template ID
125
+ * @param int $sub_id ID of the object in subcondition.
126
+ * @param array $parsed_condition condition parts
127
+ * @return int original sub ID or translated ID
128
+ */
129
+ function ddw_cpel_change_condition_sub_id_based_on_language( $sub_id, $parsed_condition ) {
130
+ global $ddw_cpel_template_id;
131
+
132
+ if ( $sub_id && ddw_cpel_is_polylang_active() && ddw_cpel_is_translation( $ddw_cpel_template_id ) ) {
133
+
134
+ if ( in_array( $parsed_condition['sub_name'], get_post_types() ) ) {
135
+
136
+ $sub_id = pll_get_post( $sub_id ) ?: $sub_id;
137
+
138
+ } else {
139
+
140
+ $sub_id = pll_get_term( $sub_id ) ?: $sub_id;
141
+
142
+ }
143
+ }
144
+
145
+ return $sub_id;
146
+
147
+ }
148
+
149
+
150
  add_filter( 'get_post_metadata', 'ddw_cpel_empty_elementor_conditions_on_translations', 10, 3 );
151
  /**
152
  * Return empty conditions on secondary translations