Repository navigation
Expand file tree
/
Copy pathdokan-wpml.php
More file actions
executable file
·2288 lines (1987 loc) · 76.2 KB
/
Copy pathdokan-wpml.php
File metadata and controls
executable file
·2288 lines (1987 loc) · 76.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: Dokan - WPML Integration
* Plugin URI: https://wedevs.com/
* Description: WPML and Dokan compatible package
* Version: 1.1.16
* Author: weDevs
* Author URI: https://wedevs.com/
* Text Domain: dokan-wpml
* WC requires at least: 8.5.0
* WC tested up to: 10.2.2
* Domain Path: /languages/
* License: GPL2
*/
/**
* Copyright (c) YEAR weDevs (email: info@wedevs.com). All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* **********************************************************************
*/
use WeDevs\DokanPro\Modules\VendorVerification\Models\VerificationMethod;
defined( 'ABSPATH' ) || exit;
/**
* Dokan_WPML class
*
* @class Dokan_WPML The class that holds the entire Dokan_WPML plugin
*/
class Dokan_WPML {
/*
* Cached options.
*
* @var array
*/
private static $cached_options = [];
/*
* WordPress Endpoints text domain
*
* @var string
*/
public $wp_endpoints = 'WP Endpoints';
/*
* Appsero client
*
* @var string
*/
protected $insights;
/**
* Constructor for the Dokan_WPML class
*
* Sets up all the appropriate hooks and actions
* within our plugin.
*
* @uses register_activation_hook()
* @uses register_deactivation_hook()
* @uses is_admin()
* @uses add_action()
*/
public function __construct() {
register_activation_hook( __FILE__, [ $this, 'dependency_missing_notice' ] );
// Declare WooCommerce feature compatibility (HPOS, cart/checkout blocks).
// Registered here — not inside the dependency-gated plugins_loaded() —
// so the declaration always runs even when WPML is inactive.
add_action( 'before_woocommerce_init', [ $this, 'declare_woocommerce_feature_compatibility' ] );
// Localize our plugin
add_action( 'init', [ $this, 'localization_setup' ] );
// load all actions and filter under plugins loaded hooks
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
// Clear option cache on option updates, additions, deletions
add_action( 'updated_option', [ $this, 'clear_option_cache' ] );
add_action( 'added_option', [ $this, 'clear_option_cache' ] );
add_action( 'deleted_option', [ $this, 'clear_option_cache' ] );
// Feed Dokan script handles to WPML's JS string scanner.
add_action( 'wp_enqueue_scripts', [ $this, 'register_dokan_scripts_for_wpml_js_scanner' ], 9999 );
// Re-register when WPML's registry is reset or String Translation reinstalled.
add_action( 'wpml_reset_plugins_before', [ $this, 'clear_wpml_js_script_registry_hash' ] );
add_action( 'activated_plugin', [ $this, 'clear_hash_when_string_translation_activates' ] );
register_activation_hook( __FILE__, [ $this, 'clear_wpml_js_script_registry_hash' ] );
}
/**
* Initializes the Dokan_WPML() class
*
* Checks for an existing Dokan_WPML() instance
* and if it doesn't find one, creates it.
*/
public static function init() {
static $instance = false;
if ( ! $instance ) {
$instance = new Dokan_WPML();
}
return $instance;
}
/**
* Execute on plugis loaded hooks
*
* @since 1.0.7 moved from constructor to plugins_loaded hook
*
* @return void
*/
public function plugins_loaded() {
if ( true !== $this->check_dependency() ) {
return;
}
// load appsero tracker
$this->appsero_init_tracker();
// Load all actions hook
add_filter( 'dokan_forced_load_scripts', [ $this, 'load_scripts_and_style' ] );
add_filter( 'dokan_force_load_extra_args', [ $this, 'load_scripts_and_style' ] );
add_filter( 'dokan_seller_setup_wizard_url', [ $this, 'render_wmpl_home_url' ], 70 );
add_filter( 'dokan_get_page_url', [ $this, 'reflect_page_url' ], 10, 4 );
add_filter( 'dokan_get_terms_condition_url', [ $this, 'get_terms_condition_url' ], 10, 2 );
add_filter( 'dokan_redirect_login', [ $this, 'redirect_if_not_login' ], 90 );
add_filter( 'dokan_force_page_redirect', [ $this, 'force_redirect_page' ], 90, 2 );
add_action( 'init', [ $this, 'handle_flushing_rewrite_rules' ] );
// Load all filters hook
add_filter('sanitize_user_meta_product_package_id', [ $this, 'set_subscription_pack_id_in_base_language' ], 10, 3 );
add_filter('dokan_vendor_subscription_package_title', [ $this, 'vendor_subscription_pack_title_translation' ], 10, 2 );
add_filter('dokan_vendor_subscription_package_id', [ $this, 'get_product_id_in_base_language' ] );
add_filter( 'dokan_get_navigation_url', [ $this, 'load_translated_url' ], 10, 3 );
add_filter( 'body_class', [ $this, 'add_dashboard_template_class_if_wpml' ], 99 );
add_filter( 'dokan_get_current_page_id', [ $this, 'dokan_set_current_page_id' ] );
add_filter( 'dokan_get_translated_page_id', [ $this, 'dokan_get_translated_page_id' ] );
add_action( 'wp_head', [ $this, 'dokan_wpml_remove_fix_fallback_links' ] );
add_filter( 'dokan_get_store_url', [ $this, 'handle_store_url_translation' ], 5, 4 );
add_action( 'dokan_store_page_query_filter', [ $this, 'load_store_page_language_switcher_filter' ], 10, 2 );
add_filter( 'dokan_dashboard_nav_settings_key', [ $this, 'filter_dashboard_settings_key' ] );
add_filter( 'dokan_dashboard_nav_menu_key', [ $this, 'filter_dashboard_settings_key' ] );
add_filter( 'dokan_dashboard_nav_submenu_key', [ $this, 'filter_dashboard_settings_key' ] );
add_filter( 'wcml_vendor_addon_configuration', [ $this, 'add_vendor_capability' ] );
add_filter('icl_lang_sel_copy_parameters', [ $this, 'set_language_switcher_copy_param' ] );
add_filter( 'dokan_vendor_subscription_product_count_query', [ $this, 'set_vendor_subscription_product_count_query' ],10 ,3 );
add_action( 'dokan_rewrite_rules_loaded', [ $this, 'register_custom_endpoint'] );
add_action( 'init', [ $this, 'fix_store_category_query_arg' ], 20 );
add_action( 'init', [ $this, 'load_wpml_admin_post_actions' ], 10 );
add_action( 'dokan_product_change_status_after_save', [ $this, 'change_product_status' ], 10, 2 );
add_action( 'dokan_product_status_revert_after_save', [ $this, 'change_product_status' ], 10, 2 );
add_filter( 'dokan_count_posts_args', [ $this, 'add_language_query_args' ] );
add_filter( 'dokan_all_products_query', [ $this, 'add_language_query_args' ] );
add_filter( 'dokan_count_posts', [ $this, 'add_language_filter_for_dokan_count_posts' ], 10, 4 );
add_filter( 'dokan_count_stock_posts_cache_key', [ $this, 'add_language_query_args_to_post_stock_count' ], 10, 4 );
add_filter( 'dokan_count_posts_instock', [ $this, 'add_language_query_args_dokan_count_posts_stock_status' ], 10, 5 );
add_filter( 'dokan_count_posts_outofstock', [ $this, 'add_language_query_args_dokan_count_posts_stock_status' ], 10, 5 );
// Single string translation.
add_action( 'dokan_pro_register_shipping_status', [ $this, 'register_shipping_status_single_string' ] );
add_action( 'dokan_pro_register_abuse_report_reason', [ $this, 'register_abuse_report_single_string' ] );
add_action( 'dokan_pro_register_rms_reason', [ $this, 'register_rma_single_string' ] );
add_filter( 'dokan_pro_shipping_status', [ $this, 'get_translated_shipping_status' ] );
add_filter( 'dokan_pro_abuse_report_reason', [ $this, 'get_translated_abuse_report_reason' ] );
add_filter( 'dokan_pro_subscription_allowed_categories', [ $this, 'get_translated_allowed_categories' ] );
add_filter( 'dokan_pro_rma_reason', [ $this, 'get_translated_rma_reason' ] );
add_action( 'dokan_pro_vendor_verification_method_created', [ $this, 'register_vendor_verification_method' ] );
add_action( 'dokan_pro_vendor_verification_method_updated', [ $this, 'register_vendor_verification_method' ] );
add_filter( 'dokan_pro_vendor_verification_method_title', [ $this, 'get_translated_verification_method_title' ] );
add_filter( 'dokan_pro_vendor_verification_method_help_text', [ $this, 'get_translated_verification_method_help_text' ] );
// Hooks for manage URL translations with Dokan and WPML.
add_action( 'dokan_disable_url_translation', [ $this, 'disable_url_translation' ] );
add_action( 'dokan_enable_url_translation', [ $this, 'enable_url_translation' ] );
add_action( 'wp', [ $this, 'set_translated_query_var_to_default_query_var' ], 11 );
add_action( 'wp', [ $this, 'set_custom_store_query_var' ], 11 );
add_filter( 'dokan_set_store_categories', [ $this, 'set_translated_category' ] );
add_filter( 'dokan_get_store_categories_in_vendor', [ $this, 'get_translated_category' ] );
// shipping methods
add_action( 'dokan_shipping_method_title_update', [ $this, 'register_shipping_method_title' ], 10, 3 );
add_filter( 'dokan_shipping_method_translatable_title', [ $this, 'get_translated_shipping_method_title' ], 10, 2 );
add_action( 'dokan_vendor_vacation_message_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_action( 'dokan_vendor_vacation_message_schedule_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_filter( 'dokan_get_vendor_vacation_message', [ $this, 'get_translated_dokan_vendor_vacation_message' ], 10, 2 );
add_action( 'dokan_vendor_biography_after_update', [ $this, 'dokan_vendor_biography_updated' ], 10, 3 );
add_filter( 'dokan_get_vendor_biography_text', [ $this, 'get_translated_dokan_vendor_biography_text' ], 10, 2 );
// Add URL translation support for language switcher.
add_filter( 'wpml_ls_language_url', [ $this, 'filter_language_switcher_url' ], 99, 2 );
// Single store endpoint translation support.
add_action( 'dokan_after_saving_settings', [ $this, 'register_single_store_custom_endpoint' ], 10, 3 );
add_action( 'dokan_rewrite_rules_loaded', [ $this, 'handle_translated_single_store_endpoint_rewrite' ] );
add_action( 'wpml_st_add_string_translation', [ $this, 'handle_single_store_endpoint_translation_update' ] );
add_action( 'dokan_product_delete', [ $this, 'before_product_delete' ] );
add_action( 'dokan_product_bulk_delete', [ $this, 'before_product_delete' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] );
}
/**
* Clear cache when option is updated, added, or deleted.
* This function accepts variable parameters to work with all three hooks.
*
* @since 1.1.13
*
* @param string $option Name of the option
*
* @return void
*/
public function clear_option_cache( $option ) {
// Clear only if the option exists in cache.
if ( empty( self::$cached_options[ $option ] ) ) {
return;
}
unset( self::$cached_options[ $option ] );
}
/**
* Initialize the plugin tracker
*
* @since 1.0.7
*
* @return void
*/
public function appsero_init_tracker() {
$client = new \Appsero\Client( 'f7973783-e0d0-4d56-bbba-229e5581b0cd', 'Dokan - WPML Integration', __FILE__ );
$this->insights = $client->insights();
$this->insights->init_plugin();
}
/**
* Print error notice if dependency not active
*
* @since 1.0.1
*
* @return void
*/
public function dependency_missing_notice() {
deactivate_plugins( plugin_basename( __FILE__ ) );
$missing_dependency = $this->check_dependency();
if ( is_wp_error( $missing_dependency ) ) {
$message = '<div class="error"><p>' . $missing_dependency->get_error_message() . '</p></div>';
wp_die( $message );
}
}
/**
* Check if dependency is active
*
* @since 1.0.7
*
* @return WP_Error|bool
*/
public function check_dependency() {
if ( ! class_exists( 'WeDevs_Dokan' ) ) {
// translators: %1$s: opening anchor tag, %2$s: closing anchor tag
$error = sprintf( __( '<b>Dokan - WPML Integration</b> requires %1$s Dokan plugin %2$s to be installed & activated!', 'dokan-wpml' ), '<a target="_blank" href="https://wedevs.com/products/plugins/dokan/">', '</a>' );
return new WP_Error( 'doakn_wpml_dependency_missing', $error );
}
if ( ! class_exists( 'SitePress' ) ) {
// translators: %1$s: opening anchor tag, %2$s: closing anchor tag
$error = sprintf( __( '<b>Dokan - WPML Integration</b> requires %1$s WPML Multilingual CMS %2$s to be installed & activated!', 'dokan-wpml' ), '<a target="_blank" href="https://wpml.org/">', '</a>' );
return new WP_Error( 'doakn_wpml_dependency_missing', $error );
}
return true;
}
/**
* Initialize plugin for localization
*
* @uses load_plugin_textdomain()
*/
public function localization_setup() {
load_plugin_textdomain( 'dokan-wpml', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Redirect seller setup wizerd into translated url
*
* @since 1.0.0
*
* @return string
*/
public function render_wmpl_home_url( $url ) {
$translated_url = apply_filters( 'wpml_home_url', $url );
return add_query_arg( array( 'page' => 'dokan-seller-setup' ), $translated_url );
}
/**
* Load custom wpml translated page url
*
* @since 1.0.0
*
* @param string $url
* @param string $name
*
* @return string
*/
public function load_translated_url( $url, $name, $new_url = false ) {
$current_lang = apply_filters( 'wpml_current_language', null );
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}
// New (React) vendor dashboard UI. The `new` host endpoint must be translated like
// every other dashboard menu item so its (translated) rewrite rule resolves — a literal
// `new` has no rewrite on translated pages and 404s. The `#<route>` hash, however, is a
// client-side React route hardcoded in the JS bundle, so it is kept verbatim.
//
// Build the base via get_dokan_url_for_language() with the translated endpoint as the
// path segment so the query string (parameter-based mode) and host (domain-based mode)
// are assembled correctly — plain string concatenation would misplace them.
if ( $new_url && ! empty( $name ) ) {
$translated_new = $this->translate_endpoint( 'new', $current_lang );
return $this->get_dokan_url_for_language( ICL_LANGUAGE_CODE, $translated_new . '/' ) . '#' . $name . '/';
}
if ( ! empty( $name ) ) {
if ( $current_lang ) {
$name_arr = explode( '/', $name );
if ( isset( $name_arr[1] ) ) {
$name_arr = array_map( function ( $part ) use ( $current_lang ) {
$part = $this->get_default_query_var( $part );
return apply_filters( 'wpml_translate_single_string', $part, $this->wp_endpoints, $part, $current_lang );
}, $name_arr );
$name = implode( '/', $name_arr );
} else {
$get_name = ( ! empty( $name_arr[0] ) ) ? $name_arr[0] : $name;
$name = apply_filters( 'wpml_translate_single_string', $get_name, $this->wp_endpoints, $get_name, $current_lang );
}
}
$url = $this->get_dokan_url_for_language( ICL_LANGUAGE_CODE, $name . '/' );
} else {
$url = $this->get_dokan_url_for_language( ICL_LANGUAGE_CODE );
}
return $url;
}
/**
* @param string $endpoint
*
* @return string
*/
private function translate_endpoint( $endpoint, $language = null ) {
return apply_filters( 'wpml_translate_single_string', $endpoint, $this->wp_endpoints, $endpoint, $language );
}
/**
* Reflect page url
*
* @since 1.0.1
*
* @return string
*/
public function reflect_page_url( $url, $page_id, $context, $subpage ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}
$page_id = wpml_object_id_filter( $page_id, 'page', true, ICL_LANGUAGE_CODE );
$url = get_permalink( $page_id );
if ( $subpage ) {
$subpages = explode( '/', $subpage );
$subpages = array_map(
function ( $item ) {
return $this->translate_endpoint( $this->get_default_query_var( $item ), ICL_LANGUAGE_CODE );
},
$subpages
);
$subpage = implode( '/', $subpages );
$url = function_exists( 'dokan_add_subpage_to_url' ) ? dokan_add_subpage_to_url( $url, $subpage ) : $url;
}
return $url;
}
/**
* Get terms and condition page url
*
* @since 1.0.1
*
* @return string
*/
public function get_terms_condition_url( $url, $page_id ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}
$page_id = wpml_object_id_filter( $page_id, 'page', true, ICL_LANGUAGE_CODE );
return get_permalink( $page_id );
}
/**
* Redirect if not login
*
* @since 1.0.1
*
* @return string
*/
public function redirect_if_not_login( $url ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}
$page_id = wc_get_page_id( 'myaccount' );
$lang_post_id = wpml_object_id_filter( $page_id, 'page', true, ICL_LANGUAGE_CODE );
return get_permalink( $lang_post_id );
}
/**
* Add language support to product query args so that cache can be managed.
*
* @param array $args product query args.
*
* @return array
*/
public function add_language_query_args( $args ) {
$args['lang'] = ICL_LANGUAGE_CODE;
return $args;
}
/**
* Vendor Product Count query override.
*
* @param mixed $result Previous result.
* @param string $post_type post type, (product)
* @param int $vendor_id Vendor ID.
* @param array $exclude_product_types Product types that need to be excluded.
*
* @return array|mixed|object|stdClass[]|null
*/
public function add_language_filter_for_dokan_count_posts( $result, $post_type, $vendor_id, $exclude_product_types ) {
global $wpdb;
if ( $result ) {
return $result;
}
$exclude_product_types_text = "'" . implode( "', '", esc_sql( $exclude_product_types ) ) . "'";
return $wpdb->get_results(
$wpdb->prepare(
"SELECT post_status, COUNT( DISTINCT wpml_translations.trid ) AS num_posts FROM {$wpdb->posts} as posts
JOIN {$wpdb->prefix}icl_translations wpml_translations ON posts.ID = wpml_translations.element_id AND wpml_translations.element_type = CONCAT('post_', posts.post_type)
INNER JOIN {$wpdb->term_relationships} AS term_relationships ON posts.ID = term_relationships.object_id
INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy ON term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id
INNER JOIN {$wpdb->terms} AS terms ON term_taxonomy.term_id = terms.term_id
WHERE
term_taxonomy.taxonomy = 'product_type'
AND terms.slug NOT IN ({$exclude_product_types_text})
AND posts.post_type = %s
AND posts.post_author = %d
GROUP BY posts.post_status",
$post_type,
$vendor_id
),
ARRAY_A
);
}
/**
* post_stock_count cache key language change support.
*
* @param string $cache_key Previous cache key.
* @param string $post_type Post type.
* @param int $user_id Vendor ID.
* @param string $stock_type Stock Status (instock, outofstock)
*
* @return string
*/
public function add_language_query_args_to_post_stock_count( $cache_key, $post_type, $user_id, $stock_type ) {
return "count_stock_posts_{$user_id}_{$post_type}_{$stock_type}_lang_" . ICL_LANGUAGE_CODE;
}
/**
* Language support added for dokan_count_posts_{stock_status}
*
* @param mixed $results Previous status.
* @param string $post_type Post Type.
* @param int $user_id Vendor ID.
* @param string $stock_type Stock Type.
* @param array $exclude_product_types Excluded product types.
*
* @return array|mixed|object|stdClass[]|null
*/
public function add_language_query_args_dokan_count_posts_stock_status( $results, $post_type, $user_id, $stock_type, $exclude_product_types = [ 'booking', 'auction' ] ) {
global $wpdb;
$exclude_product_types_text = "'" . implode( "', '", esc_sql( $exclude_product_types ) ) . "'";
if ( $results ) {
return $results;
}
return $wpdb->get_results(
$wpdb->prepare(
"SELECT p.post_status, COUNT( DISTINCT wpml_translations.trid ) AS num_posts
FROM {$wpdb->prefix}posts as p
INNER JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
JOIN {$wpdb->prefix}icl_translations wpml_translations ON p.ID = wpml_translations.element_id AND wpml_translations.element_type = CONCAT('post_', p.post_type)
WHERE p.post_type = %s
AND p.post_author = %d
AND pm.meta_key = '_stock_status'
AND pm.meta_value = %s
AND p.ID IN (
SELECT tr.object_id FROM {$wpdb->prefix}terms AS t
LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt ON t.term_id = tt.term_taxonomy_id
LEFT JOIN {$wpdb->prefix}term_relationships AS tr ON t.term_id = tr.term_taxonomy_id
WHERE tt.taxonomy = 'product_type' AND t.slug NOT IN ({$exclude_product_types_text})
)
GROUP BY p.post_status",
$post_type,
$user_id,
$stock_type
),
ARRAY_A
);
}
/**
* Undocumented function
*
* @since 1.0.1
*
* @return bool
*/
public function force_redirect_page( $flag, $page_id ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return false;
}
$lang_post_id = wpml_object_id_filter( $page_id, 'page', true, ICL_LANGUAGE_CODE );
if ( is_page( $lang_post_id ) ) {
return true;
}
return false;
}
/**
* Handle Flushing Rewrite Rules.
*
* @since 1.1.9
*
* @return void
*/
public function handle_flushing_rewrite_rules() {
if ( ! get_transient( 'dokan_wpml_flush_rewrite_rules_needed' ) ) {
return;
}
flush_rewrite_rules();
delete_transient( 'dokan_wpml_flush_rewrite_rules_needed' );
}
/**
* Filter dokan navigation url for specific language
*
* @since 1.0.0
*
* @param string $language
* @param string $name
*
* @return string [$url]
*/
public function get_dokan_url_for_language( $language, $name = '' ) {
$post_id = $this->get_raw_option( 'dashboard', 'dokan_pages' );
$lang_post_id = '';
if ( function_exists( 'wpml_object_id_filter' ) ) {
$lang_post_id = wpml_object_id_filter( $post_id, 'page', true, $language );
}
if ( (int) $lang_post_id !== 0 ) {
$url = get_permalink( $lang_post_id );
} else {
$url = apply_filters( 'wpml_home_url', get_option( 'home' ) );
}
if ( $name ) {
$urlParts = wp_parse_url( $url );
$urlParts['path'] = $urlParts['path'] . $name;
$url = http_build_url( '', $urlParts );
}
return $url;
}
/**
* Set Language switcher copy param
*
* @since 1.0.11
*
* @param array $params Copy params.
*
* @return array
*/
public function set_language_switcher_copy_param( $params ) {
$dokan_params = [
'product_listing_search',
'_product_listing_filter_nonce',
'product_search_name',
'product_cat',
'post_status',
'date',
'product_type',
'pagenum',
'product_id',
'action',
'_dokan_edit_product_nonce',
'customer_id',
'search',
'order_date_start',
'order_date_end',
'order_status',
'dokan_order_filter',
'seller_order_filter_nonce',
'order_id',
'_wpnonce',
'order_date',
'security',
'subscription_id',
'coupons_type',
'post',
'view',
'coupon_nonce_url',
'delivery_type_filter',
'chart',
'start_date_alt',
'start_date',
'end_date',
'end_date_alt',
'dokan_report_filter_nonce',
'dokan_report_filter',
'comment_status',
'type',
'_withdraw_link_nonce',
'status',
'request',
'staff_id',
'booking_id',
'booking_status',
'calendar_month',
'tab',
'filter_bookings',
'calendar_year',
'id',
'tab',
'step',
'file',
'delimiter',
'character_encoding',
'products-imported',
'products-imported-variations',
'products-failed',
'products-updated',
'products-skipped',
'file-name',
'ticket_start_date',
'ticket_end_date',
'ticket_keyword',
'ticket_status',
'dokan-support-listing-search-nonce',
'zone_id',
'instance_id',
];
return array_merge( $params, $dokan_params );
}
/**
* Get vendor dashboard settings submenu query vars.
*
* @since 1.1.1
*
* @param string|null $lang
*
* @return array
*/
public function get_translated_query_vars_map( $lang = null ): array {
$query_vars = [
'store',
'payment',
'rma',
'shipping',
'social',
'seo',
'regular-shipping',
'delivery-time',
'product-addon',
'payment-manage-dokan_razorpay',
'payment-manage-dokan_razorpay-edit',
'payment-manage-dokan_mangopay',
'payment-manage-dokan_mangopay-edit',
'payment-manage-dokan-paypal-marketplace',
'payment-manage-dokan-paypal-marketplace-edit',
'payment-manage-paypal',
'payment-manage-paypal-edit',
'payment-manage-skrill',
'payment-manage-skrill-edit',
'payment-manage-bank',
'payment-manage-bank-edit',
'payment-manage-dokan_stripe_express',
'payment-manage-dokan_stripe_express-edit',
'payment-manage-dokan-stripe-connect',
'payment-manage-dokan-stripe-connect-edit',
'payment-manage-dokan_custom',
'payment-manage-dokan_custom-edit',
'requested-quotes',
'distance-rate-shipping',
'table-rate-shipping',
'verification',
'printful',
'toc',
'biography',
'reviews',
];
$store_url = dokan_get_option( 'custom_store_url', 'dokan_general', 'store' );
if ( ! isset( $query_vars[ $store_url ] ) ) {
$query_vars[] = $store_url;
}
$query_vars = apply_filters( 'dokan_wpml_settings_query_var_map', $query_vars );
$query_vars_map = [];
foreach ( $query_vars as $query_var ) {
if ( function_exists( 'icl_register_string' ) ) {
try {
icl_register_string( $this->wp_endpoints, $query_var, $query_var );
} catch ( Exception $e ) {
// Do nothing.
}
}
$query_vars_map[ $query_var ] = $this->translate_endpoint( $query_var, $lang );
}
return $query_vars_map;
}
/**
* Add Dokan Dashboard body class when change language
*
* @since 1.0.0
*
* @param array $classes
*/
public function add_dashboard_template_class_if_wpml( $classes ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $classes;
}
global $post;
if ( ! is_object( $post ) ) {
return $classes;
}
$page_id = $this->get_raw_option( 'dashboard', 'dokan_pages' );
$current_page_id = wpml_object_id_filter( $post->ID, 'page', true, wpml_get_default_language() );
if ( ( $current_page_id == $page_id ) ) {
$classes[] = 'dokan-dashboard';
}
return $classes;
}
/**
* Load All dashboard styles and scripts
*
* @since 1.0.0
*
* @return bool
*/
public function load_scripts_and_style() {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return false;
}
global $post;
if ( ! is_object( $post ) ) {
return false;
}
$page_id = (int) $this->get_raw_option( 'dashboard', 'dokan_pages' );
$current_page_id = (int) wpml_object_id_filter( $post->ID, 'page', true, wpml_get_default_language() );
if ( ( $current_page_id === $page_id ) || ( get_query_var( 'edit' ) && is_singular( 'product' ) ) ) {
return true;
}
return false;
}
/**
* Dokan set current page id
*
* @since 1.0.2
*
* @param int page_id
*
* @return int
*/
public function dokan_set_current_page_id( $page_id ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $page_id;
}
return wpml_object_id_filter( $page_id, 'page', true, wpml_get_default_language() );
}
/**
* Dokan get translated page id.
*
* @since 1.0.9
*
* @param int $page_id Page ID to be translated.
*
* @return int
*/
public function dokan_get_translated_page_id( $page_id ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $page_id;
}
return wpml_object_id_filter( $page_id, 'page', true, ICL_LANGUAGE_CODE );
}
/**
* Set store categories with default language to store.
*
* @since 1.1.3
*
* @param array $categories Store Categories.
*
* @return array
*/
public function set_translated_category( $categories ) {
if ( ! function_exists( 'wpml_object_id_filter' ) || ! function_exists( 'wpml_get_active_languages' ) ) {
return $categories;
}
$all_categories = [];
$languages = wpml_get_active_languages();
foreach ( $categories as $store_cat_id ) {
foreach ( $languages as $code => $language ) {
$translated_cat_id = wpml_object_id_filter( $store_cat_id, 'store_category', true, $code );
$all_categories[] = $translated_cat_id;
}
}
return array_unique( $all_categories );
}
/**
* Get store categories with current translation to store.
*
* @since 1.1.3
*
* @param WP_Term[] $categories Store Categories.
*
* @return array
*/
public function get_translated_category( $categories ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $categories;
}
$category_ids = array_unique(
array_map(
function ( $store_cat ) {
return wpml_object_id_filter( $store_cat->term_id, 'store_category', true, null );
},
$categories
)
);
return array_map(
function ( $category_id ) {
return get_term( $category_id, 'store_category' );
},
$category_ids
);
}
/**
* Set Vendor Subscription product count query on based language.
*
* @since 1.1.1
*
* @param string $query Product Query.
* @param int $vendor_id Vendor Id.
* @param array $allowed_status Allowed Status.
*
* @return string
*/
public function set_vendor_subscription_product_count_query( $query, $vendor_id, $allowed_status ) {
global $wpdb;
$status = "'" . implode( "','", $allowed_status ) . "'";
return $wpdb->prepare(
"SELECT count( DISTINCT wpml_translations.trid ) as total
FROM {$wpdb->prefix}posts as posts
JOIN {$wpdb->prefix}icl_translations wpml_translations
ON posts.ID = wpml_translations.element_id
AND wpml_translations.element_type = CONCAT('post_', posts.post_type)
WHERE 1=1
AND posts.post_type = 'product'
AND posts.post_author = %d
AND posts.post_status IN ( {$status} )
",
$vendor_id
);
}
/**
* Store Vendor Subscription pack in default language.
*
* @since 1.0.11
*
* @param mixed $meta_value Meta Value
* @param string $meta_key Meta Key
* @param string $object_type Object Type
*
* @return int
*/
public function set_subscription_pack_id_in_base_language( $meta_value, $meta_key, $object_type ) {
if ( 'product_package_id' !== $meta_key || 'user' !== $object_type ) {
return $meta_value;
}
return $this->get_product_id_in_base_language( absint( $meta_value ) );
}
/**
* Dokan get base product id from translated product id.
*
* @since 1.0.11
*
* @param int $product_id Product ID.
*