forked from jigoshop/jigoshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jigoshop.php
executable file
·1825 lines (1605 loc) · 57.2 KB
/
jigoshop.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: Jigoshop
* Plugin URI: https://www.jigoshop.com
* Description: Jigoshop, a WordPress eCommerce plugin that works.
* Author: Jigoshop Limited
* Author URI: https://www.jigoshop.com
* Version: 1.18.3
* Requires at least: 4.0
* Tested up to: 4.7.1
* Text Domain: jigoshop
* Domain Path: /languages/
* DISCLAIMER
* Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
* versions in the future. If you wish to customise Jigoshop core for your needs,
* please use our GitHub repository to publish essential changes for consideration.
*
* @package Jigoshop
* @category Core
* @author Jigoshop
* @copyright Copyright © 2011-2015 Jigoshop.
* @license GNU General Public License v3
*/
if ( !defined('ABSPATH') ){
die("Not to be accessed directly");
}
if (!defined('JIGOSHOP_VERSION')) {
define('JIGOSHOP_VERSION', '1.18.3');
}
if (!defined('JIGOSHOP_DB_VERSION')) {
define('JIGOSHOP_DB_VERSION', 1503180);
}
if (!defined('JIGOSHOP_OPTIONS')) {
define('JIGOSHOP_OPTIONS', 'jigoshop_options');
}
if (!defined('JIGOSHOP_TEMPLATE_URL')) {
define('JIGOSHOP_TEMPLATE_URL', 'jigoshop/');
}
if (!defined('JIGOSHOP_DIR')) {
define('JIGOSHOP_DIR', dirname(__FILE__));
}
if (!defined('JIGOSHOP_URL')) {
define('JIGOSHOP_URL', plugins_url('', __FILE__));
}
if (!defined('JIGOSHOP_LOG_DIR')) {
$upload_dir = wp_upload_dir();
define('JIGOSHOP_LOG_DIR', $upload_dir['basedir'].'/jigoshop-logs/');
}
define('JIGOSHOP_REQUIRED_MEMORY', 64);
define('JIGOSHOP_REQUIRED_WP_MEMORY', 64);
define('JIGOSHOP_PHP_VERSION', '5.4');
define('JIGOSHOP_WORDPRESS_VERSION', '3.8');
if(!version_compare(PHP_VERSION, JIGOSHOP_PHP_VERSION, '>=')){
function jigoshop_required_version(){
echo '<div class="error"><p>'.
sprintf(__('<strong>Error!</strong> Jigoshop requires at least PHP %s! Your version is: %s. Please upgrade.', 'jigoshop'), JIGOSHOP_PHP_VERSION, PHP_VERSION).
'</p></div>';
}
add_action('admin_notices', 'jigoshop_required_version');
return;
}
include ABSPATH.WPINC.'/version.php';
/** @noinspection PhpUndefinedVariableInspection */
if(!version_compare($wp_version, JIGOSHOP_WORDPRESS_VERSION, '>=')){
function jigoshop_required_wordpress_version()
{
include ABSPATH.WPINC.'/version.php';
/** @noinspection PhpUndefinedVariableInspection */
echo '<div class="error"><p>'.
sprintf(__('<strong>Error!</strong> Jigoshop requires at least WordPress %s! Your version is: %s. Please upgrade.', 'jigoshop'), JIGOSHOP_WORDPRESS_VERSION, $wp_version).
'</p></div>';
}
add_action('admin_notices', 'jigoshop_required_wordpress_version');
return;
}
$ini_memory_limit = trim(ini_get('memory_limit'));
preg_match('/^(\d+)(\w*)?$/', $ini_memory_limit, $memory);
$memory_limit = $memory[1];
if (isset($memory[2])) {
switch ($memory[2]) {
case 'M':
case 'm':
$memory_limit *= 1024;
case 'K':
case 'k':
$memory_limit *= 1024;
}
}
if($memory_limit < JIGOSHOP_REQUIRED_MEMORY*1024*1024){
function jigoshop_required_memory_warning()
{
$ini_memory_limit = ini_get('memory_limit');
echo '<div class="error"><p>'.
sprintf(__('<strong>Warning!</strong> Jigoshop requires at least %sM of memory! Your system currently has: %s.', 'jigoshop'), JIGOSHOP_REQUIRED_MEMORY, $ini_memory_limit).
'</p></div>';
}
add_action('admin_notices', 'jigoshop_required_memory_warning');
}
preg_match('/^(\d+)(\w*)?$/', trim(WP_MEMORY_LIMIT), $memory);
$memory_limit = $memory[1];
if (isset($memory[2])) {
switch ($memory[2]) {
case 'M':
case 'm':
$memory_limit *= 1024;
case 'K':
case 'k':
$memory_limit *= 1024;
}
}
if($memory_limit < JIGOSHOP_REQUIRED_WP_MEMORY*1024*1024){
function jigoshop_required_wp_memory_warning()
{
echo '<div class="error"><p>'.
sprintf(__('<strong>Warning!</strong> Jigoshop requires at least %sM of memory for WordPress! Your system currently has: %s. <a href="%s" target="_blank">How to change?</a>', 'jigoshop'),
JIGOSHOP_REQUIRED_MEMORY, WP_MEMORY_LIMIT, 'http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP').
'</p></div>';
}
add_action('admin_notices', 'jigoshop_required_wp_memory_warning');
}
if(get_option('migration_terms_accept', false) == false) {
add_action('admin_notices', function(){
$user = wp_get_current_user();
echo '<div class="notice notice-info"><p>'.
sprintf(
__('Hi <b>%s</b>! Jigoshop 1.x will no longer be supported from the end of March 2017. We strongly recommend upgrading to Jigoshop eCommerce which is a completely brand new product. You can check your plugins\' compatibility with Jigoshop eCommerce <a href="%s">here</a>. The migration guide can be found <a href="%s">here</a>.<br /><b>Please note, that we strongly recommend to create a full-site backup before migrating.</b>', 'jigoshop'),
$user->display_name,
admin_url( 'admin.php?page=jigoshop_migration_information'),
'https://www.jigoshop.com/migration-guide/'
).
'</p></div>';
});
}
/**
* Include core files and classes
*/
include_once('classes/abstract/jigoshop_base.class.php');
include_once('classes/abstract/jigoshop_singleton.class.php');
include_once('classes/jigoshop_options.class.php');
include_once('classes/jigoshop_session.class.php');
include_once('classes/jigoshop_sanitize.class.php');
include_once('classes/jigoshop_validation.class.php');
include_once('classes/jigoshop_forms.class.php');
include_once('jigoshop_taxonomy.php');
include_once('classes/jigoshop_countries.class.php');
include_once('classes/jigoshop_customer.class.php');
include_once('classes/jigoshop_product.class.php');
include_once('classes/jigoshop_product_variation.class.php');
include_once('classes/jigoshop_order.class.php');
include_once('classes/jigoshop_orders.class.php');
include_once('classes/jigoshop_tax.class.php');
include_once('classes/jigoshop_shipping.class.php');
include_once('classes/jigoshop_coupons.class.php');
include_once('classes/jigoshop_licence_validator.class.php');
include_once('classes/jigoshop_emails.class.php');
include_once('gateways/gateways.class.php');
include_once('gateways/gateway.class.php');
include_once('gateways/bank_transfer.php');
include_once('gateways/cheque.php');
include_once('gateways/cod.php');
include_once('gateways/paypal.php');
include_once('gateways/futurepay.php');
include_once('gateways/worldpay.php');
include_once('gateways/no_payment.php');
include_once('shipping/shipping_method.class.php');
include_once('shipping/jigoshop_calculable_shipping.php');
include_once('shipping/flat_rate.php');
include_once('shipping/free_shipping.php');
include_once('shipping/local_pickup.php');
include_once('classes/jigoshop_query.class.php');
include_once('classes/jigoshop_request_api.class.php');
include_once('classes/jigoshop.class.php');
include_once('classes/jigoshop_cart.class.php');
include_once('classes/jigoshop_checkout.class.php');
include_once('classes/jigoshop_cron.class.php');
include_once('shortcodes/init.php');
include_once('widgets/init.php');
include_once('jigoshop_functions.php');
include_once('jigoshop_templates.php');
include_once('jigoshop_template_actions.php');
include_once('jigoshop_emails.php');
include_once('jigoshop_actions.php');
// Plugins
include_once('plugins/jigoshop-cart-favicon-count/jigoshop-cart-favicon-count.php');
/**
* IIS compat fix/fallback
**/
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
if (isset($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
}
}
// Load administration & check if we need to install
if (is_admin()) {
include_once('admin/jigoshop-admin.php');
register_activation_hook(__FILE__, 'install_jigoshop');
}
function jigoshop_admin_footer($text) {
$screen = get_current_screen();
if (strpos($screen->base, 'jigoshop') === false && strpos($screen->parent_base, 'jigoshop') === false && !in_array($screen->post_type, array('product', 'shop_order'))) {
return $text;
}
return sprintf(
'<a target="_blank" href="https://www.jigoshop.com/support/">%s</a> | %s',
__('Contact support', 'jigoshop'),
str_replace(
array('[stars]','[link]','[/link]'),
array(
'<a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/jigoshop#postform" >★★★★★</a>',
'<a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/jigoshop#postform" >',
'</a>'
),
__('Add your [stars] on [link]wordpress.org[/link] and keep this plugin essentially free.', 'jigoshop')
)
);
}
add_filter('admin_footer_text', 'jigoshop_admin_footer');
/**
* Adds Jigoshop items to admin bar.
*/
function jigoshop_admin_toolbar() {
/** @var WP_Admin_Bar $wp_admin_bar */
global $wp_admin_bar;
$manage_products = current_user_can('manage_jigoshop_products');
$manage_orders = current_user_can('manage_jigoshop_orders');
$manage_jigoshop = current_user_can('manage_jigoshop');
$view_reports = current_user_can('view_jigoshop_reports');
$manege_emails = current_user_can('manage_jigoshop_emails');
if (!is_admin() && ($manage_jigoshop || $manage_products || $manage_orders || $view_reports)) {
$wp_admin_bar->add_node(array(
'id' => 'jigoshop',
'title' => __('Jigoshop', 'jigoshop'),
'href' => $manage_jigoshop ? admin_url('admin.php?page=jigoshop') : '',
'parent' => false,
'meta' => array(
'class' => 'jigoshop-toolbar'
),
));
if ($manage_jigoshop) {
$wp_admin_bar->add_node(array(
'id' => 'jigoshop_dashboard',
'title' => __('Dashboard', 'jigoshop'),
'parent' => 'jigoshop',
'href' => admin_url('admin.php?page=jigoshop'),
));
}
if ($manage_products) {
$wp_admin_bar->add_node(array(
'id' => 'jigoshop_products',
'title' => __('Products', 'jigoshop'),
'parent' => 'jigoshop',
'href' => admin_url('edit.php?post_type=product'),
));
}
if ($manage_orders) {
$wp_admin_bar->add_node(array(
'id' => 'jigoshop_orders',
'title' => __('Orders', 'jigoshop'),
'parent' => 'jigoshop',
'href' => admin_url('edit.php?post_type=shop_order'),
));
}
if ($manage_jigoshop) {
$wp_admin_bar->add_node(array(
'id' => 'jigoshop_settings',
'title' => __('Settings', 'jigoshop'),
'parent' => 'jigoshop',
'href' => admin_url('admin.php?page=jigoshop_settings'),
));
}
if($manege_emails) {
$wp_admin_bar->add_node(array(
'id' => 'jigoshop_emils',
'title' => __('Emails', 'jigoshop'),
'parent' => 'jigoshop',
'href' => admin_url('edit.php?post_type=shop_email'),
));
}
}
}
add_action('admin_bar_menu', 'jigoshop_admin_toolbar', 35);
function jigoshop_admin_bar_links($links)
{
return array_merge(array(
'<a href="'.admin_url('admin.php?page=jigoshop_settings').'">'.__('Settings', 'jigoshop').'</a>',
'<a href="https://www.jigoshop.com/migration-guide/">'.__('Upgrade to Jigoshop eCommerce', 'jigoshop').'</a>',
), $links);
}
function jigoshop_admin_bar_edit($location, $term_id, $taxonomy)
{
if (in_array($taxonomy, array('product_cat', 'product_tag')) && strpos($location, 'post_type=product') === false) {
$location .= '&post_type=product';
}
return $location;
}
add_filter('get_edit_term_link', 'jigoshop_admin_bar_edit', 10, 3);
/**
* Jigoshop Init
*/
add_action('init', 'jigoshop_init', 0);
function jigoshop_init()
{
// Override default translations with custom .mo's found in wp-content/languages/jigoshop first.
load_textdomain('jigoshop', WP_LANG_DIR.'/jigoshop/jigoshop-'.get_locale().'.mo');
load_plugin_textdomain('jigoshop', false, dirname(plugin_basename(__FILE__)).'/languages/');
add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'jigoshop_admin_bar_links');
do_action('before_jigoshop_init');
// instantiate options -after- loading text domains
$options = Jigoshop_Base::get_options();
jigoshop_post_type(); // register taxonomies
new jigoshop_cron(); // -after- text domains and Options instantiation allows settings translations
jigoshop_set_image_sizes(); // called -after- our Options are loaded
// add Singletons here so that the taxonomies are loaded before calling them.
jigoshop_session::instance(); // Start sessions if they aren't already
jigoshop::instance(); // Utility functions, uses sessions
jigoshop_customer::instance(); // Customer class, sorts session data such as location
// Jigoshop will instantiate gateways and shipping methods on this same 'init' action hook
// with a very low priority to ensure text domains are loaded first prior to installing any external options
jigoshop_shipping::instance(); // Shipping class. loads shipping methods
jigoshop_payment_gateways::instance(); // Payment gateways class. loads payment methods
jigoshop_cart::instance(); // Cart class, uses sessions
add_filter( 'mce_external_plugins', 'jigoshop_register_shortcode_editor' );
add_filter( 'mce_buttons', 'jigoshop_register_shortcode_buttons' );
if (!is_admin()) {
/* Catalog Filters */
add_filter('loop-shop-query', create_function('', 'return array("orderby" => "'.$options->get('jigoshop_catalog_sort_orderby').'","order" => "'.$options->get('jigoshop_catalog_sort_direction').'");'));
add_filter('loop_shop_columns', create_function('', 'return '.$options->get('jigoshop_catalog_columns').';'));
add_filter('loop_shop_per_page', create_function('', 'return '.$options->get('jigoshop_catalog_per_page').';'));
jigoshop_catalog_query::instance(); // front end queries class
jigoshop_request_api::instance(); // front end request api for URL's
}
jigoshop_roles_init();
do_action('jigoshop_initialize_plugins');
}
/**
* Include template functions here with a low priority so they are pluggable by themes
*/
add_action('init', 'jigoshop_load_template_functions', 999);
function jigoshop_load_template_functions()
{
include_once('jigoshop_template_functions.php');
}
function jigoshop_get_core_capabilities()
{
$capabilities = array();
$capabilities['core'] = array(
'manage_jigoshop',
'view_jigoshop_reports',
'manage_jigoshop_orders',
'manage_jigoshop_coupons',
'manage_jigoshop_products',
'manage_jigoshop_emails'
);
$capability_types = array('product', 'shop_order', 'shop_coupon', 'shop_email');
foreach ($capability_types as $capability_type) {
$capabilities[$capability_type] = array(
// Post type
"edit_{$capability_type}",
"read_{$capability_type}",
"delete_{$capability_type}",
"edit_{$capability_type}s",
"edit_others_{$capability_type}s",
"publish_{$capability_type}s",
"read_private_{$capability_type}s",
"delete_{$capability_type}s",
"delete_private_{$capability_type}s",
"delete_published_{$capability_type}s",
"delete_others_{$capability_type}s",
"edit_private_{$capability_type}s",
"edit_published_{$capability_type}s",
// Terms
"manage_{$capability_type}_terms",
"edit_{$capability_type}_terms",
"delete_{$capability_type}_terms",
"assign_{$capability_type}_terms"
);
}
return $capabilities;
}
function jigoshop_roles_init()
{
global $wp_roles;
if (class_exists('WP_Roles')) {
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
}
if (is_object($wp_roles)) {
// Customer role
add_role('customer', __('Customer', 'jigoshop'), array(
'read' => true,
'edit_posts' => false,
'delete_posts' => false
));
// Shop manager role
add_role('shop_manager', __('Shop Manager', 'jigoshop'), array(
'read' => true,
'read_private_pages' => true,
'read_private_posts' => true,
'edit_users' => true,
'edit_posts' => true,
'edit_pages' => true,
'edit_published_posts' => true,
'edit_published_pages' => true,
'edit_private_pages' => true,
'edit_private_posts' => true,
'edit_others_posts' => true,
'edit_others_pages' => true,
'publish_posts' => true,
'publish_pages' => true,
'delete_posts' => true,
'delete_pages' => true,
'delete_private_pages' => true,
'delete_private_posts' => true,
'delete_published_pages' => true,
'delete_published_posts' => true,
'delete_others_posts' => true,
'delete_others_pages' => true,
'manage_categories' => true,
'manage_links' => true,
'moderate_comments' => true,
'unfiltered_html' => true,
'upload_files' => true,
'export' => true,
'import' => true,
));
$capabilities = jigoshop_get_core_capabilities();
foreach ($capabilities as $cap_group) {
foreach ($cap_group as $cap) {
$wp_roles->add_cap('administrator', $cap);
$wp_roles->add_cap('shop_manager', $cap);
}
}
}
}
function jigoshop_prepare_dashboard_title($title)
{
$result = '<span>'.preg_replace('/ /', '</span> ', $title, 1);
if (strpos($result, '</span>') === false) {
$result .= '</span>';
}
return $result;
}
/**
* Enqueues script.
* Calls filter `jrto_enqueue_script`. If the filter returns empty value the script is omitted.
* Available options:
* * version - Wordpress script version number
* * in_footer - is this script required to add to the footer?
* * page - list of pages to use the script
* Options could be extended by plugins.
*
* @param string $handle Handle name.
* @param bool $src Source file.
* @param array $dependencies List of dependencies to the script.
* @param array $options List of options.
*/
function jigoshop_add_script($handle, $src, array $dependencies = array(), array $options = array())
{
$page = isset($options['page']) ? (array)$options['page'] : array('all');
if (is_jigoshop_page($page)) {
$version = isset($options['version']) ? $options['version'] : false;
$footer = isset($options['in_footer']) ? $options['in_footer'] : false;
wp_enqueue_script($handle, $src, $dependencies, $version, $footer);
}
}
/**
* Removes script from enqueued list.
* Calls filter `jigoshop_remove_script`. If the filter returns empty value the script is omitted.
* Available options:
* * page - list of pages to use the script
* Options could be extended by plugins.
*
* @param string $handle Handle name.
* @param array $options List of options.
*/
function jigoshop_remove_script($handle, array $options = array())
{
$page = isset($options['page']) ? (array)$options['page'] : array('all');
if (is_jigoshop_page($page)) {
wp_deregister_script($handle);
}
}
/**
* Localizes script.
* Calls filter `jigoshop_localize_script`. If the filter returns empty value the script is omitted.
*
* @param string $handle Handle name.
* @param string $object Object name.
* @param array $values List of values to localize.
*/
function jigoshop_localize_script($handle, $object, array $values)
{
wp_localize_script($handle, $object, $values);
}
/**
* Enqueues stylesheet.
* Calls filter `jigoshop_add_style`. If the filter returns empty value the style is omitted.
* Available options:
* * version - Wordpress script version number
* * media - CSS media this script represents
* * page - list of pages to use the style
* Options could be extended by plugins.
*
* @param string $handle Handle name.
* @param bool $src Source file.
* @param array $dependencies List of dependencies to the stylesheet.
* @param array $options List of options.
*/
function jigoshop_add_style($handle, $src, array $dependencies = array(), array $options = array())
{
$page = isset($options['page']) ? (array)$options['page'] : array('all');
if (is_jigoshop_page($page)) {
$version = isset($options['version']) ? $options['version'] : false;
$media = isset($options['media']) ? $options['media'] : 'all';
wp_enqueue_style($handle, $src, $dependencies, $version, $media);
}
}
/**S
* Removes style from enqueued list.
* Calls filter `jigoshop_remove_style`. If the filter returns empty value the style is omitted.
* Available options:
* * page - list of pages to use the style
* Options could be extended by plugins.
*
* @param string $handle Handle name.
* @param array $options List of options.
*/
function jigoshop_remove_style($handle, array $options = array())
{
$page = isset($options['page']) ? (array)$options['page'] : array('all');
if (is_jigoshop_page($page)) {
wp_deregister_style($handle);
}
}
/**
* Checks if current page is one of given page types.
*
* @param string|array $pages List of page types to check.
* @return bool Is current page one of provided?
*/
function is_jigoshop_page($pages)
{
$result = false;
$pages = is_array($pages) ? $pages : array($pages);
foreach ($pages as $page) {
$result = $result || is_jigoshop_single_page($page);
}
return $result;
}
// Define all Jigoshop page constants
define('JIGOSHOP_CART', 'cart');
define('JIGOSHOP_CHECKOUT', 'checkout');
define('JIGOSHOP_PAY', 'pay');
define('JIGOSHOP_THANK_YOU', 'thanks');
define('JIGOSHOP_MY_ACCOUNT', 'myaccount');
define('JIGOSHOP_EDIT_ADDRESS', 'edit_address');
define('JIGOSHOP_VIEW_ORDER', 'view_order');
define('JIGOSHOP_CHANGE_PASSWORD', 'change_password');
define('JIGOSHOP_PRODUCT', 'product');
define('JIGOSHOP_PRODUCT_CATEGORY', 'product_category');
define('JIGOSHOP_PRODUCT_LIST', 'product_list');
define('JIGOSHOP_PRODUCT_TAG', 'product_tag');
define('JIGOSHOP_ALL', 'all');
/**
* Returns list of pages supported by is_jigoshop_single_page() and is_jigoshop_page().
*
* @return array List of supported pages.
*/
function jigoshop_get_available_pages()
{
return array(
JIGOSHOP_CART,
JIGOSHOP_PAY,
JIGOSHOP_CHECKOUT,
JIGOSHOP_THANK_YOU,
JIGOSHOP_EDIT_ADDRESS,
JIGOSHOP_MY_ACCOUNT,
JIGOSHOP_VIEW_ORDER,
JIGOSHOP_CHANGE_PASSWORD,
JIGOSHOP_PRODUCT,
JIGOSHOP_PRODUCT_CATEGORY,
JIGOSHOP_PRODUCT_TAG,
JIGOSHOP_PRODUCT_LIST,
JIGOSHOP_ALL,
);
}
/**
* Checks if current page is of given page type.
*
* @param string $page Page type.
* @return bool Is current page the one from name?
*/
function is_jigoshop_single_page($page)
{
switch ($page) {
case JIGOSHOP_CART:
return is_cart();
case JIGOSHOP_CHECKOUT:
return is_checkout();
case JIGOSHOP_PAY:
return is_page(jigoshop_get_page_id(JIGOSHOP_PAY));
case JIGOSHOP_THANK_YOU:
return is_page(jigoshop_get_page_id(JIGOSHOP_THANK_YOU));
case JIGOSHOP_MY_ACCOUNT:
return is_page(jigoshop_get_page_id(JIGOSHOP_MY_ACCOUNT));
case JIGOSHOP_EDIT_ADDRESS:
return is_page(jigoshop_get_page_id(JIGOSHOP_EDIT_ADDRESS));
case JIGOSHOP_VIEW_ORDER:
return is_page(jigoshop_get_page_id(JIGOSHOP_VIEW_ORDER));
case JIGOSHOP_CHANGE_PASSWORD:
return is_page(jigoshop_get_page_id(JIGOSHOP_CHANGE_PASSWORD));
case JIGOSHOP_PRODUCT:
return is_product();
case JIGOSHOP_PRODUCT_CATEGORY:
return is_product_category();
case JIGOSHOP_PRODUCT_LIST:
return is_product_list();
case JIGOSHOP_PRODUCT_TAG:
return is_product_tag();
case JIGOSHOP_ALL:
return true;
default:
return jigoshop_is_admin_page() == $page;
}
}
/**
* Jigoshop Frontend Styles and Scripts
*/
add_action('init', 'jigoshop_frontend_scripts', 1);
function jigoshop_frontend_scripts()
{
$options = Jigoshop_Base::get_options();
$frontend_css = JIGOSHOP_URL.'/assets/css/frontend.css';
$theme_css = file_exists(get_stylesheet_directory().'/jigoshop/style.css')
? get_stylesheet_directory_uri().'/jigoshop/style.css'
: $frontend_css;
if ($options->get('jigoshop_disable_css') == 'no') {
if ($options->get('jigoshop_frontend_with_theme_css') == 'yes' && $frontend_css != $theme_css) {
jrto_enqueue_style('frontend', 'jigoshop_theme_styles', $frontend_css);
}
jrto_enqueue_style('frontend', 'jigoshop_styles', $theme_css);
}
wp_enqueue_script('jquery');
wp_register_script('jquery-blockui', '//cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.66.0-2013.10.09/jquery.blockUI.min.js', array('jquery'), '2.66.0');
wp_enqueue_script('jquery-blockui');
jrto_enqueue_script('frontend', 'jigoshop_global', JIGOSHOP_URL.'/assets/js/global.js', array('jquery'), array('in_footer' => true));
if ($options->get('jigoshop_disable_fancybox') == 'no') {
jrto_enqueue_script('frontend', 'prettyPhoto', JIGOSHOP_URL.'/assets/js/jquery.prettyPhoto.js', array('jquery'), array('in_footer' => true));
jrto_enqueue_style('frontend', 'prettyPhoto', JIGOSHOP_URL.'/assets/css/prettyPhoto.css');
}
jrto_enqueue_script('frontend', 'jigoshop-cart', JIGOSHOP_URL.'/assets/js/cart.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_CART));
jrto_enqueue_script('frontend', 'jigoshop-checkout', JIGOSHOP_URL.'/assets/js/checkout.js', array('jquery', 'jquery-blockui'), array('in_footer' => true, 'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_PAY)));
jrto_enqueue_script('frontend', 'jigoshop-validation', JIGOSHOP_URL.'/assets/js/validation.js', array(), array('in_footer' => true, 'page' => JIGOSHOP_CHECKOUT));
jrto_enqueue_script('frontend', 'jigoshop-payment', JIGOSHOP_URL.'/assets/js/pay.js', array('jquery'), array('page' => JIGOSHOP_PAY));
jrto_enqueue_script('frontend', 'jigoshop-single-product', JIGOSHOP_URL.'/assets/js/single-product.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_PRODUCT));
jrto_enqueue_script('frontend', 'jigoshop-countries', JIGOSHOP_URL.'/assets/js/countries.js', array(), array(
'in_footer' => true,
'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_CART, JIGOSHOP_EDIT_ADDRESS)
));
/* Script.js variables */
// TODO: clean this up, a lot aren't even used anymore, do away with it
$jigoshop_params = array(
'ajax_url' => admin_url('admin-ajax.php', 'jigoshop'),
'assets_url' => JIGOSHOP_URL,
'validate_postcode' => $options->get('jigoshop_enable_postcode_validating', 'no'),
'checkout_url' => admin_url('admin-ajax.php?action=jigoshop-checkout', 'jigoshop'),
'currency_symbol' => get_jigoshop_currency_symbol(),
'get_variation_nonce' => wp_create_nonce("get-variation"),
'load_fancybox' => $options->get('jigoshop_disable_fancybox') == 'no',
'option_guest_checkout' => $options->get('jigoshop_enable_guest_checkout'),
'select_state_text' => __('Select a state…', 'jigoshop'),
'state_text' => __('state', 'jigoshop'),
'ratings_message' => __('Please select a star to rate your review.', 'jigoshop'),
'update_order_review_nonce' => wp_create_nonce("update-order-review"),
'billing_state' => jigoshop_customer::get_state(),
'shipping_state' => jigoshop_customer::get_shipping_state(),
'is_checkout' => (is_page(jigoshop_get_page_id('checkout')) || is_page(jigoshop_get_page_id('pay'))),
'error_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_error_disappear_time', 8000),
'message_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_message_disappear_time', 4000),
);
if (isset(jigoshop_session::instance()->min_price)) {
$jigoshop_params['min_price'] = $_GET['min_price'];
}
if (isset(jigoshop_session::instance()->max_price)) {
$jigoshop_params['max_price'] = $_GET['max_price'];
}
$jigoshop_params = apply_filters('jigoshop_params', $jigoshop_params);
jrto_localize_script('jigoshop_global', 'jigoshop_params', $jigoshop_params);
}
/**
* Add post thumbnail support to WordPress if needed
*/
add_action('after_setup_theme', 'jigoshop_check_thumbnail_support', 99);
function jigoshop_check_thumbnail_support()
{
if (!current_theme_supports('post-thumbnails')) {
add_theme_support('post-thumbnails');
remove_post_type_support('post', 'thumbnail');
remove_post_type_support('page', 'thumbnail');
} else {
add_post_type_support('product', 'thumbnail');
}
}
add_action('current_screen', 'jigoshop_admin_styles');
function jigoshop_admin_styles()
{
/* Our setting icons */
jrto_enqueue_style('admin', 'jigoshop_admin_icons_style', JIGOSHOP_URL.'/assets/css/admin-icons.css');
global $current_screen;
if ($current_screen === null || (!jigoshop_is_admin_page() && $current_screen->base !== 'user-edit')) {
return;
}
jrto_enqueue_style('admin', 'jigoshop-select2', JIGOSHOP_URL.'/assets/css/select2.css');
if (jigoshop_is_admin_page()) {
wp_enqueue_style('thickbox');
jrto_enqueue_style('admin', 'jigoshop_admin_styles', JIGOSHOP_URL.'/assets/css/admin.css');
jrto_enqueue_style('admin', 'jigoshop-jquery-ui', JIGOSHOP_URL.'/assets/css/jquery-ui.css');
jrto_enqueue_style('admin', 'prettyPhoto', JIGOSHOP_URL.'/assets/css/prettyPhoto.css');
}
}
add_action('admin_enqueue_scripts', 'jigoshop_admin_scripts', 1);
function jigoshop_admin_scripts()
{
global $current_screen;
if (!jigoshop_is_admin_page() && $current_screen->base !== 'user-edit') {
return;
}
jrto_enqueue_script('admin', 'jigoshop-select2', JIGOSHOP_URL.'/assets/js/select2.min.js', array('jquery'));
jrto_enqueue_script('admin', 'jigoshop-editor-shortcodes', JIGOSHOP_URL.'/assets/js/editor-shortcodes.js', array('jquery'));
wp_register_script('jquery-blockui', '//cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.66.0-2013.10.09/jquery.blockUI.min.js', array('jquery'));
if (jigoshop_is_admin_page()) {
wp_enqueue_media();
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('jquery-blockui');
jrto_enqueue_script('admin', 'jigoshop_datetimepicker', JIGOSHOP_URL.'/assets/js/jquery-ui-timepicker-addon.min.js', array('jquery', 'jquery-ui-datepicker'));
jrto_enqueue_script('admin', 'jigoshop_media', JIGOSHOP_URL.'/assets/js/media.js', array('jquery', 'media-editor'));
jrto_enqueue_script('admin', 'jigoshop_backend', JIGOSHOP_URL.'/assets/js/backend.js', array('jquery'), array('version' => JIGOSHOP_VERSION));
if($current_screen->base == 'edit-tags' && Jigoshop_Base::get_options()->get('jigoshop_enable_draggable_categories') == 'yes') {
jrto_enqueue_script('admin', 'jigoshop_draggable_categories', JIGOSHOP_URL.'/assets/js/draggable_categories.js', array('jquery'), array('version' => JIGOSHOP_VERSION));
}
jrto_enqueue_script('admin', 'jquery_flot', JIGOSHOP_URL.'/assets/js/admin/jquery.flot.min.js', array('jquery'), array(
'version' => '0.8.1',
'page' => array('jigoshop_page_jigoshop_reports', 'toplevel_page_jigoshop')
)
);
jrto_enqueue_script('admin', 'jquery_flot_pie', JIGOSHOP_URL.'/assets/js/admin/jquery.flot.pie.min.js', array('jquery'), array(
'version' => '0.8.1',
'page' => array('jigoshop_page_jigoshop_reports', 'toplevel_page_jigoshop')
)
);
jrto_enqueue_script('admin', 'jquery_flot_resize', JIGOSHOP_URL.'/assets/js/admin/jquery.flot.resize.min.js', array('jquery'), array(
'version' => '0.8.1',
'page' => array('jigoshop_page_jigoshop_reports', 'toplevel_page_jigoshop')
)
);
jrto_enqueue_script('admin', 'jquery_flot_stack', JIGOSHOP_URL.'/assets/js/admin/jquery.flot.stack.min.js', array('jquery'), array(
'version' => '0.8.1',
'page' => array('jigoshop_page_jigoshop_reports', 'toplevel_page_jigoshop')
)
);
jrto_enqueue_script('admin', 'jquery_flot_time', JIGOSHOP_URL.'/assets/js/admin/jquery.flot.time.min.js', array('jquery'), array(
'version' => '0.8.1',
'page' => array('jigoshop_page_jigoshop_reports', 'toplevel_page_jigoshop')
)
);
jrto_enqueue_script('admin', 'jigoshop_reports', JIGOSHOP_URL.'/assets/js/admin/reports.js', array('jquery'), array(
'version' => JIGOSHOP_VERSION,
'page' => array('jigoshop_page_jigoshop_reports', 'toplevel_page_jigoshop')
)
);
jrto_enqueue_script('admin', 'jquery.tiptip', JIGOSHOP_URL.'/assets/js/admin/jquery.tipTip.min.js', array('jquery'), array(
'version' => '1.3',
'page' => array('jigoshop_page_jigoshop_reports', 'jigoshop_page_jigoshop_system_info', 'toplevel_page_jigoshop')
)
);
jrto_enqueue_script('admin', 'jquery.zeroclipboard', JIGOSHOP_URL.'/assets/js/admin/jquery.zeroclipboard.min.js', array('jquery'), array(
'version' => '0.2.0',
'page' => array('jigoshop_page_jigoshop_system_info', 'toplevel_page_jigoshop')
)
);
jrto_localize_script('jigoshop_backend', 'jigoshop_params', array(
'ajax_url' => admin_url('admin-ajax.php', 'jigoshop'),
'search_products_nonce' => wp_create_nonce("search-products"),
));
$pagenow = jigoshop_is_admin_page();
/**
* Disable autosaves on the order and coupon pages. Prevents the javascript alert when modifying.
* `wp_deregister_script( 'autosave' )` would produce errors, so we use a filter instead.
*/
if ($pagenow == 'shop_order' || $pagenow == 'shop_coupon') {
add_filter('script_loader_src', 'jigoshop_disable_autosave', 10, 2);
}
}
}
function jigoshop_register_shortcode_editor( $plugin_array ) {
$plugin_array['jigoshopShortcodes'] = JIGOSHOP_URL.'/assets/js/editor-shortcodes.js';
return $plugin_array;
}
function jigoshop_register_shortcode_buttons( $buttons ) {
array_push( $buttons, "jrto_enqueue_cart" );
array_push( $buttons, "jigoshop_show_product" );
array_push( $buttons, "jigoshop_show_category" );
array_push( $buttons, "jigoshop_show_featured_products" );
array_push( $buttons, "jigoshop_show_selected_products" );
array_push( $buttons, "jigoshop_product_search" );
array_push( $buttons, "jigoshop_recent_products" );
array_push( $buttons, "jigoshop_sale_products" );
return $buttons;
}
/**
* Load required CSS files when frontend styles
*/
add_action('init', 'jigoshop_check_required_css', 99);
function jigoshop_check_required_css()
{
global $wp_styles;
$options = Jigoshop_Base::get_options();
if (empty($wp_styles->registered['jigoshop_styles'])) {
jrto_enqueue_style('frontend', 'jigoshop-jquery-ui', JIGOSHOP_URL.'/assets/css/jquery-ui.css');
jrto_enqueue_style('frontend', 'jigoshop-select2', JIGOSHOP_URL.'/assets/css/select2.css');
if ($options->get('jigoshop_disable_fancybox') == 'no') {
jrto_enqueue_style('frontend', 'prettyPhoto', JIGOSHOP_URL.'/assets/css/prettyPhoto.css');
}
}
}
//### Functions #########################################################
/**
* Set Jigoshop Product Image Sizes for WordPress based on Admin->Jigoshop->Settings->Images
*/
function jigoshop_set_image_sizes()
{
$options = Jigoshop_Base::get_options();
$sizes = array(
'shop_tiny' => 'tiny',
'shop_thumbnail' => 'thumbnail',
'shop_small' => 'catalog',
'shop_large' => 'featured'
);
foreach ($sizes as $size => $altSize) {
add_image_size(
$size,
$options->get('jigoshop_'.$size.'_w'),
$options->get('jigoshop_'.$size.'_h'),
($options->get('jigoshop_use_wordpress_'.$altSize.'_crop', 'no') == 'yes')
);
}
/* The elephant in the room (._. ) */
add_image_size('admin_product_list', 32, 32, $options->get('jigoshop_use_wordpress_tiny_crop', 'no') == 'yes' ? true : false);
}
/**
* Get Jigoshop Product Image Size based on Admin->Jigoshop->Settings->Images
*
* @param string $size - one of the 4 defined Jigoshop image sizes
* @return array - an array containing the width and height of the required size
* @since 0.9.9
*/
function jigoshop_get_image_size($size)
{
$options = Jigoshop_Base::get_options();
if (is_array($size)) {
return $size;
}
switch ($size) {
case 'admin_product_list':
$image_size = array(32, 32);
break;
case 'shop_tiny':
$image_size = array($options->get('jigoshop_shop_tiny_w'), $options->get('jigoshop_shop_tiny_h'));
break;
case 'shop_thumbnail':
$image_size = array($options->get('jigoshop_shop_thumbnail_w'), $options->get('jigoshop_shop_thumbnail_h'));
break;
case 'shop_small':
$image_size = array($options->get('jigoshop_shop_small_w'), $options->get('jigoshop_shop_small_h'));
break;
case 'shop_large':