3
3
Plugin Name: Dokan - WPML Integration
4
4
Plugin URI: https://wedevs.com/
5
5
Description: WPML and Dokan compitable package
6
- Version: 1.0.2
6
+ Version: 1.0.3
7
7
Author: weDevs
8
8
Author URI: https://wedevs.com/
9
9
Text Domain: dokan-wpml
10
10
WC requires at least: 3.0
11
- WC tested up to: 3.8.0
11
+ WC tested up to: 4.7.1
12
12
Domain Path: /languages/
13
13
License: GPL2
14
14
*/
48
48
*/
49
49
class Dokan_WPML {
50
50
51
+ /*
52
+ * WordPress Endpoints text domain
53
+ *
54
+ * @var string
55
+ */
56
+ public $ wp_endpoints = 'WP Endpoints ' ;
57
+
51
58
/**
52
59
* Constructor for the Dokan_WPML class
53
60
*
@@ -60,24 +67,26 @@ class Dokan_WPML {
60
67
* @uses add_action()
61
68
*/
62
69
public function __construct () {
63
- register_activation_hook ( __FILE__ , array ( $ this , 'dependency_missing_notice ' ) );
70
+ register_activation_hook ( __FILE__ , [ $ this , 'dependency_missing_notice ' ] );
64
71
65
72
// Localize our plugin
66
- add_action ( 'init ' , array ( $ this , 'localization_setup ' ) );
73
+ add_action ( 'init ' , [ $ this , 'localization_setup ' ] );
67
74
68
75
// Load all actions hook
69
- add_filter ( 'dokan_forced_load_scripts ' , array ( $ this , 'load_scripts_and_style ' ) );
70
- add_filter ( 'dokan_force_load_extra_args ' , array ( $ this , 'load_scripts_and_style ' ) );
71
- add_filter ( 'dokan_seller_setup_wizard_url ' , array ( $ this , 'render_wmpl_home_url ' ) , 70 );
72
- add_filter ( 'dokan_get_page_url ' , array ( $ this , 'reflect_page_url ' ) , 10 , 3 );
73
- add_filter ( 'dokan_get_terms_condition_url ' , array ( $ this , 'get_terms_condition_url ' ) , 10 , 2 );
74
- add_filter ( 'dokan_redirect_login ' , array ( $ this , 'redirect_if_not_login ' ) , 90 );
75
- add_filter ( 'dokan_force_page_redirect ' , array ( $ this , 'force_redirect_page ' ) , 90 , 2 );
76
+ add_filter ( 'dokan_forced_load_scripts ' , [ $ this , 'load_scripts_and_style ' ] );
77
+ add_filter ( 'dokan_force_load_extra_args ' , [ $ this , 'load_scripts_and_style ' ] );
78
+ add_filter ( 'dokan_seller_setup_wizard_url ' , [ $ this , 'render_wmpl_home_url ' ] , 70 );
79
+ add_filter ( 'dokan_get_page_url ' , [ $ this , 'reflect_page_url ' ] , 10 , 3 );
80
+ add_filter ( 'dokan_get_terms_condition_url ' , [ $ this , 'get_terms_condition_url ' ] , 10 , 2 );
81
+ add_filter ( 'dokan_redirect_login ' , [ $ this , 'redirect_if_not_login ' ] , 90 );
82
+ add_filter ( 'dokan_force_page_redirect ' , [ $ this , 'force_redirect_page ' ] , 90 , 2 );
76
83
77
84
// Load all filters hook
78
- add_filter ( 'dokan_get_navigation_url ' , array ( $ this , 'load_translated_url ' ) , 10 ,2 );
79
- add_filter ( 'body_class ' , array ( $ this , 'add_dashboard_template_class_if_wpml ' ) , 99 );
85
+ add_filter ( 'dokan_get_navigation_url ' , [ $ this , 'load_translated_url ' ] , 10 ,2 );
86
+ add_filter ( 'body_class ' , [ $ this , 'add_dashboard_template_class_if_wpml ' ] , 99 );
80
87
add_filter ( 'dokan_get_current_page_id ' , [ $ this , 'dokan_set_current_page_id ' ] );
88
+ add_filter ( 'dokan_get_dashboard_nav ' , [ $ this , 'replace_dokan_dashboard_nav_key ' ] );
89
+ add_action ( 'wp_head ' , [ $ this , 'dokan_wpml_remove_fix_fallback_links ' ] );
81
90
}
82
91
83
92
/**
@@ -129,12 +138,12 @@ public function localization_setup() {
129
138
}
130
139
131
140
/**
132
- * Redirect seller setup wizerd into translated url
133
- *
134
- * @since 1.0.0
135
- *
136
- * @return void
137
- * */
141
+ * Redirect seller setup wizerd into translated url
142
+ *
143
+ * @since 1.0.0
144
+ *
145
+ * @return void
146
+ */
138
147
public function render_wmpl_home_url ( $ url ) {
139
148
$ translated_url = apply_filters ( 'wpml_home_url ' , $ url );
140
149
return add_query_arg ( array ( 'page ' => 'dokan-seller-setup ' ), $ translated_url );
@@ -151,12 +160,27 @@ public function render_wmpl_home_url( $url ) {
151
160
* @return string
152
161
*/
153
162
function load_translated_url ( $ url , $ name ) {
163
+ $ current_lang = apply_filters ( 'wpml_current_language ' , NULL );
164
+
154
165
if ( ! function_exists ( 'wpml_object_id_filter ' ) ) {
155
166
return $ url ;
156
167
}
157
168
158
169
if ( ! empty ( $ name ) ) {
170
+
171
+ if ( $ current_lang ) {
172
+ $ name_arr = explode ( '/ ' , $ name );
173
+
174
+ if ( isset ( $ name_arr [1 ] ) ) {
175
+ $ name = apply_filters ( 'wpml_translate_single_string ' , $ name_arr [0 ], $ this ->wp_endpoints , $ name_arr [0 ], $ current_lang ).'/ ' .$ name_arr [1 ];
176
+ } else {
177
+ $ get_name = ( ! empty ( $ name_arr [0 ] ) ) ? $ name_arr [0 ] : $ name ;
178
+ $ name = apply_filters ( 'wpml_translate_single_string ' , $ get_name , $ this ->wp_endpoints , $ get_name , $ current_lang );
179
+ }
180
+ }
181
+
159
182
$ url = $ this ->get_dokan_url_for_language ( ICL_LANGUAGE_CODE ).$ name .'/ ' ;
183
+
160
184
} else {
161
185
$ url = $ this ->get_dokan_url_for_language ( ICL_LANGUAGE_CODE );
162
186
}
@@ -165,12 +189,36 @@ function load_translated_url( $url, $name ) {
165
189
}
166
190
167
191
/**
168
- * Reflect page url
169
- *
170
- * @since 1.0.1
171
- *
172
- * @return void
173
- **/
192
+ * Replace dashboard key language wise
193
+ *
194
+ * @param array $urls
195
+ *
196
+ * @since 2.4
197
+ *
198
+ * @return array $urls
199
+ */
200
+ public function replace_dokan_dashboard_nav_key ( $ urls ) {
201
+ $ current_lang = apply_filters ( 'wpml_current_language ' , NULL );
202
+ $ new_urls = $ urls ;
203
+
204
+ foreach ( $ urls as $ get_key => $ item ) {
205
+ $ new_key = apply_filters ( 'wpml_translate_single_string ' , $ get_key , $ this ->wp_endpoints , $ get_key , $ current_lang );
206
+ if ( $ get_key != $ new_key ) {
207
+ $ new_urls [$ new_key ] = $ new_urls [$ get_key ];
208
+ unset($ new_urls [$ get_key ]);
209
+ }
210
+ }
211
+
212
+ return $ new_urls ;
213
+ }
214
+
215
+ /**
216
+ * Reflect page url
217
+ *
218
+ * @since 1.0.1
219
+ *
220
+ * @return void
221
+ */
174
222
public function reflect_page_url ( $ url , $ page_id , $ context ) {
175
223
if ( ! function_exists ( 'wpml_object_id_filter ' ) ) {
176
224
return $ url ;
@@ -182,12 +230,12 @@ public function reflect_page_url( $url, $page_id, $context ) {
182
230
}
183
231
184
232
/**
185
- * Get terms and condition page url
186
- *
187
- * @since 1.0.1
188
- *
189
- * @return url
190
- * */
233
+ * Get terms and condition page url
234
+ *
235
+ * @since 1.0.1
236
+ *
237
+ * @return url
238
+ */
191
239
public function get_terms_condition_url ( $ url , $ page_id ) {
192
240
if ( ! function_exists ( 'wpml_object_id_filter ' ) ) {
193
241
return $ url ;
@@ -199,12 +247,12 @@ public function get_terms_condition_url( $url, $page_id ) {
199
247
}
200
248
201
249
/**
202
- * Redirect if not login
203
- *
204
- * @since 1.0.1
205
- *
206
- * @return void
207
- * */
250
+ * Redirect if not login
251
+ *
252
+ * @since 1.0.1
253
+ *
254
+ * @return void
255
+ */
208
256
public function redirect_if_not_login ( $ url ) {
209
257
if ( ! function_exists ( 'wpml_object_id_filter ' ) ) {
210
258
return $ url ;
@@ -217,12 +265,12 @@ public function redirect_if_not_login( $url ) {
217
265
}
218
266
219
267
/**
220
- * undocumented function
221
- *
222
- * @since 1.0.1
223
- *
224
- * @return void
225
- * */
268
+ * Undocumented function
269
+ *
270
+ * @since 1.0.1
271
+ *
272
+ * @return void
273
+ */
226
274
public function force_redirect_page ( $ flag , $ page_id ) {
227
275
if ( ! function_exists ( 'wpml_object_id_filter ' ) ) {
228
276
return false ;
@@ -339,7 +387,7 @@ public function dokan_set_current_page_id( $page_id ) {
339
387
/**
340
388
* Get raw value from database
341
389
*
342
- * @since DOKAN_WPML_SINCE
390
+ * @since 1.0.3
343
391
*
344
392
* @param string $option
345
393
* @param string $section
@@ -360,6 +408,23 @@ public function get_raw_option( $option, $section, $default = '' ) {
360
408
return isset ( $ options [ $ option ] ) ? $ options [ $ option ] : $ default ;
361
409
}
362
410
411
+ /**
412
+ * Remove callback links with WPML on vendor dashboard
413
+ *
414
+ * @since 1.0.3
415
+ */
416
+ public function dokan_wpml_remove_fix_fallback_links () {
417
+ if ( function_exists ( 'dokan_is_seller_dashboard ' ) && ! dokan_is_seller_dashboard () ) {
418
+ return ;
419
+ }
420
+
421
+ if ( ! class_exists ( 'WPML_Fix_Links_In_Display_As_Translated_Content ' ) || ! function_exists ( 'dokan_remove_hook_for_anonymous_class ' ) ) {
422
+ return ;
423
+ }
424
+
425
+ dokan_remove_hook_for_anonymous_class ( 'the_content ' , 'WPML_Fix_Links_In_Display_As_Translated_Content ' , 'fix_fallback_links ' , 99 );
426
+ }
427
+
363
428
} // Dokan_WPML
364
429
365
430
function dokan_load_wpml () {
0 commit comments