-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathecwid-shopping-cart.php
3077 lines (2349 loc) · 87.9 KB
/
ecwid-shopping-cart.php
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: Ecwid by Lightspeed Ecommerce Shopping Cart
Plugin URI: http://www.ecwid.com?partner=wporg
Description: Ecwid by Lightspeed is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
Text Domain: ecwid-shopping-cart
Author: Ecwid Ecommerce
Version: 6.12.24
Author URI: https://ecwid.to/ecwid-site
License: GPLv2 or later
*/
register_activation_hook( __FILE__, 'ecwid_store_activate' );
register_deactivation_hook( __FILE__, 'ecwid_store_deactivate' );
register_uninstall_hook( __FILE__, 'ecwid_uninstall' );
define( 'ECWID_API_AVAILABILITY_CHECK_TIME', 60 * 60 * 3 );
define( 'ECWID_TRIMMED_DESCRIPTION_LENGTH', 160 );
if ( ! defined( 'ECWID_PLUGIN_DIR' ) ) {
define( 'ECWID_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'ECWID_TEMPLATES_DIR' ) ) {
define( 'ECWID_TEMPLATES_DIR', ECWID_PLUGIN_DIR . 'templates' );
}
if ( ! defined( 'ECWID_PLUGIN_BASENAME' ) ) {
define( 'ECWID_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
}
if ( ! defined( 'ECWID_PLUGIN_URL' ) ) {
define( 'ECWID_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'ECWID_SHORTCODES_DIR' ) ) {
define( 'ECWID_SHORTCODES_DIR', ECWID_PLUGIN_DIR . 'includes/shortcodes' );
}
add_action( 'plugins_loaded', 'ecwid_init_integrations' );
add_filter( 'plugins_loaded', 'ecwid_load_textdomain' );
if ( is_admin() ) {
add_action( 'init', 'ecwid_apply_theme', 0 );
add_action( 'init', 'ecwid_maybe_remove_emoji' );
add_action( 'admin_init', 'ecwid_settings_api_init' );
add_action( 'admin_init', 'ecwid_check_version' );
add_action( 'wp_ajax_ec_check_api_cache', 'ecwid_admin_check_api_cache' );
add_action( 'admin_enqueue_scripts', 'ecwid_common_admin_scripts' );
add_action( 'admin_enqueue_scripts', 'ecwid_register_admin_styles' );
add_action( 'admin_enqueue_scripts', 'ecwid_register_settings_styles' );
add_action( 'admin_enqueue_scripts', 'ecwid_enqueue_cache_control' );
add_action( 'wp_ajax_ecwid_hide_vote_message', 'ecwid_hide_vote_message' );
add_action( 'wp_ajax_ecwid_hide_message', 'ecwid_ajax_hide_message' );
add_action( 'wp_ajax_ecwid_reset_categories_cache', 'ecwid_reset_categories_cache' );
add_action( 'wp_ajax_ecwid_create_store', 'ecwid_ajax_create_store' );
add_action( 'wp_ajax_ecwid_sync_products', 'ecwid_sync_products' );
add_action( 'admin_post_ecwid_sync_products', 'ecwid_sync_products' );
add_action( 'admin_post_ec_connect', 'ecwid_admin_post_connect' );
add_action( 'admin_post_ecwid_get_debug', 'ecwid_get_debug_file' );
add_action( 'admin_head', 'ecwid_ie8_fonts_inclusion' );
add_action( 'get_footer', 'ecwid_admin_get_footer' );
add_action( 'admin_init', 'ecwid_process_oauth_params' );
add_action( 'admin_notices', 'ecwid_show_admin_messages' );
add_filter( 'plugin_action_links_' . ECWID_PLUGIN_BASENAME, 'ecwid_plugin_actions' );
add_filter( 'tiny_mce_before_init', 'ecwid_tinymce_init' );
} else {
add_shortcode( 'ecwid_script', 'ecwid_script_shortcode' );
add_action( 'init', 'ecwid_backward_compatibility' );
add_action( 'init', 'ecwid_check_api_cache' );
add_action( 'template_redirect', 'ecwid_404_on_broken_escaped_fragment' );
// ecwid_apply_theme - why not init?
add_action( 'template_redirect', 'ecwid_apply_theme' );
add_action( 'wp', 'ecwid_seo_ultimate_compatibility', 0 );
add_action( 'wp', 'ecwid_remove_default_canonical' );
add_filter( 'wp', 'ecwid_seo_compatibility_init', 0 );
add_action( 'wp_head', 'ecwid_seo_compatibility_restore', 1000 );
add_action( 'wp_head', 'ecwid_print_inline_js_config' );
add_action( 'wp_head', 'ecwid_product_browser_url_in_head' );
add_action( 'send_headers', 'ecwid_503_on_store_closed' );
add_action( 'wp_enqueue_scripts', 'ecwid_enqueue_frontend' );
add_filter( 'wp_title', 'ecwid_seo_title', 10000, 3 );
add_filter( 'document_title_parts', 'ecwid_seo_title_parts' );
add_filter( 'widget_meta_poweredby', 'ecwid_add_credits' );
add_filter( 'body_class', 'ecwid_body_class' );
add_action( 'redirect_canonical', 'ecwid_redirect_canonical', 10, 2 );
$ecwid_seo_title = '';
}//end if
add_action( 'admin_bar_menu', 'add_ecwid_admin_bar_node', 1000 );
if ( get_option( 'ecwid_last_oauth_fail_time' ) > 0 ) {
add_action( 'plugins_loaded', 'ecwid_test_oauth' );
}
require_once ECWID_PLUGIN_DIR . 'lib/ecwid_platform.php';
require_once ECWID_PLUGIN_DIR . 'lib/ecwid_api_v3.php';
require_once ECWID_PLUGIN_DIR . 'includes/themes.php';
require_once ECWID_PLUGIN_DIR . 'includes/widgets.php';
require_once ECWID_PLUGIN_DIR . 'includes/shortcodes.php';
require_once ECWID_PLUGIN_DIR . 'includes/kliken.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ec-store-oembed.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-message-manager.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-store-editor.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-product-popup.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-oauth.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-products.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-config.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-admin.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-admin-main-page.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ec-store-admin-access.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-static-page.php';
if ( is_admin() ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-admin-ui-framework.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-help-page.php';
if ( ! Ecwid_Admin::disable_dashboard() ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-custom-admin-page.php';
}
}
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-nav-menus.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-ajax-defer-renderer.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ec-store-defer-init.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-store-page.php';
require_once ECWID_PLUGIN_DIR . 'lib/ecwid_product.php';
require_once ECWID_PLUGIN_DIR . 'lib/ecwid_category.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-seo-links.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-html-meta.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-wp-dashboard-feed.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-well-known.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-admin-storefront-page.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-admin-developers-page.php';
if ( version_compare( phpversion(), '5.6', '>=' ) ) {
require_once ECWID_PLUGIN_DIR . 'includes/importer/importer.php';
}
$version = get_bloginfo( 'version' );
if ( version_compare( $version, '4.0' ) >= 0 ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-customizer.php';
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-floating-minicart.php';
}
if ( strpos( $version, '5.0' ) === 0 || version_compare( $version, '5.0' ) > 0 ) {
require_once ECWID_PLUGIN_DIR . 'includes/gutenberg/class-ecwid-gutenberg.php';
}
if ( strpos( $version, '5.5' ) === 0 || version_compare( $version, '5.5' ) >= 0 ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ec-store-sitemap-provider.php';
}
if ( Ecwid_Config::is_cli_running() ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ec-store-wp-cli.php';
}
// Needs to be in both front-end and back-end to allow admin zone recognize the shortcode
foreach ( Ecwid_Shortcode_Base::get_store_shortcode_names() as $shortcode_name ) {
add_shortcode( $shortcode_name, 'ecwid_shortcode' );
}
add_action( 'update_option_' . Ecwid_Api_V3::TOKEN_OPTION_NAME, array( 'Ecwid_Store_Page', 'set_store_url' ) );
add_action( 'update_option_' . Ecwid_Store_Page::OPTION_MAIN_STORE_PAGE_ID, array( 'Ecwid_Store_Page', 'set_store_url' ) );
add_action( 'update_option_rewrite_rules', array( 'Ecwid_Store_Page', 'set_store_url' ) );
function ecwid_init_integrations() {
if ( ! function_exists( 'get_plugins' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$integrations = array(
'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'aiosp',
'wordpress-seo/wp-seo.php' => 'wpseo',
'wordpress-seo-premium/wp-seo-premium.php' => 'wpseo',
'divi-builder/divi-builder.php' => 'divibuilder',
'autoptimize/autoptimize.php' => 'autoptimize',
'js_composer/js_composer.php' => 'wpbakery-composer',
'beaver-builder-lite-version/fl-builder.php' => 'beaver-builder',
'bb-plugin/fl-builder.php' => 'beaver-builder',
'elementor/elementor.php' => 'elementor',
'sitepress-multilingual-cms/sitepress.php' => 'wpml',
'pwa/pwa.php' => 'pwa',
'polylang/polylang.php' => 'polylang',
'wp-rocket/wp-rocket.php' => 'wprocket',
'urbango-core/main.php' => 'urbango',
'seo-by-rank-math/rank-math.php' => 'rank-math',
'litespeed-cache/litespeed-cache.php' => 'litespeed-cache',
'sg-cachepress/sg-cachepress.php' => 'sg-optimizer',
'google-sitemap-generator/sitemap.php' => 'google-sitemap-generator',
'jetpack/jetpack.php' => 'jetpack',
);
$old_wordpress = version_compare( get_bloginfo( 'version' ), '5.0', '<' );
$old_php = version_compare( phpversion(), '5.4', '<' );
// that integration did not work well with older php
// and it is not needed for newer wordpress since blocks are a part of its core
if ( ! $old_php && $old_wordpress ) {
$integrations['gutenberg/gutenberg.php'] = 'gutenberg';
}
foreach ( $integrations as $plugin => $class ) {
if ( is_plugin_active( $plugin ) ) {
require_once ECWID_PLUGIN_DIR . 'includes/integrations/class-ecwid-integration-' . $class . '.php';
}
}
// exception case when divi builder supplied from theme
if ( function_exists( 'ecwid_get_theme_identification' ) ) {
$divi = 'divi-builder/divi-builder.php';
if ( ! is_plugin_active( $divi ) && ecwid_get_theme_identification() === 'Divi' ) {
require_once ECWID_PLUGIN_DIR . 'includes/integrations/class-ecwid-integration-' . $integrations[ $divi ] . '.php';
}
}
}
add_action( 'admin_post_ecwid_estimate_sync', 'ecwid_estimate_sync' );
function ecwid_estimate_sync() {
$p = new Ecwid_Products();
$result = $p->estimate_sync();
echo json_encode( $result );
}
if ( version_compare( $version, '3.6' ) < 0 ) {
/**
* A copy of has_shortcode functionality from wordpress 3.6
* http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/shortcodes.php
*/
if ( ! function_exists( 'shortcode_exists' ) ) {
function shortcode_exists( $tag ) {
global $shortcode_tags;
return array_key_exists( $tag, $shortcode_tags );
}
}
if ( ! function_exists( 'has_shortcode' ) ) {
function has_shortcode( $content, $tag ) {
if ( false === strpos( $content, '[' ) ) {
return false;
}
if ( shortcode_exists( $tag ) ) {
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) )
return false;
foreach ( $matches as $shortcode ) {
if ( $tag === $shortcode[2] ) {
return true;
} elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) {
return true;
}
}
}
return false;
}
}
}
if ( is_admin() ) {
$main_button_class = '';
if ( version_compare( $version, '3.8-beta' ) > 0 ) {
$main_button_class = 'button-primary';
} else {
$main_button_class = 'pure-button pure-button-primary';
}
define( 'ECWID_MAIN_BUTTON_CLASS', $main_button_class );
}
function ecwid_body_class( $classes ) {
if ( Ecwid_Store_Page::is_store_page() ) {
$classes[] = 'ecwid-shopping-cart';
}
return $classes;
}
function ecwid_redirect_canonical( $redirect_url, $requested_url ) {
if ( ! is_front_page() ) {
return $redirect_url;
}
if ( strpos( $requested_url, '_escaped_fragment_' ) === false ) {
return $redirect_url;
}
$parsed = parse_url( $requested_url );
$query = array();
parse_str( $parsed['query'], $query );
if ( ! array_key_exists( '_escaped_fragment_', $query) ) {
return $redirect_url;
}
if ( ! Ecwid_Store_Page::is_store_page() ) {
return $redirect_url;
}
return $requested_url;
}
function ecwid_ie8_fonts_inclusion() {
$user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
if ( strpos( $user_agent, 'MSIE 8' ) === false ) {
return;
}
$url = ECWID_PLUGIN_URL . 'fonts/ecwid-logo.eot';
?>
<style>
@font-face {
font-family: "ecwid-logo";
src: url('<?php echo esc_url( $url ); ?>');
}
</style>
<?php
}
add_action( 'wp_head', 'ecwid_maybe_remove_emoji', 0 );
function ecwid_maybe_remove_emoji() {
if ( Ecwid_Store_page::is_store_page() && get_option( 'ecwid_remove_emoji' ) == 'Y' ) {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
}
}
add_action( 'wp_ajax_ecwid_get_product_info', 'ecwid_ajax_get_product_info' );
add_action( 'wp_ajax_nopriv_ecwid_get_product_info', 'ecwid_ajax_get_product_info' );
add_filter( 'redirect_canonical', 'ecwid_redirect_canonical2', 10, 3 );
function ecwid_redirect_canonical2( $redir, $req ) {
global $wp_query;
$adds_slash = $req . '/' == $redir;
$adds_slash |= urldecode( $req . '/' ) == urldecode( $redir );
if ( Ecwid_Store_Page::is_store_page() && $adds_slash ) {
return $req;
}
return $redir;
}
add_action( 'current_screen', 'ecwid_add_deactivation_popup' );
function ecwid_add_deactivation_popup() {
if ( get_current_screen()->id == 'plugins' ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-popup-deactivate.php';
$popup = new Ecwid_Popup_Deactivate();
if ( ! $popup->is_disabled() ) {
Ecwid_Popup::add_popup( $popup );
}
}
}
function ecwid_enqueue_frontend() {
global $ecwid_current_theme;
if ( $ecwid_current_theme && $ecwid_current_theme->historyjs_html4mode || get_option( 'ecwid_historyjs_html4mode' ) ) {
wp_enqueue_script('ecwid-historyjs-wa', ECWID_PLUGIN_URL . 'js/historywa.js');
}
$version = get_bloginfo( 'version' );
if ( ! wp_script_is( 'jquery-ui-widget' ) && version_compare( $version, '5.6' ) < 0 ) {
wp_enqueue_script( 'jquery-ui-widget', includes_url() . 'js/jquery/ui/widget.min.js', array( 'jquery' ) );
}
wp_enqueue_style( 'ecwid-css', ECWID_PLUGIN_URL . 'css/frontend.css', array(), get_option( 'ecwid_plugin_version' ) );
wp_enqueue_script( 'ecwid-frontend-js', ECWID_PLUGIN_URL . 'js/frontend.js', array( 'jquery' ), get_option( 'ecwid_plugin_version' ), true );
wp_localize_script( 'ecwid-frontend-js', 'ecwidParams', array(
'useJsApiToOpenStoreCategoriesPages' => Ecwid_Nav_Menus::should_use_js_api_for_categories_menu(),
'storeId' => get_ecwid_store_id()
));
if ( get_post() && get_post()->post_type == Ecwid_Products::POST_TYPE_PRODUCT ) {
wp_enqueue_script( 'ecwid-post-product', ECWID_PLUGIN_URL . 'js/post-product.js', array(), get_option( 'ecwid_plugin_version' ), true );
$meta = get_post_meta( get_the_ID(), 'ecwid_id' );
wp_localize_script( 'ecwid-post-product', 'ecwidPost', array(
'productId' => $meta[0],
'storePageUrl' => Ecwid_Store_Page::get_store_url()
) );
}
if ( is_active_widget( false, false, 'ecwidrecentlyviewed' ) ) {
wp_enqueue_script( 'ecwid-recently-viewed', ECWID_PLUGIN_URL . 'js/recently-viewed-common.js', array( 'jquery', 'utils' ), get_option( 'ecwid_plugin_version' ), true );
wp_localize_script(
'ecwid-products-list-js',
'wp_ecwid_products_list_vars',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'is_api_available' => ecwid_is_paid_account()
)
);
}
if ( is_plugin_active( 'contact-form-7-designer/cf7-styles.php' ) ) {
wp_enqueue_script( 'ecwid-cf7designer', ECWID_PLUGIN_URL . 'js/cf7designer.js', array(), get_option( 'ecwid-plugin-version' ), true );
}
if ( current_user_can( Ecwid_Admin::get_capability() ) ) {
wp_enqueue_style( 'ecwid-fonts-css', ECWID_PLUGIN_URL . 'css/fonts.css', array(), get_option( 'ecwid_plugin_version' ) );
}
if ( Ecwid_Store_Page::is_store_page() && ( current_user_can( Ecwid_Admin::get_capability() ) || is_admin_bar_showing() ) ) {
$is_post_edit_replace = true;
if ( Ecwid_Config::is_wl() && ! Ecwid_Api_V3::is_available() ) {
$is_post_edit_replace = false;
}
if ( $is_post_edit_replace ) {
$post_edit_url = 'https://my.ecwid.com/#';
$is_api_available = false;
if ( Ecwid_Config::is_wl() || Ecwid_Api_V3::is_available() ) {
$post_edit_url = get_admin_url() . 'admin.php?page=ec-store&ec-store-page=';
$is_api_available = true;
}
if ( ! ecwid_is_demo_store() ) {
wp_enqueue_script( 'ecwid-admin-bar-js', ECWID_PLUGIN_URL . 'js/admin-bar.js', array( 'jquery' ), get_option( 'ecwid_plugin_version' ) );
wp_localize_script( 'ecwid-admin-bar-js', 'ecwidEditPostLinkParams', array(
'languages' => array(
'editProduct' => __('Edit Product', 'ecwid-shopping-cart'),
'editCategory' => __('Edit Category', 'ecwid-shopping-cart')
),
'url' => $post_edit_url,
'admin_url' => admin_url(),
'is_api_available' => $is_api_available
));
}
}
}
}
function ecwid_print_inline_js_config() {
$js = PHP_EOL;
$js .= 'window.ec = window.ec || Object()' . PHP_EOL;
$js .= 'window.ec.config = window.ec.config || Object();' . PHP_EOL;
$js .= 'window.ec.config.enable_canonical_urls = true;' . PHP_EOL;
$plugins_disabling_interactive = array(
'shiftnav-pro/shiftnav.php',
'easymega/easymega.php',
);
foreach ( $plugins_disabling_interactive as $plugin ) {
if ( is_plugin_active( $plugin ) ) {
$js .= 'window.ec.config.interactive = false;' . PHP_EOL;
break;
}
}
$js = apply_filters( 'ecwid_inline_js_config', $js ) . PHP_EOL;
echo sprintf( '<script data-cfasync="false" data-no-optimize="1" type="text/javascript">%s</script>' . PHP_EOL, $js ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
add_action( 'ecwid_inline_js_config', 'ecwid_add_chameleon' );
function ecwid_add_chameleon( $js ) {
$colors = array();
foreach ( array( 'foreground', 'background', 'link', 'price', 'button' ) as $kind ) {
$color = get_option( 'ecwid_chameleon_colors_' . $kind );
if ( $color ) {
$colors[ 'color-' . $kind ] = $color;
}
}
if ( ! get_option( 'ecwid_use_chameleon' ) && empty( $colors ) ) {
return $js;
}
if ( empty( $colors ) ) {
$colors = 'auto';
}
$colors = json_encode( $colors );
$font = '"auto"';
$chameleon = apply_filters( 'ecwid_chameleon_settings', array( 'colors' => $colors, 'font' => $font ) );
if ( ! is_array( $chameleon ) ) {
$chameleon = array(
'colors' => $colors,
'font' => $font,
);
}
if ( ! isset( $chameleon['colors'] ) ) {
$chameleon['colors'] = json_encode( $colors );
}
if ( ! isset( $chameleon['font'] ) ) {
$chameleon['font'] = $font;
}
$js .= 'window.ec.config.chameleon = window.ec.config.chameleon || Object();' . PHP_EOL;
$js .= sprintf( 'window.ec.config.chameleon.font = %s;', $chameleon['font'] ) . PHP_EOL;
$js .= sprintf( 'window.ec.config.chameleon.colors = %s;', $chameleon['colors'] ) . PHP_EOL;
return $js;
}
function ecwid_load_textdomain() {
load_plugin_textdomain( 'ecwid-shopping-cart', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
function ecwid_404_on_broken_escaped_fragment() {
if ( !Ecwid_Api_V3::is_available() ) {
return;
}
$params = array();
if (isset($_GET['_escaped_fragment_'])) {
$params = ecwid_parse_escaped_fragment();
} elseif (Ecwid_Seo_Links::is_product_browser_url()) {
$params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
}
if (isset($params['mode']) && !empty($params['mode']) && isset($params['id'])) {
$result = array();
$is_root_cat = $params['mode'] == 'category' && $params['id'] == 0;
if ($params['mode'] == 'product') {
$result = Ecwid_Product::get_by_id( $params['id'] );
} elseif (!$is_root_cat && $params['mode'] == 'category') {
$result = Ecwid_Category::get_by_id( $params['id'] );
}
if (!$is_root_cat && ( empty( $result ) || is_object ( $result ) && ( !isset( $result->id ) || !$result->enabled ) ) ) {
status_header( 404 );
global $wp_query;
$wp_query->set_404();
}
}
}
function ecwid_503_on_store_closed() {
if ( !isset( $_GET['_escaped_fragment_'] ) ) {
return;
}
if ( ecwid_is_store_closed() ) {
header( 'HTTP/1.1 503 Service Temporarily Unavailable' );
header( 'Status: 503 Service Temporarily Unavailable' );
}
}
function ecwid_is_store_closed()
{
if ( Ecwid_Api_V3::is_available() ) {
$api = new Ecwid_Api_V3();
$profile = $api->get_store_profile();
if ( !$profile || !isset( $profile->settings ) ) {
return false;
}
return @$profile->settings->closed;
}
return false;
}
function ecwid_backward_compatibility() {
// Backward compatibility with 1.1.2 and earlier
if (isset($_GET['ecwid_product_id']) || isset($_GET['ecwid_category_id'])) {
if (isset($_GET['ecwid_product_id']))
$redirect = ecwid_get_product_url(intval($_GET['ecwid_product_id']));
elseif (isset($_GET['ecwid_category_id']))
$redirect = ecwid_get_category_url(intval($_GET['ecwid_category_id']));
wp_safe_redirect($redirect, 301);
exit();
}
}
function ecwid_build_sitemap( $callback, $page_num = 1 ) {
if ( ! Ecwid_Api_V3::is_available() || ! ecwid_is_store_page_available() ) {
return;
}
$page_id = Ecwid_Store_Page::get_current_store_page_id();
if ( get_post_status( $page_id ) === 'publish' ) {
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-sitemap-builder.php';
$sitemap = new EcwidSitemapBuilder( Ecwid_Store_Page::get_store_url(), $callback );
$sitemap->generate( (int) $page_num );
}
}
function ecwid_minifier_compatibility()
{
if ( !function_exists( 'get_plugins' ) ) { require_once ( ABSPATH . 'wp-admin/includes/plugin.php' ); }
$plugins = get_plugins();
$wp_minify_plugin = 'wp-minify/wp-minify.php';
if (array_key_exists($wp_minify_plugin, $plugins) && is_plugin_active($wp_minify_plugin)) {
global $wp_minify;
if (is_object($wp_minify) && array_key_exists('default_exclude', get_object_vars($wp_minify)) && is_array($wp_minify->default_exclude)) {
$wp_minify->default_exclude[] = Ecwid_Config::get_scriptjs_domain() . '/script.js';
}
}
}
function ecwid_check_version() {
$plugin_data = get_plugin_data( __FILE__ );
$current_version = $plugin_data['Version'];
$stored_version = get_option( 'ecwid_plugin_version', null );
$migration_since_version = get_option( 'ecwid_plugin_migration_since_version', null );
if ( is_null( $migration_since_version ) ) {
update_option( 'ecwid_plugin_migration_since_version', $current_version );
}
$fresh_install = ! $stored_version;
$upgrade = $stored_version && version_compare( $current_version, $stored_version ) > 0;
if ( $fresh_install ) {
do_action( 'ecwid_plugin_installed', $current_version );
add_option( 'ecwid_plugin_version', $current_version );
// Called in Ecwid_Seo_Links->on_fresh_install
do_action( 'ecwid_on_fresh_install' );
} elseif ( $upgrade ) {
do_action( 'ecwid_plugin_upgraded', array( 'old' => $stored_version, 'new' => $current_version ) );
update_option( 'ecwid_plugin_version', $current_version );
do_action( 'ecwid_on_plugin_upgrade' );
}//end if
if ( $fresh_install || $upgrade || isset( $_GET['ecwid_reinit'] ) ) {
add_option( Ecwid_Seo_Links::OPTION_ENABLED, false );
if ( ecwid_migrations_is_original_plugin_version_older_than( '4.3' ) ) {
add_option( 'ecwid_fetch_url_use_file_get_contents', '' );
add_option( 'ecwid_remote_get_timeout', '5' );
}
add_option( 'ecwid_support_email', '[email protected]' );
add_option( 'ecwid_enable_sso' );
add_option( Ecwid_Products::OPTION_ENABLED, Ecwid_Products::is_enabled() );
add_option( 'ecwid_disable_pb_url', false );
add_option( 'ecwid_historyjs_html4mode', false );
add_option( Ecwid_Widget_Floating_Shopping_Cart::OPTION_DISPLAY_POSITION, '' );
// Since 5.4
delete_option( 'ecwid_use_new_search' );
delete_option( 'ecwid_use_new_categories' );
// /Since 5.4
// Since 5.4.2
delete_option( 'ecwid_hide_appearance_menu' );
// Since 5.4.3
add_option( Ecwid_Widget_Floating_Shopping_Cart::OPTION_MOVE_INTO_BODY, '' );
// Since 5.7.3
delete_option( 'ecwid_use_js_api_to_open_store_pages' );
// Since 5.7.4
update_option( 'ecwid_use_js_api_to_open_store_categories_pages', Ecwid_Nav_Menus::OPTVAL_USE_JS_API_FOR_CATS_MENU_AUTO );
// Since 5.8
add_option( Ecwid_Admin::OPTION_ENABLE_AUTO_MENUS, 'auto' );
// Since 5.8
add_option( 'ecwid_print_html_catalog', 'Y' );
// Since 5.8.1+
add_option( Ecwid_Products::OPTION_SYNC_LIMIT, 20 );
// Since 6.0.x
add_option( 'ecwid_hide_prefetch', 'off' );
// Since 6.1.x
if ( class_exists( 'Ecwid_Floating_Minicart' ) ) {
Ecwid_Floating_Minicart::create_default_options();
}
add_option( 'ecwid_hide_old_minicart', ecwid_is_recent_installation() );
Ecwid_Config::load_from_ini();
// Since 6.2.x
delete_option( 'force_scriptjs_render' );
// Since 6.4.x
add_option( EcwidPlatform::OPTION_LOG_CACHE );
// Since 6.4.8
add_option( 'ecwid_hide_canonical', false );
// Since 6.4.9
add_option( Ecwid_Theme_Base::OPTION_LEGACY_CUSTOM_SCROLLER, false );
// Since 6.4.9+
add_option( 'ecwid_remove_emoji', 'Y' );
// Since 6.4.14+
add_option( Ecwid_Store_Page::OPTION_REPLACE_TITLE, $fresh_install ? 'Y' : '' );
do_action( 'ecwid_on_plugin_update' );
Ecwid_Store_Page::add_store_page( get_option( 'ecwid_store_page_id' ) );
Ecwid_Store_Page::add_store_page( get_option( 'ecwid_store_page_id_auto' ) );
if ( Ecwid_Store_Page::get_current_store_page_id() ) {
delete_option( 'ecwid_store_page_id_auto' );
}
Ecwid_Api_V3::reset_api_status();
flush_rewrite_rules();
}//end if
add_option( 'ecwid_disable_dashboard', '' );
}
function ecwid_get_woocommerce_status() {
$woo = EcwidPlatform::cache_get('woo_status', null);
if (is_null($woo)) {
$woo = 0;
$all_plugins = get_plugins();
if (array_key_exists('woocommerce/woocommerce.php', $all_plugins)) {
$active_plugins = get_option('active_plugins');
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', $active_plugins))) {
$woo = 2;
} else {
$woo = 1;
}
}
EcwidPlatform::cache_set('woo_status', $woo, 60 * 60 * 24);
}
return $woo;
}
function ecwid_is_recent_installation() {
return get_option( 'ecwid_plugin_migration_since_version' ) == get_option('ecwid_plugin_version' );
}
function ecwid_migrations_is_original_plugin_version_older_than( $version ) {
$migration_since_version = get_option( 'ecwid_plugin_migration_since_version', false );
return version_compare( $migration_since_version, $version ) < 0;
}
function ecwid_log_error( $message ) {
$errors = get_option( 'ecwid_error_log' );
if ( ! $errors ) {
$errors = array();
} else {
$errors = json_decode( $errors );
if ( ! is_array( $errors ) ) {
$errors = array();
}
}
while ( count( $errors ) > 10 ) {
array_shift( $errors );
}
$errors[] = array(
'message' => $message,
'date' => date_i18n( 'D F j H:i:s Y' ),
);
update_option( 'ecwid_error_log', json_encode( $errors ) );
}
function ecwid_override_option( $name, $new_value = null ) {
static $overridden = array();
if ( ! array_key_exists( $name, $overridden ) ) {
$overridden[ $name ] = get_option( $name );
}
if ( ! is_null( $new_value ) ) {
update_option( $name, $new_value );
} else {
update_option( $name, $overridden[ $name ] );
}
}
function ecwid_tinymce_init( $in ) {
if ( ! empty( $in['extended_valid_elements'] ) ) {
$in['extended_valid_elements'] .= ',';
} else {
$in['extended_valid_elements'] = '';
}
$in['extended_valid_elements'] .= '@[id|class|style|title|itemscope|itemtype|itemprop|customprop|datetime|rel],div,dl,ul,dt,dd,li,span,a|rev|charset|href|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur]';
return $in;
}
function ecwid_seo_ultimate_compatibility() {
global $seo_ultimate;
if ( ! $seo_ultimate ) {
return;
}
if ( ! Ecwid_Store_Page::is_store_page() ) {
return;
}
if ( isset( $_GET['_escaped_fragment_'] ) || ( Ecwid_Seo_Links::is_enabled() && Ecwid_Seo_Links::is_product_browser_url() ) ) {
remove_action( 'template_redirect', array( $seo_ultimate->modules['titles'], 'before_header' ), 0 );
remove_action( 'wp_head', array( $seo_ultimate->modules['titles'], 'after_header' ), 1000 );
remove_action( 'su_head', array( $seo_ultimate->modules['meta-descriptions'], 'head_tag_output' ) );
remove_action( 'su_head', array( $seo_ultimate->modules['canonical'], 'link_rel_canonical_tag' ) );
remove_action( 'su_head', array( $seo_ultimate->modules['canonical'], 'http_link_rel_canonical' ) );
}
}
function ecwid_remove_default_canonical() {
if ( Ecwid_Store_Page::is_store_page() ) {
remove_action( 'wp_head', 'rel_canonical' );
}
}
function ecwid_seo_compatibility_init( $title ) {
if ( ! array_key_exists( '_escaped_fragment_', $_GET ) || ! Ecwid_Store_Page::is_store_page() ) {
return $title;
}
// Platinum SEO Pack
// Canonical
ecwid_override_option( 'psp_canonical', false );
// Title
ecwid_override_option( 'aiosp_rewrite_titles', false );
add_action( 'amt_basic_metadata_head', 'ecwid_amt_remove_description' );
return $title;
}
function ecwid_amt_remove_description( $params ) {
foreach ( $params as $key => $value ) {
if ( preg_match( '/meta name="description"/', $value ) ) {
unset( $params[ $key ] );
}
}
return $params;
}
function ecwid_seo_compatibility_restore() {
if ( ! array_key_exists( '_escaped_fragment_', $_GET ) || ! Ecwid_Store_Page::is_store_page() ) {
return;
}
ecwid_override_option( 'psp_canonical' );
ecwid_override_option( 'aiosp_rewrite_titles' );
}
function ecwid_check_api_cache() {
EcwidPlatform::cache_log_record( 'init', array() );
$last_cache = get_option( 'ecwid_last_api_cache_check' );
if ( time() - $last_cache > HOUR_IN_SECONDS ) {
ecwid_invalidate_cache();
}
}
function ecwid_enqueue_cache_control() {
wp_enqueue_script( 'ecwid-defer-actions', ECWID_PLUGIN_URL . 'js/defer-actions.js', array(), get_option( 'ecwid_plugin_version' ), true );
wp_localize_script(
'ecwid-defer-actions',
'ecwidCacheControlParams',
array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
);
}
function ecwid_admin_check_api_cache() {
$is_ajax_check_api_cache = isset( $_GET['action'] ) && $_GET['action'] == 'ec_check_api_cache';
$is_doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
$is_get_request = isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET';
if ( ! $is_ajax_check_api_cache && ( $is_doing_ajax || $is_get_request ) ) return; //phpcs:ignore Generic.ControlStructures.InlineControlStructure.NotAllowed
EcwidPlatform::cache_log_record( 'admin_init', array() );
$last_cache = get_option( 'ecwid_last_api_cache_check' );
if ( Ecwid_Api_V3::get_api_status() == Ecwid_Api_V3::API_STATUS_OK ) {
$check_time_period = 5 * MINUTE_IN_SECONDS;
} else {
$check_time_period = MINUTE_IN_SECONDS;
}
if ( time() - $last_cache > $check_time_period ) {
Ecwid_Api_V3::reset_api_status();
}
ecwid_regular_cache_check();
}
function ecwid_invalidate_cache( $full_reset = false ) {
if ( $full_reset ) {
ecwid_full_cache_reset();
return;
}
ecwid_regular_cache_check();
}
function ecwid_regular_cache_check() {
static $already_checked = false;
if ( Ecwid_Api_V3::is_available() && ! $already_checked ) {
$already_checked = true;
$api = new Ecwid_Api_V3();
$stats = $api->get_store_update_stats();
EcwidPlatform::cache_log_record( 'reg cache check', array( 'stats' => $stats ) );
if ( $stats ) {
//phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
EcwidPlatform::invalidate_products_cache_from( strtotime( $stats->productsUpdated ) );
EcwidPlatform::invalidate_categories_cache_from( strtotime( $stats->categoriesUpdated ) );
EcwidPlatform::invalidate_profile_cache_from( strtotime( $stats->profileUpdated ) );
//phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
update_option( 'ecwid_last_api_cache_check', time() );
}
$last_transients = get_option( 'ecwid_last_transients_check' );
if ( time() - $last_transients > WEEK_IN_SECONDS * 2 ) {
EcwidPlatform::clear_all_transients();
update_option( 'ecwid_last_transients_check', time() );
}
if ( EcwidPlatform::is_need_clear_transients() ) {
EcwidPlatform::clear_all_transients();
}
}//end if