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

Version Description

  • 2021-04-27 =
  • Ensure Theme Builder conditions for all languages (prev. version only saves main language conditions)
  • When a template is a translation override with empty conditions
Download this release

Release Info

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

Code changes from version 1.0.2 to 1.0.3

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.2
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.2 - 2021-04-26 =
224
  * Fix Elementor template display conditions reset
225
  * Fix wp-cli error languages undefined
@@ -228,36 +232,30 @@ There are quite a few:
228
  * Added JetEngine Listing CPT translatable
229
  * WordPress PHP Coding Standards
230
 
231
-
232
  = 1.0.1 - 2020-06-17 =
233
  * Stability update for edge cases were experiencing fatal errors
234
  * Thanks to sebastienserre for correct fatal unknow pll_the_languages();
235
 
236
-
237
  = 1.0.0 - 2018-11-28 =
238
  * Official public release on WordPress.org
239
 
240
-
241
  = 0.9.1 - 2018-11-27 =
242
  * *First Release Candidate (RC) version*
243
  * New: Automatic enabling of Elementor My Templates post type for Polylang support
244
  * Tweak: Code improvements throughout
245
  * Tweak: Inline documentation and PHP doc improvements
246
 
247
-
248
  = 0.9.0 - 2018-11-26 =
249
  * *Second beta version*
250
  * New: More settings for Polylang Switcher widget
251
  * Tweak: Improved Dynamic Tags additions
252
  * Tweak: Improved Elementor Finder integration
253
 
254
-
255
  = 0.8.0 - 2018-11-25 =
256
  * *First beta version*
257
  * New: Added native Elementor Widget - Polylang Language Switcher
258
  * New: Added Dynamic Tags for Polylang (requires Elementor Pro)
259
 
260
-
261
  = 0.7.0 - 2018-11-24 =
262
  * *Second alpha version*
263
  * New: Added Elementor Finder integration for Polylang plugin links and resources
@@ -265,14 +263,12 @@ There are quite a few:
265
  * New: Added Readme file, plus `composer.json`
266
  * New: First public alpha release on GitHub
267
 
268
-
269
  = 0.5.0 - 2018-10-30 =
270
  * *Plugin idea by Brad*
271
  * *First alpha version by David*
272
  * New: Template tweaks work in form of plugin code - coding standards improvements
273
 
274
 
275
-
276
  == Upgrade Notice ==
277
 
278
  = 1.0.2 =
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
 
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
226
+
227
  = 1.0.2 - 2021-04-26 =
228
  * Fix Elementor template display conditions reset
229
  * Fix wp-cli error languages undefined
232
  * Added JetEngine Listing CPT translatable
233
  * WordPress PHP Coding Standards
234
 
 
235
  = 1.0.1 - 2020-06-17 =
236
  * Stability update for edge cases were experiencing fatal errors
237
  * Thanks to sebastienserre for correct fatal unknow pll_the_languages();
238
 
 
239
  = 1.0.0 - 2018-11-28 =
240
  * Official public release on WordPress.org
241
 
 
242
  = 0.9.1 - 2018-11-27 =
243
  * *First Release Candidate (RC) version*
244
  * New: Automatic enabling of Elementor My Templates post type for Polylang support
245
  * Tweak: Code improvements throughout
246
  * Tweak: Inline documentation and PHP doc improvements
247
 
 
248
  = 0.9.0 - 2018-11-26 =
249
  * *Second beta version*
250
  * New: More settings for Polylang Switcher widget
251
  * Tweak: Improved Dynamic Tags additions
252
  * Tweak: Improved Elementor Finder integration
253
 
 
254
  = 0.8.0 - 2018-11-25 =
255
  * *First beta version*
256
  * New: Added native Elementor Widget - Polylang Language Switcher
257
  * New: Added Dynamic Tags for Polylang (requires Elementor Pro)
258
 
 
259
  = 0.7.0 - 2018-11-24 =
260
  * *Second alpha version*
261
  * New: Added Elementor Finder integration for Polylang plugin links and resources
263
  * New: Added Readme file, plus `composer.json`
264
  * New: First public alpha release on GitHub
265
 
 
266
  = 0.5.0 - 2018-10-30 =
267
  * *Plugin idea by Brad*
268
  * *First alpha version by David*
269
  * New: Template tweaks work in form of plugin code - coding standards improvements
270
 
271
 
 
272
  == Upgrade Notice ==
273
 
274
  = 1.0.2 =
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.2
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.2' );
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.3
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.3' );
45
 
46
  /** File */
47
  define( 'CPEL__FILE__', __FILE__ );
includes/functions-conditionals.php CHANGED
@@ -82,3 +82,19 @@ function ddw_cpel_is_polylang_free_active() {
82
  return ddw_cpel_is_polylang_active() && ! ddw_cpel_is_polylang_pro_active();
83
 
84
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  return ddw_cpel_is_polylang_active() && ! ddw_cpel_is_polylang_pro_active();
83
 
84
  }
85
+
86
+
87
+ /**
88
+ * Is post a translation in secondary language
89
+ *
90
+ * @since 1.0.3
91
+ *
92
+ * @return bool TRUE if is a translation, FALSE otherwise.
93
+ */
94
+ function ddw_cpel_is_translation( $post_id ) {
95
+
96
+ $default_lang = pll_default_language();
97
+
98
+ return $default_lang !== pll_get_post_language( $post_id ) && pll_get_post( $post_id, $default_lang );
99
+
100
+ }
modules/connect/tweaks-polylang-elementor.php CHANGED
@@ -66,16 +66,14 @@ add_action( 'parse_query', 'ddw_cpel_polylang_elementor_library_conditions_parse
66
  * @link https://github.com/pojome/elementor/issues/4839
67
  *
68
  * @since 1.0.0
 
69
  *
70
  * @param WP_Query $query
71
  */
72
  function ddw_cpel_polylang_elementor_library_conditions_parse_query( $query ) {
73
 
74
- if ( is_admin() && ! empty( $query->query_vars['post_type'] ) && 'elementor_library' === $query->query_vars['post_type']
75
- && ! empty( $query->query_vars['meta_key'] )
76
- && '_elementor_conditions' === $query->query_vars['meta_key']
77
- ) {
78
- $query->set( 'lang', '' );
79
  }
80
 
81
  }
@@ -108,29 +106,47 @@ function ddw_cpel_change_template_based_on_language( $post_id ) {
108
  }
109
 
110
 
111
- add_filter( 'posts_request', 'ddw_cpel_elementor_generate_conditions_on_default_language', 10, 2 );
112
  /**
113
- * Ensure Elementor Theme Builder conditions are generated with main language
114
  *
115
- * @since 1.0.2
116
  *
117
- * @uses pll_current_language()
118
- * @uses pll_default_language()
119
- *
120
- * @param string $request SQL select query
121
- * @param WP_Query $wp_query Current query
122
- * @return string updated SQL query
123
  */
124
- function ddw_cpel_elementor_generate_conditions_on_default_language( $request, $wp_query ) {
125
 
126
- if ( function_exists( 'pll_current_language' ) && isset( $wp_query->query['meta_key'] ) && '_elementor_conditions' == $wp_query->query['meta_key'] ) {
127
 
128
- $current_lang = 'term_taxonomy_id IN (' . pll_current_language( 'term_taxonomy_id' ) . ')';
129
- $default_lang = 'term_taxonomy_id IN (' . pll_default_language( 'term_taxonomy_id' ) . ')';
130
 
131
- $request = str_replace( $current_lang, $default_lang, $request );
132
  }
133
 
134
- return $request;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  }
66
  * @link https://github.com/pojome/elementor/issues/4839
67
  *
68
  * @since 1.0.0
69
+ * @since 1.0.3 only check meta_key is '_elementor_conditions' & set lang 'all'
70
  *
71
  * @param WP_Query $query
72
  */
73
  function ddw_cpel_polylang_elementor_library_conditions_parse_query( $query ) {
74
 
75
+ if ( is_admin() && ddw_cpel_is_polylang_active() && '_elementor_conditions' === $query->query_vars['meta_key'] ) {
76
+ $query->set( 'lang', 'all' );
 
 
 
77
  }
78
 
79
  }
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
112
  *
113
+ * @since 1.0.3
114
  *
115
+ * @param mixed $null null value
116
+ * @param int $post_id post ID
117
+ * @param string $meta_key Post meta key name
118
+ * @return mixed null or empty array
 
 
119
  */
120
+ function ddw_cpel_empty_elementor_conditions_on_translations( $null, $post_id, $meta_key ) {
121
 
122
+ if ( is_admin() && ddw_cpel_is_polylang_active() && '_elementor_conditions' === $meta_key ) {
123
 
124
+ return ddw_cpel_is_translation( $post_id ) ? array( array() ) : $null;
 
125
 
 
126
  }
127
 
128
+ return $null;
129
+
130
+ }
131
+
132
+
133
+ add_filter( 'pre_update_option_elementor_pro_theme_builder_conditions', 'ddw_cpel_theme_builder_conditions_clear_empty' );
134
+ /**
135
+ * Clear empty conditions before save 'elementor_pro_theme_builder_conditions' option
136
+ *
137
+ * @since 1.0.3
138
+ *
139
+ * @param array $value array of theme builder conditions
140
+ * @return array filtered array
141
+ */
142
+ function ddw_cpel_theme_builder_conditions_clear_empty( $value ) {
143
+
144
+ foreach ( $value as $location => $items ) {
145
+ $value[ $location ] = array_filter( $items );
146
+ }
147
+
148
+ $value = array_filter( $value );
149
+
150
+ return $value;
151
 
152
  }