forked from jigoshop/jigoshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jigoshop.php
1232 lines (991 loc) · 41.1 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: http://jigoshop.com/
* Description: Jigoshop, a WordPress eCommerce plugin that works.
* Author: Jigowatt
* Author URI: http://jigowatt.co.uk
*
* Version: 1.4.9
* Requires at least: 3.3
* Tested up to: 3.5
*
* 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 Jigowatt
* @copyright Copyright © 2011-2012 Jigowatt Ltd.
* @license http://jigoshop.com/license/commercial-edition
*/
if ( !defined( "JIGOSHOP_VERSION" )) define( "JIGOSHOP_VERSION", 1211270) ;
if ( !defined( "JIGOSHOP_OPTIONS" )) define( "JIGOSHOP_OPTIONS", 'jigoshop_options' );
if ( !defined( 'JIGOSHOP_TEMPLATE_URL' ) ) define( 'JIGOSHOP_TEMPLATE_URL', 'jigoshop/' );
if ( !defined( "PHP_EOL" )) define( "PHP_EOL", "\r\n" );
/**
* 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( '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/skrill.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.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_templates.php' );
include_once( 'jigoshop_template_actions.php' );
include_once( 'jigoshop_emails.php' );
include_once( 'jigoshop_actions.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' );
}
/**
* Jigoshop Inits
**/
add_action( 'init', 'jigoshop_init', 0 );
function jigoshop_init() {
/* ensure nothing is output to the browser prior to this (other than headers) */
ob_start();
// http://www.geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
// this means that all Jigoshop extensions, shipping modules and gateways must load their text domains on the 'init' action hook
//
// 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/' );
// instantiate options -after- loading text domains
$jigoshop_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
if ( ! is_admin()) {
/* Catalog Filters */
add_filter( 'loop-shop-query', create_function( '', 'return array("orderby" => "' . $jigoshop_options->get_option('jigoshop_catalog_sort_orderby') . '","order" => "' . $jigoshop_options->get_option('jigoshop_catalog_sort_direction') . '");' ) );
add_filter( 'loop_shop_columns' , create_function( '', 'return ' . $jigoshop_options->get_option('jigoshop_catalog_columns') . ';' ) );
add_filter( 'loop_shop_per_page', create_function( '', 'return ' . $jigoshop_options->get_option('jigoshop_catalog_per_page') . ';' ) );
jigoshop_catalog_query::instance(); // front end queries class
}
jigoshop_roles_init();
}
function jigoshop_get_core_capabilities() {
$capabilities = array();
$capabilities['core'] = array(
"manage_jigoshop",
"view_jigoshop_reports"
);
$capability_types = array( 'product', 'shop_order', 'shop_coupon' );
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
) );
$capabilities = jigoshop_get_core_capabilities();
foreach( $capabilities as $cap_group ) {
foreach( $cap_group as $cap ) {
$wp_roles->add_cap( 'administrator', $cap );
}
}
}
}
/**
* 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' );
}
/**
* Jigoshop Frontend Styles and Scripts
**/
add_action( 'template_redirect', 'jigoshop_frontend_scripts' );
function jigoshop_frontend_scripts() {
if ( ! is_jigoshop() && is_admin() ) return false;
$jigoshop_options = Jigoshop_Base::get_options();
/**
* Frontend Styles
*
* For Jigoshop 1.3 or better there are 2 CSS related options
* The ususal 'jigoshop_disable_css' must be off to use -any- Jigoshop CSS
* otherwise the theme is expected to provide -all- CSS located wherever it likes, loaded by the theme
* A user can also copy both frontend.less and frontend.css to a 'jigoshop' folder in the theme folder and
* rename them to style.less and style.css and compile changes with SimpLESS
* http://wearekiss.com/simpless
* If Jigoshop finds this file, it will load -only- that file, or if not found will default to our frontend.css
* A user can also with the second option 'jigoshop_frontend_with_theme_css' enabled, load -both- the default frontend.css
* -and- any extra bits found in the same 'theme/jigoshop/style.css'
* This allows only a few modifications to be added in after the default frontend.css
* It will also allow for easier additions to frontend.css that get missed if themers don't upgrade their version.
* With these 2 options, users should either provide the complete frontend.css (style.css in the theme jigoshop folder)
* or just the few changes again in the style.css in the theme jigoshop folder and set the 2nd option accordingly
*/
$frontend_css = jigoshop::assets_url() . '/assets/css/frontend.css';
$theme_css = file_exists( get_stylesheet_directory() . '/jigoshop/style.css')
? get_stylesheet_directory_uri() . '/jigoshop/style.css'
: jigoshop::assets_url() . '/assets/css/frontend.css';
if ( $jigoshop_options->get_option( 'jigoshop_disable_css' ) == 'no' ) {
if ( $jigoshop_options->get_option( 'jigoshop_frontend_with_theme_css' ) == 'yes' ) {
wp_enqueue_style( 'jigoshop_frontend_styles', $frontend_css );
}
wp_enqueue_style( 'jigoshop_theme_styles', $theme_css );
}
if ( $jigoshop_options->get_option( 'jigoshop_disable_fancybox' ) == 'no' ) {
wp_enqueue_style( 'jigoshop_fancybox_styles', jigoshop::assets_url() . '/assets/css/fancybox.css' );
wp_enqueue_script( 'fancybox', jigoshop::assets_url().'/assets/js/jquery.fancybox-1.3.4.pack.js', array('jquery'));
}
wp_enqueue_style( 'jqueryui_styles', jigoshop::assets_url().'/assets/css/ui.css' );
wp_enqueue_script( 'jqueryui', jigoshop::assets_url().'/assets/js/jquery-ui-1.9.2.min.js', array('jquery'), '1.9.2' );
wp_enqueue_script( 'jigoshop_blockui', jigoshop::assets_url().'/assets/js/blockui.js', array('jquery'));
wp_enqueue_script( 'jigoshop_frontend', jigoshop::assets_url().'/assets/js/jigoshop_frontend.js', array('jquery'));
wp_enqueue_script( 'jigoshop_script', jigoshop::assets_url().'/assets/js/script.js', array('jquery'));
/* Script.js variables */
$jigoshop_params = array(
'ajax_url' => admin_url('admin-ajax.php'),
'assets_url' => jigoshop::assets_url(),
'checkout_url' => admin_url('admin-ajax.php?action=jigoshop-checkout'),
'countries' => json_encode(jigoshop_countries::$states),
'currency_symbol' => get_jigoshop_currency_symbol(),
'get_variation_nonce' => wp_create_nonce("get-variation"),
'load_fancybox' => $jigoshop_options->get_option( 'jigoshop_disable_fancybox' )=='no'?true:false,
'option_guest_checkout' => $jigoshop_options->get_option('jigoshop_enable_guest_checkout'),
'select_state_text' => __('Select a state…', 'jigoshop'),
'state_text' => __('state', 'jigoshop'),
'update_order_review_nonce' => wp_create_nonce("update-order-review"),
'billing_state' => jigoshop_customer::get_state(),
'shipping_state' => jigoshop_customer::get_shipping_state()
);
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['is_checkout'] = ( is_page( jigoshop_get_page_id( 'checkout' )) || is_page( jigoshop_get_page_id( 'pay' )) );
$jigoshop_params = apply_filters('jigoshop_params', $jigoshop_params);
wp_localize_script( 'jigoshop_script', 'jigoshop_params', $jigoshop_params );
}
/**
* Add a "Settings" link to the plugins.php page for Jigoshop
**/
add_filter( 'plugin_action_links', 'jigoshop_add_settings_link', 10, 2 );
function jigoshop_add_settings_link( $links, $file ) {
$this_plugin = plugin_basename( __FILE__ );
if ( $file == $this_plugin ) {
$settings_link = '<a href="admin.php?page=jigoshop_settings">' . __( 'Settings', 'jigoshop' ) . '</a>';
array_unshift( $links, $settings_link );
}
return $links;
}
/**
* 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( 'admin_enqueue_scripts', 'jigoshop_admin_styles' );
function jigoshop_admin_styles() {
/* Our setting icons */
wp_enqueue_style( 'jigoshop_admin_icons_style', jigoshop::assets_url() . '/assets/css/admin-icons.css' );
if ( ! jigoshop_is_admin_page() ) return false;
wp_enqueue_style( 'jigoshop_admin_styles', jigoshop::assets_url() . '/assets/css/admin.css' );
wp_enqueue_style( 'jigoshop-select2', jigoshop::assets_url() . '/assets/css/select2.css', '', '3.1', 'screen' );
wp_enqueue_style( 'jquery-ui-jigoshop-styles', jigoshop::assets_url() . '/assets/css/jquery-ui-1.8.16.jigoshop.css' );
wp_enqueue_style( 'thickbox' );
}
add_action( 'admin_print_scripts', 'jigoshop_admin_scripts' );
function jigoshop_admin_scripts() {
if ( !jigoshop_is_admin_page() ) return false;
$pagenow = jigoshop_is_admin_page();
wp_enqueue_script( 'jigoshop-select2', jigoshop::assets_url().'/assets/js/select2.min.js', array( 'jquery' ), '3.1' );
wp_enqueue_script( 'jquery-ui-datepicker', jigoshop::assets_url().'/assets/js/jquery-ui-datepicker-1.8.16.min.js', array( 'jquery' ), '1.8.16' );
wp_enqueue_script( 'jigoshop_blockui', jigoshop::assets_url() . '/assets/js/blockui.js', array( 'jquery' ), '2.4.6' );
wp_enqueue_script( 'jigoshop_backend', jigoshop::assets_url() . '/assets/js/jigoshop_backend.js', array( 'jquery' ), '1.0' );
wp_enqueue_script( 'thickbox' );
if ( $pagenow == 'jigoshop_page_jigoshop_reports' || $pagenow == 'toplevel_page_jigoshop' ) {
wp_enqueue_script('jquery_flot', jigoshop::assets_url().'/assets/js/jquery.flot.min.js', array( 'jquery' ), '1.0' );
wp_enqueue_script('jquery_flot_pie', jigoshop::assets_url().'/assets/js/jquery.flot.pie.min.js', array( 'jquery' ), '1.0' );
}
/**
* 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 );
}
//### Functions #########################################################
/**
* Set Jigoshop Product Image Sizes for WordPress based on Admin->Jigoshop->Settings->Images
**/
function jigoshop_set_image_sizes() {
$jigoshop_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,
$jigoshop_options->get_option('jigoshop_' . $size . '_w'),
$jigoshop_options->get_option('jigoshop_' . $size . '_h'),
( $jigoshop_options->get_option( 'jigoshop_use_wordpress_' . $altSize . '_crop', 'no' ) == 'yes' )
);
/* The elephant in the room (._. ) */
add_image_size( 'admin_product_list', 32, 32, $jigoshop_options->get_option( '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 ) {
$jigoshop_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( $jigoshop_options->get_option('jigoshop_shop_tiny_w'), $jigoshop_options->get_option('jigoshop_shop_tiny_h') );
break;
case 'shop_thumbnail':
$image_size = array( $jigoshop_options->get_option('jigoshop_shop_thumbnail_w'), $jigoshop_options->get_option('jigoshop_shop_thumbnail_h') );
break;
case 'shop_small':
$image_size = array( $jigoshop_options->get_option('jigoshop_shop_small_w'), $jigoshop_options->get_option('jigoshop_shop_small_h') );
break;
case 'shop_large':
$image_size = array( $jigoshop_options->get_option('jigoshop_shop_large_w'), $jigoshop_options->get_option('jigoshop_shop_large_h') );
break;
default:
$image_size = array( $jigoshop_options->get_option('jigoshop_shop_small_w'), $jigoshop_options->get_option('jigoshop_shop_small_h') );
break;
endswitch;
return $image_size;
}
function jigoshop_is_admin_page() {
global $current_screen;
if ( $current_screen->post_type == 'product' || $current_screen->post_type == 'shop_order' || $current_screen->post_type == 'shop_coupon' )
return $current_screen->post_type;
if ( strstr( $current_screen->id, 'jigoshop' ) )
return $current_screen->id;
return false;
}
function jigoshop_disable_autosave( $src, $handle ) {
if ( 'autosave' != $handle ) return $src;
return '';
}
/**
* jigoshop_demo_store
* Adds a demo store banner to the site
*/
add_action( 'wp_footer', 'jigoshop_demo_store' );
function jigoshop_demo_store() {
if ( Jigoshop_Base::get_options()->get_option( 'jigoshop_demo_store' ) == 'yes' && is_jigoshop() ) :
$bannner_text = apply_filters( 'jigoshop_demo_banner_text', __('This is a demo store for testing purposes — no orders shall be fulfilled.', 'jigoshop') );
echo '<p class="demo_store">'.$bannner_text.'</p>';
endif;
}
/**
* jigoshop_sharethis
* Adds social sharing code to footer
*/
add_action( 'wp_footer', 'jigoshop_sharethis' );
function jigoshop_sharethis() {
$jigoshop_options = Jigoshop_Base::get_options();
if (is_single() && $jigoshop_options->get_option('jigoshop_sharethis')) :
if (is_ssl()) :
$sharethis = 'https://ws.sharethis.com/button/buttons.js';
else :
$sharethis = 'http://w.sharethis.com/button/buttons.js';
endif;
echo '<script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="'.$sharethis.'"></script><script type="text/javascript">stLight.options({publisher:"'.$jigoshop_options->get_option('jigoshop_sharethis').'"});</script>';
endif;
}
/**
* Mail from name/email
**/
add_filter( 'wp_mail_from_name', 'jigoshop_mail_from_name' );
function jigoshop_mail_from_name( $name ) {
$name = get_bloginfo('name');
$name = esc_attr($name);
return $name;
}
/*
add_filter( 'wp_mail_from', 'jigoshop_mail_from' );
function jigoshop_mail_from( $email ) {
$email = Jigoshop_Base::get_options()->get_option('jigoshop_email');
return $email;
}
*/
/**
* Allow product_cat in the permalinks for products.
*
* @param string $permalink The existing permalink URL.
*/
add_filter( 'post_type_link', 'jigoshop_product_cat_filter_post_link', 10, 4 );
function jigoshop_product_cat_filter_post_link( $permalink, $post, $leavename, $sample ) {
if ($post->post_type!=='product') return $permalink;
// Abort early if the placeholder rewrite tag isn't in the generated URL
if ( false === strpos( $permalink, '%product_cat%' ) ) return $permalink;
// Get the custom taxonomy terms in use by this post
$terms = get_the_terms( $post->ID, 'product_cat' );
if ( empty( $terms ) ) :
// If no terms are assigned to this post, use a string instead
$permalink = str_replace( '%product_cat%', _x('product', 'slug', 'jigoshop'), $permalink );
else :
// Replace the placeholder rewrite tag with the first term's slug
$first_term = apply_filters( 'jigoshop_product_cat_permalink_terms', array_shift( $terms ), $terms);
$permalink = str_replace( '%product_cat%', $first_term->slug, $permalink );
endif;
return $permalink;
}
/**
* Evaluates to true only on the Shop page, not Product categories and tags
* Note:is used to replace is_page( jigoshop_get_page_id( 'shop' ) )
*
* @return bool
* @since 0.9.9
*/
function is_shop() {
return is_post_type_archive( 'product' ) || is_page( jigoshop_get_page_id('shop') );
}
/**
* Evaluates to true only on the Category Pages
*
* @return bool
* @since 0.9.9
*/
function is_product_category() {
return is_tax( 'product_cat' );
}
/**
* Evaluates to true only on the Tag Pages
*
* @return bool
* @since 0.9.9
*/
function is_product_tag() {
return is_tax( 'product_tag' );
}
/**
* Evaluates to true only on the Single Product Page
*
* @return bool
* @since 0.9.9
*/
function is_product() {
return is_singular( array('product') );
}
/**
* Evaluates to true only on Shop, Product Category, and Product Tag pages
*
* @return bool
* @since 0.9.9
*/
function is_product_list() {
$is_list = false;
$is_list |= is_shop();
$is_list |= is_product_tag();
$is_list |= is_product_category();
return $is_list;
}
/**
* Evaluates to true for all Jigoshop pages
*
* @return bool
* @since 0.9.9
*/
function is_jigoshop() {
$is_jigo = false;
$is_jigo |= is_content_wrapped();
$is_jigo |= is_account();
$is_jigo |= is_cart();
$is_jigo |= is_checkout();
$is_jigo |= is_order_tracker();
return $is_jigo;
}
/**
* Evaluates to true only on the Shop, Category, Tag and Single Product Pages
*
* @return bool
* @since 0.9.9.1
*/
function is_content_wrapped() {
$is_wrapped = false;
$is_wrapped |= is_product_list();
$is_wrapped |= is_product();
return $is_wrapped;
}
/**
* Jigoshop page IDs
*
* returns -1 if no page is found
**/
if (!function_exists('jigoshop_get_page_id')) {
function jigoshop_get_page_id( $page ) {
$jigoshop_options = Jigoshop_Base::get_options();
$page = apply_filters('jigoshop_get_' . $page . '_page_id', $jigoshop_options->get_option('jigoshop_' . $page . '_page_id'));
return ($page) ? $page : -1;
}
}
/**
* Evaluates to true only on the Order Tracking page
*
* @return bool
* @since 0.9.9.1
*/
function is_order_tracker() {
return is_page( jigoshop_get_page_id('track_order'));
}
/**
* Evaluates to true only on the Cart page
*
* @return bool
* @since 0.9.8
*/
function is_cart() {
return is_page( jigoshop_get_page_id('cart'));
}
/**
* Evaluates to true only on the Checkout or Pay pages
*
* @return bool
* @since 0.9.8
*/
function is_checkout() {
return is_page( jigoshop_get_page_id('checkout')) | is_page( jigoshop_get_page_id('pay'));
}
/**
* Evaluates to true only on the main Account or any sub-account pages
*
* @return bool
* @since 0.9.9.1
*/
function is_account() {
$is_account = false;
$is_account |= is_page( jigoshop_get_page_id('myaccount') );
$is_account |= is_page( jigoshop_get_page_id('edit_address') );
$is_account |= is_page( jigoshop_get_page_id('change_password') );
$is_account |= is_page( jigoshop_get_page_id('view_order') );
return $is_account;
}
if (!function_exists('is_ajax')) {
function is_ajax() {
if ( isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) return true;
return false;
}
}
function jigoshop_force_ssl() {
if (is_checkout() && !is_ssl()) :
wp_safe_redirect( str_replace('http:', 'https:', get_permalink(jigoshop_get_page_id('checkout'))), 301 );
exit;
endif;
}
if (!is_admin() && Jigoshop_Base::get_options()->get_option('jigoshop_force_ssl_checkout')=='yes') add_action( 'wp', 'jigoshop_force_ssl');
function jigoshop_force_ssl_images( $content ) {
if (is_ssl()) :
if (is_array($content)) :
$content = array_map('jigoshop_force_ssl_images', $content);
else :
$content = str_replace('http:', 'https:', $content);
endif;
endif;
return $content;
}
add_filter('post_thumbnail_html', 'jigoshop_force_ssl_images');
add_filter('widget_text', 'jigoshop_force_ssl_images');
add_filter('wp_get_attachment_url', 'jigoshop_force_ssl_images');
add_filter('wp_get_attachment_image_attributes', 'jigoshop_force_ssl_images');
add_filter('wp_get_attachment_url', 'jigoshop_force_ssl_images');
function jigoshop_force_ssl_urls( $url ) {
if (is_ssl()) :
$url = str_replace('http:', 'https:', $url);
endif;
return $url;
}
add_filter('option_siteurl', 'jigoshop_force_ssl_urls');
add_filter('option_home', 'jigoshop_force_ssl_urls');
add_filter('option_url', 'jigoshop_force_ssl_urls');
add_filter('option_wpurl', 'jigoshop_force_ssl_urls');
add_filter('option_stylesheet_url', 'jigoshop_force_ssl_urls');
add_filter('option_template_url', 'jigoshop_force_ssl_urls');
add_filter('script_loader_src', 'jigoshop_force_ssl_urls');
add_filter('style_loader_src', 'jigoshop_force_ssl_urls');
// http://www.xe.com/symbols.php
function get_jigoshop_currency_symbol() {
$jigoshop_options = Jigoshop_Base::get_options();
$currency = $jigoshop_options->get_option('jigoshop_currency');
$currency_symbol = '';
switch ($currency) :
case 'AED' : $currency_symbol = 'د.إ'; break;
case 'AUD' : $currency_symbol = '$'; break;
case 'BRL' : $currency_symbol = 'R$'; break;
case 'CAD' : $currency_symbol = '$'; break;
case 'CHF' : $currency_symbol = 'SFr.'; break;
case 'CNY' : $currency_symbol = '¥'; break;
case 'CZK' : $currency_symbol = 'Kč'; break;
case 'DKK' : $currency_symbol = 'kr'; break;
case 'EUR' : $currency_symbol = '€'; break;
case 'GBP' : $currency_symbol = '£'; break;
case 'HKD' : $currency_symbol = '$'; break;
case 'HRK' : $currency_symbol = 'kn'; break;
case 'HUF' : $currency_symbol = 'Ft'; break;
case 'IDR' : $currency_symbol = 'Rp'; break;
case 'ILS' : $currency_symbol = '₪'; break;
case 'INR' : $currency_symbol = '₨'; break;
case 'JPY' : $currency_symbol = '¥'; break;
case 'KES' : $currency_symbol = 'KSh'; break;
case 'MXN' : $currency_symbol = '$'; break;
case 'MYR' : $currency_symbol = 'RM'; break;
case 'NGN' : $currency_symbol = '₦'; break;
case 'NOK' : $currency_symbol = 'kr'; break;
case 'NZD' : $currency_symbol = '$'; break;
case 'PHP' : $currency_symbol = '₱'; break;
case 'PLN' : $currency_symbol = 'zł'; break;
case 'RON' : $currency_symbol = 'lei'; break;
case 'RUB' : $currency_symbol = 'руб'; break;
case 'SEK' : $currency_symbol = 'kr'; break;
case 'SGD' : $currency_symbol = '$'; break;
case 'THB' : $currency_symbol = '฿'; break;
case 'TRY' : $currency_symbol = '₤'; break;
case 'TWD' : $currency_symbol = 'NT$'; break;
case 'USD' : $currency_symbol = '$'; break;
case 'ZAR' : $currency_symbol = 'R'; break;
default : $currency_symbol = '£'; break;
endswitch;
return apply_filters('jigoshop_currency_symbol', $currency_symbol, $currency);
}
function jigoshop_price( $price, $args = array() ) {
$jigoshop_options = Jigoshop_Base::get_options();
extract(shortcode_atts(array(
'ex_tax_label' => 0, // 0 for no label, 1 for ex. tax, 2 for inc. tax
'with_currency' => true
), $args));
$tax_label = '';
if ($ex_tax_label === 1) {
$tax_label = __(' <small>(ex. tax)</small>', 'jigoshop');
} else if ($ex_tax_label === 2) {
$tax_label = __(' <small>(inc. tax)</small>', 'jigoshop');
} else {
$tax_label = '';
}
$return = '';
$price = number_format(
(double) $price,
(int) $jigoshop_options->get_option('jigoshop_price_num_decimals'),
$jigoshop_options->get_option('jigoshop_price_decimal_sep'),
$jigoshop_options->get_option('jigoshop_price_thousand_sep')
);
$return = $price;
if ($with_currency) :
$currency_pos = $jigoshop_options->get_option('jigoshop_currency_pos');
$currency_symbol = get_jigoshop_currency_symbol();
$currency_code = $jigoshop_options->get_option('jigoshop_currency');
switch ($currency_pos) :
case 'left' :
$return = $currency_symbol . $price;
break;
case 'left_space' :
$return = $currency_symbol . ' ' . $price;
break;
case 'right' :
$return = $price . $currency_symbol;
break;
case 'right_space' :
$return = $price . ' ' . $currency_symbol;
break;
case 'left_code' :
$return = $currency_code . $price;
break;
case 'left_code_space' :
$return = $currency_code . ' ' . $price;
break;
case 'right_code' :
$return = $price . $currency_code;
break;
case 'right_code_space' :
$return = $price . ' ' . $currency_code;
break;
case 'code_symbol' :
$return = $currency_code . $price . $currency_symbol;
break;
case 'code_symbol_space' :
$return = $currency_code . ' ' . $price . ' ' . $currency_symbol;
break;
case 'symbol_code' :
$return = $currency_symbol . $price . $currency_code;
break;
case 'symbol_code_space' :
$return = $currency_symbol . ' ' . $price . ' ' . $currency_code;
break;
endswitch;
// only show tax label (ex. tax) if we are going to show the price with currency as well. Otherwise we just want the formatted price
if ($jigoshop_options->get_option('jigoshop_calc_taxes')=='yes') $return .= $tax_label;
endif;
return $return;
}
/** Show variation info if set */
function jigoshop_get_formatted_variation( $variation = '', $flat = false ) {
if ($variation && is_array($variation)) :
$return = '';
if (!$flat) :
$return = '<dl class="variation">';
endif;
$varation_list = array();
foreach ($variation as $name => $value) :
$name = str_replace('tax_', '', $name);
if ( taxonomy_exists( 'pa_'.$name )) :
$terms = get_terms( 'pa_'.$name, array( 'orderby' => 'slug', 'hide_empty' => '0' ) );
foreach ( $terms as $term ) :
if ( $term->slug == $value ) $value = $term->name;
endforeach;
$name = get_taxonomy( 'pa_'.$name )->labels->name;
$name = jigoshop_product::attribute_label('pa_'.$name);
endif;
if ($flat) :
$varation_list[] = $name.': '.$value;
else :
$varation_list[] = '<dt>'.$name.':</dt><dd>'.$value.'</dd>';
endif;
endforeach;
if ($flat) :
$return .= implode(', ', $varation_list);
else :
$return .= implode('', $varation_list);
endif;
if (!$flat) :
$return .= '</dl>';
endif;
return $return;
endif;
}
// Remove pingbacks/trackbacks from Comments Feed
// betterwp.net/wordpress-tips/remove-pingbackstrackbacks-from-comments-feed/
add_filter('request', 'jigoshop_filter_request');
function jigoshop_filter_request($qv) {
if (isset($qv['feed']) && !empty($qv['withcomments']))
{
add_filter('comment_feed_where', 'jigoshop_comment_feed_where');
}
return $qv;
}
function jigoshop_comment_feed_where($cwhere) {
$cwhere .= " AND comment_type != 'jigoshop' ";
return $cwhere;
}
function jigoshop_let_to_num($v) {
$l = substr($v, -1);
$ret = substr($v, 0, -1);
switch(strtoupper($l)){
case 'P':
$ret *= 1024;
case 'T':
$ret *= 1024;
case 'G':
$ret *= 1024;
case 'M':
$ret *= 1024;
case 'K':
$ret *= 1024;
break;
}
return $ret;
}
function jigowatt_clean( $var ) {
return strip_tags(stripslashes(trim($var)));
}
// Returns a float value
function jigoshop_sanitize_num( $var ) {
// TODO: as it stands, it doesn't allow negative values (-JAP-)
// should be - preg_replace("/^[^[\-\+]0-9\.]/","",$var)
// currently only used for prices in product-data-save.php
return strip_tags(stripslashes(floatval(preg_replace("/^[^0-9\.]/","",$var))));
}
// Author: Sergey Biryukov
// Plugin URI: http://wordpress.org/extend/plugins/allow-cyrillic-usernames/
add_filter('sanitize_user', 'jigoshop_sanitize_user', 10, 3);
function jigoshop_sanitize_user($username, $raw_username, $strict) {
$username = wp_strip_all_tags( $raw_username );
$username = remove_accents( $username );
$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
if ( $strict )
$username = preg_replace( '|[^a-z?-?0-9 _.\-@]|iu', '', $username );
$username = trim( $username );
$username = preg_replace( '|\s+|', ' ', $username );