WooCommerce Menu Cart - Version 2.7.1

Version Description

  • fix label on price to display setting
  • Fix live updating cart for first product with 'Always display cart' setting enabled
Download this release

Release Info

Developer pomegranate
Plugin Icon 128x128 WooCommerce Menu Cart
Version 2.7.1
Comparing to
See all releases

Code changes from version 2.7.0 to 2.7.1

includes/wpmenucart-settings.php CHANGED
@@ -1,784 +1,784 @@
1
- <?php
2
- class WpMenuCart_Settings {
3
-
4
- public function __construct() {
5
- add_action( 'admin_init', array( &$this, 'init_settings' ) ); // Registers settings
6
- add_action( 'admin_menu', array( &$this, 'wpmenucart_add_page' ) );
7
- add_filter( 'plugin_action_links_'.WpMenuCart::$plugin_basename, array( &$this, 'wpmenucart_add_settings_link' ) );
8
-
9
- //Menu admin, not using for now (very complex ajax structure...)
10
- //add_action( 'admin_init', array( &$this, 'wpmenucart_add_meta_box' ) );
11
- }
12
- /**
13
- * User settings.
14
- */
15
- public function init_settings() {
16
- $option = 'wpmenucart';
17
-
18
- // Create option in wp_options.
19
- if ( false == get_option( $option ) ) {
20
- add_option( $option );
21
- }
22
-
23
- // Section.
24
- add_settings_section(
25
- 'plugin_settings',
26
- __( 'Plugin settings', 'wp-menu-cart' ),
27
- array( &$this, 'section_options_callback' ),
28
- $option
29
- );
30
-
31
- add_settings_field(
32
- 'shop_plugin',
33
- __( 'Select which e-commerce plugin you would like Menu Cart to work with', 'wp-menu-cart' ),
34
- array( &$this, 'select_element_callback' ),
35
- $option,
36
- 'plugin_settings',
37
- array(
38
- 'menu' => $option,
39
- 'id' => 'shop_plugin',
40
- 'options' => (array) $this->get_shop_plugins(),
41
- )
42
- );
43
-
44
- if( $parent_theme = wp_get_theme(get_template()) ) {
45
- if (in_array($parent_theme->get('Name'), array('Storefront','Divi'))) {
46
- add_settings_field(
47
- 'hide_theme_cart',
48
- __( 'Hide theme shopping cart icon', 'wp-menu-cart' ),
49
- array( &$this, 'checkbox_element_callback' ),
50
- $option,
51
- 'plugin_settings',
52
- array(
53
- 'menu' => $option,
54
- 'id' => 'hide_theme_cart',
55
- )
56
- );
57
- }
58
- }
59
-
60
- add_settings_field(
61
- 'menu_slugs',
62
- __( 'Select the menu(s) in which you want to display the Menu Cart', 'wp-menu-cart' ),
63
- array( &$this, 'menus_select_element_callback' ),
64
- $option,
65
- 'plugin_settings',
66
- array(
67
- 'menu' => $option,
68
- 'id' => 'menu_slugs',
69
- 'options' => (array) $this->get_menu_array(),
70
- )
71
- );
72
-
73
- add_settings_field(
74
- 'always_display',
75
- __( "Always display cart, even if it's empty", 'wp-menu-cart' ),
76
- array( &$this, 'checkbox_element_callback' ),
77
- $option,
78
- 'plugin_settings',
79
- array(
80
- 'menu' => $option,
81
- 'id' => 'always_display',
82
- )
83
- );
84
-
85
- add_settings_field(
86
- 'icon_display',
87
- __( 'Display shopping cart icon.', 'wp-menu-cart' ),
88
- array( &$this, 'checkbox_element_callback' ),
89
- $option,
90
- 'plugin_settings',
91
- array(
92
- 'menu' => $option,
93
- 'id' => 'icon_display',
94
- )
95
- );
96
-
97
- add_settings_field(
98
- 'flyout_display',
99
- __( 'Display cart contents in menu fly-out.', 'wp-menu-cart' ),
100
- array( &$this, 'checkbox_element_callback' ),
101
- $option,
102
- 'plugin_settings',
103
- array(
104
- 'menu' => $option,
105
- 'id' => 'flyout_display',
106
- 'disabled' => true,
107
- )
108
- );
109
-
110
- add_settings_field(
111
- 'flyout_itemnumber',
112
- __( 'Set maximum number of products to display in fly-out', 'wp-menu-cart' ),
113
- array( &$this, 'select_element_callback' ),
114
- $option,
115
- 'plugin_settings',
116
- array(
117
- 'menu' => $option,
118
- 'id' => 'flyout_itemnumber',
119
- 'options' => array(
120
- '0' => '0',
121
- '1' => '1',
122
- '2' => '2',
123
- '3' => '3',
124
- '4' => '4',
125
- '5' => '5',
126
- '6' => '6',
127
- '7' => '7',
128
- '8' => '8',
129
- '9' => '9',
130
- '10' => '10',
131
- ),
132
- 'disabled' => true,
133
- )
134
- );
135
-
136
- add_settings_field(
137
- 'cart_icon',
138
- __( 'Choose a cart icon.', 'wp-menu-cart' ),
139
- array( &$this, 'icons_radio_element_callback' ),
140
- $option,
141
- 'plugin_settings',
142
- array(
143
- 'menu' => $option,
144
- 'id' => 'cart_icon',
145
- 'options' => array(
146
- '0' => '0',
147
- '1' => '1',
148
- '2' => '2',
149
- '3' => '3',
150
- '4' => '4',
151
- '5' => '5',
152
- '6' => '6',
153
- '7' => '7',
154
- '8' => '8',
155
- '9' => '9',
156
- '10' => '10',
157
- '11' => '11',
158
- '12' => '12',
159
- '13' => '13',
160
- ),
161
- )
162
- );
163
-
164
-
165
- add_settings_field(
166
- 'items_display',
167
- __( 'What would you like to display in the menu?', 'wp-menu-cart' ),
168
- array( &$this, 'radio_element_callback' ),
169
- $option,
170
- 'plugin_settings',
171
- array(
172
- 'menu' => $option,
173
- 'id' => 'items_display',
174
- 'options' => array(
175
- '1' => __( 'Items Only.' , 'wp-menu-cart' ),
176
- '2' => __( 'Price Only.' , 'wp-menu-cart' ),
177
- '3' => __( 'Both price and items.' , 'wp-menu-cart' ),
178
- ),
179
- )
180
- );
181
-
182
- add_settings_field(
183
- 'items_alignment',
184
- __( 'Select the alignment that looks best with your menu.', 'wp-menu-cart' ),
185
- array( &$this, 'radio_element_callback' ),
186
- $option,
187
- 'plugin_settings',
188
- array(
189
- 'menu' => $option,
190
- 'id' => 'items_alignment',
191
- 'options' => array(
192
- 'left' => __( 'Align Left.' , 'wp-menu-cart' ),
193
- 'right' => __( 'Align Right.' , 'wp-menu-cart' ),
194
- 'standard' => __( 'Default Menu Alignment.' , 'wp-menu-cart' ),
195
- ),
196
- )
197
- );
198
-
199
- if ( class_exists( 'WooCommerce' ) ) {
200
- add_settings_field(
201
- 'total_price_type',
202
- __( 'Price to display', 'wp-menu-cart' ),
203
- array( &$this, 'select_element_callback' ),
204
- $option,
205
- 'plugin_settings',
206
- array(
207
- 'menu' => $option,
208
- 'id' => 'total_price_type',
209
- 'options' => array(
210
- 'total' => __( 'Total (including fees)' , 'wp-menu-cart' ),
211
- 'subtotal' => __( 'Subtotal (total of products)' , 'wp-menu-cart' ),
212
- ),
213
- 'default' => 'total',
214
- )
215
- );
216
- }
217
-
218
- add_settings_field(
219
- 'custom_class',
220
- __( 'Enter a custom CSS class (optional)', 'wp-menu-cart' ),
221
- array( &$this, 'text_element_callback' ),
222
- $option,
223
- 'plugin_settings',
224
- array(
225
- 'menu' => $option,
226
- 'id' => 'custom_class',
227
- 'disabled' => true,
228
- )
229
- );
230
-
231
- if ( function_exists( 'icl_register_string' ) ) {
232
- add_settings_field(
233
- 'wpml_string_translation',
234
- __( "Use WPML String Translation", 'wp-menu-cart' ),
235
- array( &$this, 'checkbox_element_callback' ),
236
- $option,
237
- 'plugin_settings',
238
- array(
239
- 'menu' => $option,
240
- 'id' => 'wpml_string_translation',
241
- )
242
- );
243
- }
244
-
245
- if ( class_exists( 'WooCommerce' ) || defined('JIGOSHOP_VERSION') || class_exists( 'Easy_Digital_Downloads' ) ) {
246
- add_settings_field(
247
- 'builtin_ajax',
248
- __( 'Use custom AJAX', 'wp-menu-cart' ),
249
- array( &$this, 'checkbox_element_callback' ),
250
- $option,
251
- 'plugin_settings',
252
- array(
253
- 'menu' => $option,
254
- 'id' => 'builtin_ajax',
255
- 'description' => __( 'Enable this option to use the custom AJAX / live update functions instead of the default ones from your shop plugin. Only use when you have issues with AJAX!', 'wp-menu-cart' ),
256
- )
257
- );
258
- }
259
-
260
- // Register settings.
261
- register_setting( $option, $option, array( &$this, 'wpmenucart_options_validate' ) );
262
-
263
- // Register defaults if settings empty (might not work in case there's only checkboxes and they're all disabled)
264
- $option_values = get_option($option);
265
- if ( empty( $option_values ) )
266
- $this->default_settings();
267
-
268
- // Convert old wpmenucart menu settings to array
269
- if ( isset($option_values['menu_name_1']) ) {
270
- $option_values['menu_slugs'] = array( '1' => $option_values['menu_name_1'] );
271
- update_option( 'wpmenucart', $option_values );
272
- }
273
- }
274
-
275
- /**
276
- * Add menu page
277
- */
278
- public function wpmenucart_add_page() {
279
- if (class_exists('WooCommerce')) {
280
- $parent_slug = 'woocommerce';
281
- } else {
282
- $parent_slug = 'options-general.php';
283
- }
284
-
285
- $wpmenucart_page = add_submenu_page(
286
- $parent_slug,
287
- __( 'Menu Cart', 'wp-menu-cart' ),
288
- __( 'Menu Cart Setup', 'wp-menu-cart' ),
289
- 'manage_options',
290
- 'wpmenucart_options_page',
291
- array( $this, 'wpmenucart_options_do_page' )
292
- );
293
- add_action( 'admin_print_styles-' . $wpmenucart_page, array( &$this, 'wpmenucart_admin_styles' ) );
294
- }
295
-
296
- /**
297
- * Add settings link to plugins page
298
- */
299
- public function wpmenucart_add_settings_link( $links ) {
300
- $settings_link = '<a href="admin.php?page=wpmenucart_options_page">'. __( 'Settings', 'woocommerce' ) . '</a>';
301
- array_push( $links, $settings_link );
302
- return $links;
303
- }
304
-
305
- /**
306
- * Styles for settings page
307
- */
308
- public function wpmenucart_admin_styles() {
309
- wp_register_style( 'wpmenucart-admin', plugins_url( 'css/wpmenucart-icons.css', dirname(__FILE__) ), array(), '', 'all' );
310
- wp_enqueue_style( 'wpmenucart-admin' );
311
- wp_register_style( 'wpmenucart-fontawesome', plugins_url( '/css/wpmenucart-fontawesome.css', dirname(__FILE__) ), array(), '', 'all' );
312
- wp_enqueue_style( 'wpmenucart-fontawesome' );
313
- }
314
-
315
- /**
316
- * Default settings.
317
- */
318
- public function default_settings() {
319
- $wcmenucart_options = get_option('wcmenucart');
320
- $menu_slugs = array( '1' => isset($wcmenucart_options['menu_name_1']) ? $wcmenucart_options['menu_name_1']:'0' );
321
-
322
- $active_shop_plugins = WpMenuCart::get_active_shops();
323
-
324
- //switch keys & values, then strip plugin path to folder
325
- foreach ($active_shop_plugins as $key => $value) {
326
- $filtered_active_shop_plugins[] = dirname($value);
327
- }
328
-
329
- $first_active_shop_plugin = isset($filtered_active_shop_plugins[0])?$filtered_active_shop_plugins[0]:'';
330
- $default = array(
331
- 'menu_slugs' => $menu_slugs,
332
- 'always_display' => isset($wcmenucart_options['always_display']) ? $wcmenucart_options['always_display']:'',
333
- 'icon_display' => isset($wcmenucart_options['icon_display']) ? $wcmenucart_options['icon_display']:'1',
334
- 'items_display' => isset($wcmenucart_options['items_display']) ? $wcmenucart_options['items_display']:'3',
335
- 'items_alignment' => isset($wcmenucart_options['items_alignment']) ? $wcmenucart_options['items_alignment']:'standard',
336
- 'custom_class' => '',
337
- 'flyout_display' => '',
338
- 'flyout_itemnumber' => '5',
339
- 'cart_icon' => '0',
340
- 'shop_plugin' => $first_active_shop_plugin,
341
- 'builtin_ajax' => '',
342
- 'hide_theme_cart' => 1,
343
- );
344
-
345
- update_option( 'wpmenucart', $default );
346
- }
347
-
348
- /**
349
- * Build the options page.
350
- */
351
- public function wpmenucart_options_do_page() {
352
- ?>
353
-
354
- <div class="wrap">
355
- <div class="icon32" id="icon-options-general"><br /></div>
356
- <h2><?php _e('WP Menu Cart', 'wp-menu-cart' ) ?></h2>
357
- <?php
358
- // print_r(get_option('wpmenucart')); //for debugging
359
- //print_r($this->get_shop_plugins());
360
- //print_r(apply_filters( 'active_plugins', get_option( 'active_plugins' )));
361
- if (!$this->get_menu_array()) {
362
- ?>
363
- <div class="error" style="width:400px; padding:10px;">
364
- You need to create a menu before you can use Menu Cart. Go to <strong>Appearence > Menus</strong> and create menu to add the cart to.
365
- </div>
366
- <?php } ?>
367
- <form method="post" action="options.php">
368
- <?php
369
-
370
- settings_fields( 'wpmenucart' );
371
- do_settings_sections( 'wpmenucart' );
372
-
373
- submit_button();
374
- ?>
375
-
376
- </form>
377
- <script type="text/javascript">
378
- jQuery('.hidden-input').click(function() {
379
- jQuery(this).closest('.hidden-input').prev('.pro-feature').show('slow');
380
- jQuery(this).closest('.hidden-input').hide();
381
- });
382
- jQuery('.hidden-input-icon').click(function() {
383
- jQuery('.pro-icon').show('slow');
384
- });
385
- </script>
386
- <style type="text/css">
387
- .menucart-pro-ad {
388
- border: 1px solid #3D5C99;
389
- background-color: #EBF5FF;
390
- border-radius: 5px;
391
- padding: 15px;
392
- }
393
- .menucart-pro-ad-big {
394
- margin-top: 15px;
395
- min-height: 90px;
396
- position: relative;
397
- padding-left: 100px;
398
- }
399
- .menucart-pro-ad-small {
400
- position: absolute;
401
- right: 20px;
402
- top: 20px;
403
- }
404
- img.wpo-helper {
405
- position: absolute;
406
- top: -20px;
407
- left: 3px;
408
- }
409
- </style>
410
- <div class="menucart-pro-ad menucart-pro-ad-small">
411
- Want To Stand Out? <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartgopro">Go Pro.</a>
412
- <ul style="font-size: 12px;list-style-type:circle;margin-left: 20px">
413
- <li><?php _e('Unlimited Menus', 'wp-menu-cart' ) ?></li>
414
- <li><?php _e('Choice of 14 icons', 'wp-menu-cart' ) ?></li>
415
- <li><?php _e('Packed with customization options', 'wp-menu-cart' ) ?></li>
416
- <li><?php _e('Access to Shortcode', 'wp-menu-cart' ) ?></li>
417
- <li><?php _e('Top Notch Support', 'wp-menu-cart' ) ?></li>
418
- </ul>
419
- </div>
420
- <div class="menucart-pro-ad menucart-pro-ad-big">
421
- <img src="<?php echo plugins_url( 'images/', dirname(__FILE__) ) . 'wpo-helper.png'; ?>" class="wpo-helper">
422
- <h2><?php _e('Sell In Style With Menu Cart Pro!', 'wp-menu-cart' ) ?></h2>
423
- <br>
424
- <?php _e('Go Pro with Menu Cart Pro. Includes all the great standard features found in this free version plus:', 'wp-menu-cart' ) ?>
425
- <br>
426
- <ul style="list-style-type:circle;margin-left: 40px">
427
- <li><?php _e('A choice of over 10 cart icons', 'wp-menu-cart' ) ?></li>
428
- <li><?php _e('A fully featured cart details flyout', 'wp-menu-cart' ) ?></li>
429
- <li><?php _e('Ability to add cart + flyout to an <strong>unlimited</strong> amount of menus', 'wp-menu-cart' ) ?></li>
430
- <li><?php _e('Adjust the content & URLs via the settings', 'wp-menu-cart' ) ?></li>
431
- <li><?php _e('Enter custom styles and apply custom classes via the settings', 'wp-menu-cart' ) ?></li>
432
- <li><?php _e('WPML compatible', 'wp-menu-cart' ) ?></li>
433
- <li><?php _e('Automatic updates on any great new features', 'wp-menu-cart' ) ?></li>
434
- <li><?php _e('Put the cart anywhere with the [wpmenucart] shortcode', 'wp-menu-cart' ) ?></li>
435
- </ul>
436
- <?php
437
- $menucartadmore = '<a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartadmore">';
438
- printf (__('Need to see more? %sClick here%s to check it out. Add a product to your cart and watch what happens!', 'wp-menu-cart' ), $menucartadmore,'</a>'); ?><br><br>
439
- <a class="button button-primary" style="text-align: center;margin: 0px auto" href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartadbuy"><?php _e('Buy Now', 'wp-menu-cart' ) ?></a>
440
- </div>
441
- </div>
442
- <?php
443
- }
444
-
445
- /**
446
- * Get menu array.
447
- *
448
- * @return array menu slug => menu name
449
- */
450
- public function get_menu_array() {
451
- $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
452
- $menu_list = array();
453
-
454
- foreach ( $menus as $menu ) {
455
- $menu_list[$menu->slug] = $menu->name;
456
- }
457
-
458
- if (!empty($menu_list)) return $menu_list;
459
- }
460
-
461
- /**
462
- * Get array of active shop plugins
463
- *
464
- * @return array plugin slug => plugin name
465
- */
466
- public function get_shop_plugins() {
467
- $active_shop_plugins = WpMenuCart::get_active_shops();
468
-
469
- //switch keys & values, then strip plugin path to folder
470
- foreach ($active_shop_plugins as $key => $value) {
471
- $filtered_active_shop_plugins[dirname($value)] = $key;
472
- }
473
-
474
- $active_shop_plugins = isset($filtered_active_shop_plugins) ? $filtered_active_shop_plugins:'';
475
-
476
- return $active_shop_plugins;
477
- }
478
-
479
- /**
480
- * Text field callback.
481
- *
482
- * @param array $args Field arguments.
483
- *
484
- * @return string Text field.
485
- */
486
- public function text_element_callback( $args ) {
487
- $menu = $args['menu'];
488
- $id = $args['id'];
489
- $size = isset( $args['size'] ) ? $args['size'] : '25';
490
-
491
- $options = get_option( $menu );
492
-
493
- if ( isset( $options[$id] ) ) {
494
- $current = $options[$id];
495
- } else {
496
- $current = isset( $args['default'] ) ? $args['default'] : '';
497
- }
498
-
499
- $disabled = (isset( $args['disabled'] )) ? ' disabled' : '';
500
- $html = sprintf( '<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" size="%4$s"%5$s/>', $id, $menu, $current, $size, $disabled );
501
-
502
- // Displays option description.
503
- if ( isset( $args['description'] ) ) {
504
- $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
505
- }
506
-
507
- if (isset( $args['disabled'] )) {
508
- $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartcustomclass">Menu Cart Pro</a></i></span>';
509
- $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
510
- $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
511
- }
512
-
513
- echo $html;
514
- }
515
-
516
- /**
517
- * Displays a selectbox for a settings field
518
- *
519
- * @param array $args settings field args
520
- */
521
- public function select_element_callback( $args ) {
522
- $menu = $args['menu'];
523
- $id = $args['id'];
524
-
525
- $options = get_option( $menu );
526
-
527
- if ( isset( $options[$id] ) ) {
528
- $current = $options[$id];
529
- } else {
530
- $current = isset( $args['default'] ) ? $args['default'] : '';
531
- }
532
-
533
- $disabled = (isset( $args['disabled'] )) ? ' disabled' : '';
534
-
535
- $html = sprintf( '<select name="%1$s[%2$s]" id="%1$s[%2$s]"%3$s>', $menu, $id, $disabled );
536
- $html .= sprintf( '<option value="%s"%s>%s</option>', '0', selected( $current, '0', false ), '' );
537
-
538
- foreach ( $args['options'] as $key => $label ) {
539
- $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label );
540
- }
541
- $html .= sprintf( '</select>' );
542
-
543
- if ( isset( $args['description'] ) ) {
544
- $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
545
- }
546
-
547
- if (isset( $args['disabled'] )) {
548
- $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartflyout">Menu Cart Pro</a></i></span>';
549
- $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
550
- $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
551
- }
552
-
553
- echo $html;
554
- }
555
-
556
- /**
557
- * Displays a multiple selectbox for a settings field
558
- *
559
- * @param array $args settings field args
560
- */
561
- public function menus_select_element_callback( $args ) {
562
- $menu = $args['menu'];
563
- $id = $args['id'];
564
-
565
- $options = get_option( $menu );
566
- $menus = $options['menu_slugs'];
567
-
568
- for ( $x = 1; $x <= 3; $x++ ) {
569
- $html = '';
570
- if ( isset( $options[$id][$x] ) ) {
571
- $current = $options[$id][$x];
572
- } else {
573
- $current = isset( $args['default'] ) ? $args['default'] : '';
574
- }
575
-
576
- $disabled = ($x == 1) ? '' : ' disabled';
577
-
578
- $html .= sprintf( '<select name="%1$s[%2$s][%3$s]" id="%1$s[%2$s][%3$s]"%4$s>', $menu, $id, $x, $disabled);
579
- $html .= sprintf( '<option value="%s"%s>%s</option>', '0', selected( $current, '0', false ), '' );
580
-
581
- foreach ( (array) $args['options'] as $key => $label ) {
582
- $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label );
583
- }
584
- $html .= '</select>';
585
-
586
- if ( isset( $args['description'] ) ) {
587
- $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
588
- }
589
- if ( $x > 1 ) {
590
- $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartmultiplemenus">Menu Cart Pro</a></i></span>';
591
- $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
592
- $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
593
- }
594
-
595
- $html .= '<br />';
596
- echo $html;
597
- }
598
-
599
- }
600
-
601
- /**
602
- * Checkbox field callback.
603
- *
604
- * @param array $args Field arguments.
605
- *
606
- * @return string Checkbox field.
607
- */
608
- public function checkbox_element_callback( $args ) {
609
- $menu = $args['menu'];
610
- $id = $args['id'];
611
-
612
- $options = get_option( $menu );
613
-
614
- if ( isset( $options[$id] ) ) {
615
- $current = $options[$id];
616
- } else {
617
- $current = isset( $args['default'] ) ? $args['default'] : '';
618
- }
619
-
620
- $disabled = (isset( $args['disabled'] )) ? ' disabled' : '';
621
- $html = sprintf( '<input type="checkbox" id="%1$s" name="%2$s[%1$s]" value="1"%3$s %4$s/>', $id, $menu, checked( 1, $current, false ), $disabled );
622
-
623
- // Displays option description.
624
- if ( isset( $args['description'] ) ) {
625
- $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
626
- }
627
-
628
- if (isset( $args['disabled'] )) {
629
- $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartflyout">Menu Cart Pro</a></i></span>';
630
- $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
631
- $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
632
- }
633
-
634
- echo $html;
635
- }
636
-
637
- /**
638
- * Displays a multicheckbox a settings field
639
- *
640
- * @param array $args settings field args
641
- */
642
- public function radio_element_callback( $args ) {
643
- $menu = $args['menu'];
644
- $id = $args['id'];
645
-
646
- $options = get_option( $menu );
647
-
648
- if ( isset( $options[$id] ) ) {
649
- $current = $options[$id];
650
- } else {
651
- $current = isset( $args['default'] ) ? $args['default'] : '';
652
- }
653
-
654
- $html = '';
655
- foreach ( $args['options'] as $key => $label ) {
656
- $html .= sprintf( '<input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s"%4$s />', $menu, $id, $key, checked( $current, $key, false ) );
657
- $html .= sprintf( '<label for="%1$s[%2$s][%3$s]"> %4$s</label><br>', $menu, $id, $key, $label);
658
- }
659
-
660
- // Displays option description.
661
- if ( isset( $args['description'] ) ) {
662
- $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
663
- }
664
-
665
- if (isset( $args['disabled'] )) {
666
- $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartflyout">Menu Cart Pro</a></i></span>';
667
- $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
668
- $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
669
- }
670
-
671
- echo $html;
672
- }
673
-
674
- /**
675
- * Displays a multicheckbox a settings field
676
- *
677
- * @param array $args settings field args
678
- */
679
- public function icons_radio_element_callback( $args ) {
680
- $menu = $args['menu'];
681
- $id = $args['id'];
682
-
683
- $options = get_option( $menu );
684
-
685
- if ( isset( $options[$id] ) ) {
686
- $current = $options[$id];
687
- } else {
688
- $current = isset( $args['default'] ) ? $args['default'] : '';
689
- }
690
-
691
- $icons = '';
692
- $radios = '';
693
-
694
- foreach ( $args['options'] as $key => $iconnumber ) {
695
- if ($key == 0) {
696
- $icons .= sprintf( '<td style="padding-bottom:0;font-size:16pt;" align="center"><label for="%1$s[%2$s][%3$s]"><i class="wpmenucart-icon-shopping-cart-%4$s"></i></label></td>', $menu, $id, $key, $iconnumber);
697
- $radios .= sprintf( '<td style="padding-top:0" align="center"><input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s"%4$s /></td>', $menu, $id, $key, checked( $current, $key, false ) );
698
- } else {
699
- $icons .= sprintf( '<td style="padding-bottom:0;font-size:16pt;" align="center"><label for="%1$s[%2$s][%3$s]"><img src="%4$scart-icon-%5$s.png" /></label></td>', $menu, $id, $key, plugins_url( 'images/', dirname(__FILE__) ), $iconnumber);
700
- $radio = sprintf( '<input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" disabled />', $menu, $id, $key);
701
- $radio .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input-icon"></div>';
702
- $radio = '<div style="display:inline-block; position:relative;">'.$radio.'</div>';
703
-
704
- $radios .= '<td style="padding-top:0" align="center">'.$radio.'</td>';
705
- }
706
- }
707
-
708
- $profeature = '<span style="display:none;" class="pro-icon"><i>'. __('Additional icons are only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucarticons">Menu Cart Pro</a></i></span>';
709
-
710
- $html = '<table><tr>'.$icons.'</tr><tr>'.$radios.'</tr></table>'.$profeature;
711
-
712
- echo $html;
713
- }
714
-
715
- /**
716
- * Section null callback.
717
- *
718
- * @return void.
719
- */
720
- public function section_options_callback() {
721
-
722
- }
723
-
724
- /**
725
- * Validate/sanitize options input
726
- */
727
- public function wpmenucart_options_validate( $input ) {
728
- // Create our array for storing the validated options.
729
- $output = array();
730
-
731
- // Loop through each of the incoming options.
732
- foreach ( $input as $key => $value ) {
733
-
734
- // Check to see if the current option has a value. If so, process it.
735
- if ( isset( $input[$key] ) ) {
736
- // Strip all HTML and PHP tags and properly handle quoted strings.
737
- if ( is_array( $input[$key] ) ) {
738
- foreach ( $input[$key] as $sub_key => $sub_value ) {
739
- $output[$key][$sub_key] = strip_tags( stripslashes( $input[$key][$sub_key] ) );
740
- }
741
-
742
- } else {
743
- $output[$key] = strip_tags( stripslashes( $input[$key] ) );
744
- }
745
- }
746
- }
747
-
748
- // Return the array processing any additional functions filtered by this action.
749
- return apply_filters( 'wpmenucart_validate_input', $output, $input );
750
- }
751
-
752
- public function wpmenucart_add_meta_box() {
753
- add_meta_box(
754
- 'wpmenucart-meta-box',
755
- __('Menu Cart'),
756
- array( &$this, 'wpmenucart_menu_item_meta_box' ),
757
- 'nav-menus',
758
- 'side',
759
- 'default'
760
- );
761
- }
762
-
763
- public function wpmenucart_menu_item_meta_box() {
764
- global $_nav_menu_placeholder, $nav_menu_selected_id;
765
- $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
766
-
767
- ?>
768
- <p>
769
- <input value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" type="text" />
770
- <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" value="" />
771
- <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" title="<?php esc_attr_e('Menu Item'); ?>" />
772
- </p>
773
-
774
- <p class="wpmenucart-meta-box" id="wpmenucart-meta-box">
775
- <span class="add-to-menu">
776
- <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="menucart-menu-item" id="menucart-menu-item" />
777
- <span class="spinner"></span>
778
- </span>
779
- </p>
780
- <?php
781
- }
782
-
783
-
784
  }
1
+ <?php
2
+ class WpMenuCart_Settings {
3
+
4
+ public function __construct() {
5
+ add_action( 'admin_init', array( &$this, 'init_settings' ) ); // Registers settings
6
+ add_action( 'admin_menu', array( &$this, 'wpmenucart_add_page' ) );
7
+ add_filter( 'plugin_action_links_'.WpMenuCart::$plugin_basename, array( &$this, 'wpmenucart_add_settings_link' ) );
8
+
9
+ //Menu admin, not using for now (very complex ajax structure...)
10
+ //add_action( 'admin_init', array( &$this, 'wpmenucart_add_meta_box' ) );
11
+ }
12
+ /**
13
+ * User settings.
14
+ */
15
+ public function init_settings() {
16
+ $option = 'wpmenucart';
17
+
18
+ // Create option in wp_options.
19
+ if ( false == get_option( $option ) ) {
20
+ add_option( $option );
21
+ }
22
+
23
+ // Section.
24
+ add_settings_section(
25
+ 'plugin_settings',
26
+ __( 'Plugin settings', 'wp-menu-cart' ),
27
+ array( &$this, 'section_options_callback' ),
28
+ $option
29
+ );
30
+
31
+ add_settings_field(
32
+ 'shop_plugin',
33
+ __( 'Select which e-commerce plugin you would like Menu Cart to work with', 'wp-menu-cart' ),
34
+ array( &$this, 'select_element_callback' ),
35
+ $option,
36
+ 'plugin_settings',
37
+ array(
38
+ 'menu' => $option,
39
+ 'id' => 'shop_plugin',
40
+ 'options' => (array) $this->get_shop_plugins(),
41
+ )
42
+ );
43
+
44
+ if( $parent_theme = wp_get_theme(get_template()) ) {
45
+ if (in_array($parent_theme->get('Name'), array('Storefront','Divi'))) {
46
+ add_settings_field(
47
+ 'hide_theme_cart',
48
+ __( 'Hide theme shopping cart icon', 'wp-menu-cart' ),
49
+ array( &$this, 'checkbox_element_callback' ),
50
+ $option,
51
+ 'plugin_settings',
52
+ array(
53
+ 'menu' => $option,
54
+ 'id' => 'hide_theme_cart',
55
+ )
56
+ );
57
+ }
58
+ }
59
+
60
+ add_settings_field(
61
+ 'menu_slugs',
62
+ __( 'Select the menu(s) in which you want to display the Menu Cart', 'wp-menu-cart' ),
63
+ array( &$this, 'menus_select_element_callback' ),
64
+ $option,
65
+ 'plugin_settings',
66
+ array(
67
+ 'menu' => $option,
68
+ 'id' => 'menu_slugs',
69
+ 'options' => (array) $this->get_menu_array(),
70
+ )
71
+ );
72
+
73
+ add_settings_field(
74
+ 'always_display',
75
+ __( "Always display cart, even if it's empty", 'wp-menu-cart' ),
76
+ array( &$this, 'checkbox_element_callback' ),
77
+ $option,
78
+ 'plugin_settings',
79
+ array(
80
+ 'menu' => $option,
81
+ 'id' => 'always_display',
82
+ )
83
+ );
84
+
85
+ add_settings_field(
86
+ 'icon_display',
87
+ __( 'Display shopping cart icon.', 'wp-menu-cart' ),
88
+ array( &$this, 'checkbox_element_callback' ),
89
+ $option,
90
+ 'plugin_settings',
91
+ array(
92
+ 'menu' => $option,
93
+ 'id' => 'icon_display',
94
+ )
95
+ );
96
+
97
+ add_settings_field(
98
+ 'flyout_display',
99
+ __( 'Display cart contents in menu fly-out.', 'wp-menu-cart' ),
100
+ array( &$this, 'checkbox_element_callback' ),
101
+ $option,
102
+ 'plugin_settings',
103
+ array(
104
+ 'menu' => $option,
105
+ 'id' => 'flyout_display',
106
+ 'disabled' => true,
107
+ )
108
+ );
109
+
110
+ add_settings_field(
111
+ 'flyout_itemnumber',
112
+ __( 'Set maximum number of products to display in fly-out', 'wp-menu-cart' ),
113
+ array( &$this, 'select_element_callback' ),
114
+ $option,
115
+ 'plugin_settings',
116
+ array(
117
+ 'menu' => $option,
118
+ 'id' => 'flyout_itemnumber',
119
+ 'options' => array(
120
+ '0' => '0',
121
+ '1' => '1',
122
+ '2' => '2',
123
+ '3' => '3',
124
+ '4' => '4',
125
+ '5' => '5',
126
+ '6' => '6',
127
+ '7' => '7',
128
+ '8' => '8',
129
+ '9' => '9',
130
+ '10' => '10',
131
+ ),
132
+ 'disabled' => true,
133
+ )
134
+ );
135
+
136
+ add_settings_field(
137
+ 'cart_icon',
138
+ __( 'Choose a cart icon.', 'wp-menu-cart' ),
139
+ array( &$this, 'icons_radio_element_callback' ),
140
+ $option,
141
+ 'plugin_settings',
142
+ array(
143
+ 'menu' => $option,
144
+ 'id' => 'cart_icon',
145
+ 'options' => array(
146
+ '0' => '0',
147
+ '1' => '1',
148
+ '2' => '2',
149
+ '3' => '3',
150
+ '4' => '4',
151
+ '5' => '5',
152
+ '6' => '6',
153
+ '7' => '7',
154
+ '8' => '8',
155
+ '9' => '9',
156
+ '10' => '10',
157
+ '11' => '11',
158
+ '12' => '12',
159
+ '13' => '13',
160
+ ),
161
+ )
162
+ );
163
+
164
+
165
+ add_settings_field(
166
+ 'items_display',
167
+ __( 'What would you like to display in the menu?', 'wp-menu-cart' ),
168
+ array( &$this, 'radio_element_callback' ),
169
+ $option,
170
+ 'plugin_settings',
171
+ array(
172
+ 'menu' => $option,
173
+ 'id' => 'items_display',
174
+ 'options' => array(
175
+ '1' => __( 'Items Only.' , 'wp-menu-cart' ),
176
+ '2' => __( 'Price Only.' , 'wp-menu-cart' ),
177
+ '3' => __( 'Both price and items.' , 'wp-menu-cart' ),
178
+ ),
179
+ )
180
+ );
181
+
182
+ add_settings_field(
183
+ 'items_alignment',
184
+ __( 'Select the alignment that looks best with your menu.', 'wp-menu-cart' ),
185
+ array( &$this, 'radio_element_callback' ),
186
+ $option,
187
+ 'plugin_settings',
188
+ array(
189
+ 'menu' => $option,
190
+ 'id' => 'items_alignment',
191
+ 'options' => array(
192
+ 'left' => __( 'Align Left.' , 'wp-menu-cart' ),
193
+ 'right' => __( 'Align Right.' , 'wp-menu-cart' ),
194
+ 'standard' => __( 'Default Menu Alignment.' , 'wp-menu-cart' ),
195
+ ),
196
+ )
197
+ );
198
+
199
+ if ( class_exists( 'WooCommerce' ) ) {
200
+ add_settings_field(
201
+ 'total_price_type',
202
+ __( 'Price to display', 'wp-menu-cart' ),
203
+ array( &$this, 'select_element_callback' ),
204
+ $option,
205
+ 'plugin_settings',
206
+ array(
207
+ 'menu' => $option,
208
+ 'id' => 'total_price_type',
209
+ 'options' => array(
210
+ 'total' => __( 'Cart total (including discounts)' , 'wp-menu-cart' ),
211
+ 'subtotal' => __( 'Subtotal (total of products)' , 'wp-menu-cart' ),
212
+ ),
213
+ 'default' => 'total',
214
+ )
215
+ );
216
+ }
217
+
218
+ add_settings_field(
219
+ 'custom_class',
220
+ __( 'Enter a custom CSS class (optional)', 'wp-menu-cart' ),
221
+ array( &$this, 'text_element_callback' ),
222
+ $option,
223
+ 'plugin_settings',
224
+ array(
225
+ 'menu' => $option,
226
+ 'id' => 'custom_class',
227
+ 'disabled' => true,
228
+ )
229
+ );
230
+
231
+ if ( function_exists( 'icl_register_string' ) ) {
232
+ add_settings_field(
233
+ 'wpml_string_translation',
234
+ __( "Use WPML String Translation", 'wp-menu-cart' ),
235
+ array( &$this, 'checkbox_element_callback' ),
236
+ $option,
237
+ 'plugin_settings',
238
+ array(
239
+ 'menu' => $option,
240
+ 'id' => 'wpml_string_translation',
241
+ )
242
+ );
243
+ }
244
+
245
+ if ( class_exists( 'WooCommerce' ) || defined('JIGOSHOP_VERSION') || class_exists( 'Easy_Digital_Downloads' ) ) {
246
+ add_settings_field(
247
+ 'builtin_ajax',
248
+ __( 'Use custom AJAX', 'wp-menu-cart' ),
249
+ array( &$this, 'checkbox_element_callback' ),
250
+ $option,
251
+ 'plugin_settings',
252
+ array(
253
+ 'menu' => $option,
254
+ 'id' => 'builtin_ajax',
255
+ 'description' => __( 'Enable this option to use the custom AJAX / live update functions instead of the default ones from your shop plugin. Only use when you have issues with AJAX!', 'wp-menu-cart' ),
256
+ )
257
+ );
258
+ }
259
+
260
+ // Register settings.
261
+ register_setting( $option, $option, array( &$this, 'wpmenucart_options_validate' ) );
262
+
263
+ // Register defaults if settings empty (might not work in case there's only checkboxes and they're all disabled)
264
+ $option_values = get_option($option);
265
+ if ( empty( $option_values ) )
266
+ $this->default_settings();
267
+
268
+ // Convert old wpmenucart menu settings to array
269
+ if ( isset($option_values['menu_name_1']) ) {
270
+ $option_values['menu_slugs'] = array( '1' => $option_values['menu_name_1'] );
271
+ update_option( 'wpmenucart', $option_values );
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Add menu page
277
+ */
278
+ public function wpmenucart_add_page() {
279
+ if (class_exists('WooCommerce')) {
280
+ $parent_slug = 'woocommerce';
281
+ } else {
282
+ $parent_slug = 'options-general.php';
283
+ }
284
+
285
+ $wpmenucart_page = add_submenu_page(
286
+ $parent_slug,
287
+ __( 'Menu Cart', 'wp-menu-cart' ),
288
+ __( 'Menu Cart Setup', 'wp-menu-cart' ),
289
+ 'manage_options',
290
+ 'wpmenucart_options_page',
291
+ array( $this, 'wpmenucart_options_do_page' )
292
+ );
293
+ add_action( 'admin_print_styles-' . $wpmenucart_page, array( &$this, 'wpmenucart_admin_styles' ) );
294
+ }
295
+
296
+ /**
297
+ * Add settings link to plugins page
298
+ */
299
+ public function wpmenucart_add_settings_link( $links ) {
300
+ $settings_link = '<a href="admin.php?page=wpmenucart_options_page">'. __( 'Settings', 'woocommerce' ) . '</a>';
301
+ array_push( $links, $settings_link );
302
+ return $links;
303
+ }
304
+
305
+ /**
306
+ * Styles for settings page
307
+ */
308
+ public function wpmenucart_admin_styles() {
309
+ wp_register_style( 'wpmenucart-admin', plugins_url( 'css/wpmenucart-icons.css', dirname(__FILE__) ), array(), '', 'all' );
310
+ wp_enqueue_style( 'wpmenucart-admin' );
311
+ wp_register_style( 'wpmenucart-fontawesome', plugins_url( '/css/wpmenucart-fontawesome.css', dirname(__FILE__) ), array(), '', 'all' );
312
+ wp_enqueue_style( 'wpmenucart-fontawesome' );
313
+ }
314
+
315
+ /**
316
+ * Default settings.
317
+ */
318
+ public function default_settings() {
319
+ $wcmenucart_options = get_option('wcmenucart');
320
+ $menu_slugs = array( '1' => isset($wcmenucart_options['menu_name_1']) ? $wcmenucart_options['menu_name_1']:'0' );
321
+
322
+ $active_shop_plugins = WpMenuCart::get_active_shops();
323
+
324
+ //switch keys & values, then strip plugin path to folder
325
+ foreach ($active_shop_plugins as $key => $value) {
326
+ $filtered_active_shop_plugins[] = dirname($value);
327
+ }
328
+
329
+ $first_active_shop_plugin = isset($filtered_active_shop_plugins[0])?$filtered_active_shop_plugins[0]:'';
330
+ $default = array(
331
+ 'menu_slugs' => $menu_slugs,
332
+ 'always_display' => isset($wcmenucart_options['always_display']) ? $wcmenucart_options['always_display']:'',
333
+ 'icon_display' => isset($wcmenucart_options['icon_display']) ? $wcmenucart_options['icon_display']:'1',
334
+ 'items_display' => isset($wcmenucart_options['items_display']) ? $wcmenucart_options['items_display']:'3',
335
+ 'items_alignment' => isset($wcmenucart_options['items_alignment']) ? $wcmenucart_options['items_alignment']:'standard',
336
+ 'custom_class' => '',
337
+ 'flyout_display' => '',
338
+ 'flyout_itemnumber' => '5',
339
+ 'cart_icon' => '0',
340
+ 'shop_plugin' => $first_active_shop_plugin,
341
+ 'builtin_ajax' => '',
342
+ 'hide_theme_cart' => 1,
343
+ );
344
+
345
+ update_option( 'wpmenucart', $default );
346
+ }
347
+
348
+ /**
349
+ * Build the options page.
350
+ */
351
+ public function wpmenucart_options_do_page() {
352
+ ?>
353
+
354
+ <div class="wrap">
355
+ <div class="icon32" id="icon-options-general"><br /></div>
356
+ <h2><?php _e('WP Menu Cart', 'wp-menu-cart' ) ?></h2>
357
+ <?php
358
+ // print_r(get_option('wpmenucart')); //for debugging
359
+ //print_r($this->get_shop_plugins());
360
+ //print_r(apply_filters( 'active_plugins', get_option( 'active_plugins' )));
361
+ if (!$this->get_menu_array()) {
362
+ ?>
363
+ <div class="error" style="width:400px; padding:10px;">
364
+ You need to create a menu before you can use Menu Cart. Go to <strong>Appearence > Menus</strong> and create menu to add the cart to.
365
+ </div>
366
+ <?php } ?>
367
+ <form method="post" action="options.php">
368
+ <?php
369
+
370
+ settings_fields( 'wpmenucart' );
371
+ do_settings_sections( 'wpmenucart' );
372
+
373
+ submit_button();
374
+ ?>
375
+
376
+ </form>
377
+ <script type="text/javascript">
378
+ jQuery('.hidden-input').click(function() {
379
+ jQuery(this).closest('.hidden-input').prev('.pro-feature').show('slow');
380
+ jQuery(this).closest('.hidden-input').hide();
381
+ });
382
+ jQuery('.hidden-input-icon').click(function() {
383
+ jQuery('.pro-icon').show('slow');
384
+ });
385
+ </script>
386
+ <style type="text/css">
387
+ .menucart-pro-ad {
388
+ border: 1px solid #3D5C99;
389
+ background-color: #EBF5FF;
390
+ border-radius: 5px;
391
+ padding: 15px;
392
+ }
393
+ .menucart-pro-ad-big {
394
+ margin-top: 15px;
395
+ min-height: 90px;
396
+ position: relative;
397
+ padding-left: 100px;
398
+ }
399
+ .menucart-pro-ad-small {
400
+ position: absolute;
401
+ right: 20px;
402
+ top: 20px;
403
+ }
404
+ img.wpo-helper {
405
+ position: absolute;
406
+ top: -20px;
407
+ left: 3px;
408
+ }
409
+ </style>
410
+ <div class="menucart-pro-ad menucart-pro-ad-small">
411
+ Want To Stand Out? <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartgopro">Go Pro.</a>
412
+ <ul style="font-size: 12px;list-style-type:circle;margin-left: 20px">
413
+ <li><?php _e('Unlimited Menus', 'wp-menu-cart' ) ?></li>
414
+ <li><?php _e('Choice of 14 icons', 'wp-menu-cart' ) ?></li>
415
+ <li><?php _e('Packed with customization options', 'wp-menu-cart' ) ?></li>
416
+ <li><?php _e('Access to Shortcode', 'wp-menu-cart' ) ?></li>
417
+ <li><?php _e('Top Notch Support', 'wp-menu-cart' ) ?></li>
418
+ </ul>
419
+ </div>
420
+ <div class="menucart-pro-ad menucart-pro-ad-big">
421
+ <img src="<?php echo plugins_url( 'images/', dirname(__FILE__) ) . 'wpo-helper.png'; ?>" class="wpo-helper">
422
+ <h2><?php _e('Sell In Style With Menu Cart Pro!', 'wp-menu-cart' ) ?></h2>
423
+ <br>
424
+ <?php _e('Go Pro with Menu Cart Pro. Includes all the great standard features found in this free version plus:', 'wp-menu-cart' ) ?>
425
+ <br>
426
+ <ul style="list-style-type:circle;margin-left: 40px">
427
+ <li><?php _e('A choice of over 10 cart icons', 'wp-menu-cart' ) ?></li>
428
+ <li><?php _e('A fully featured cart details flyout', 'wp-menu-cart' ) ?></li>
429
+ <li><?php _e('Ability to add cart + flyout to an <strong>unlimited</strong> amount of menus', 'wp-menu-cart' ) ?></li>
430
+ <li><?php _e('Adjust the content & URLs via the settings', 'wp-menu-cart' ) ?></li>
431
+ <li><?php _e('Enter custom styles and apply custom classes via the settings', 'wp-menu-cart' ) ?></li>
432
+ <li><?php _e('WPML compatible', 'wp-menu-cart' ) ?></li>
433
+ <li><?php _e('Automatic updates on any great new features', 'wp-menu-cart' ) ?></li>
434
+ <li><?php _e('Put the cart anywhere with the [wpmenucart] shortcode', 'wp-menu-cart' ) ?></li>
435
+ </ul>
436
+ <?php
437
+ $menucartadmore = '<a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartadmore">';
438
+ printf (__('Need to see more? %sClick here%s to check it out. Add a product to your cart and watch what happens!', 'wp-menu-cart' ), $menucartadmore,'</a>'); ?><br><br>
439
+ <a class="button button-primary" style="text-align: center;margin: 0px auto" href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartadbuy"><?php _e('Buy Now', 'wp-menu-cart' ) ?></a>
440
+ </div>
441
+ </div>
442
+ <?php
443
+ }
444
+
445
+ /**
446
+ * Get menu array.
447
+ *
448
+ * @return array menu slug => menu name
449
+ */
450
+ public function get_menu_array() {
451
+ $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
452
+ $menu_list = array();
453
+
454
+ foreach ( $menus as $menu ) {
455
+ $menu_list[$menu->slug] = $menu->name;
456
+ }
457
+
458
+ if (!empty($menu_list)) return $menu_list;
459
+ }
460
+
461
+ /**
462
+ * Get array of active shop plugins
463
+ *
464
+ * @return array plugin slug => plugin name
465
+ */
466
+ public function get_shop_plugins() {
467
+ $active_shop_plugins = WpMenuCart::get_active_shops();
468
+
469
+ //switch keys & values, then strip plugin path to folder
470
+ foreach ($active_shop_plugins as $key => $value) {
471
+ $filtered_active_shop_plugins[dirname($value)] = $key;
472
+ }
473
+
474
+ $active_shop_plugins = isset($filtered_active_shop_plugins) ? $filtered_active_shop_plugins:'';
475
+
476
+ return $active_shop_plugins;
477
+ }
478
+
479
+ /**
480
+ * Text field callback.
481
+ *
482
+ * @param array $args Field arguments.
483
+ *
484
+ * @return string Text field.
485
+ */
486
+ public function text_element_callback( $args ) {
487
+ $menu = $args['menu'];
488
+ $id = $args['id'];
489
+ $size = isset( $args['size'] ) ? $args['size'] : '25';
490
+
491
+ $options = get_option( $menu );
492
+
493
+ if ( isset( $options[$id] ) ) {
494
+ $current = $options[$id];
495
+ } else {
496
+ $current = isset( $args['default'] ) ? $args['default'] : '';
497
+ }
498
+
499
+ $disabled = (isset( $args['disabled'] )) ? ' disabled' : '';
500
+ $html = sprintf( '<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" size="%4$s"%5$s/>', $id, $menu, $current, $size, $disabled );
501
+
502
+ // Displays option description.
503
+ if ( isset( $args['description'] ) ) {
504
+ $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
505
+ }
506
+
507
+ if (isset( $args['disabled'] )) {
508
+ $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartcustomclass">Menu Cart Pro</a></i></span>';
509
+ $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
510
+ $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
511
+ }
512
+
513
+ echo $html;
514
+ }
515
+
516
+ /**
517
+ * Displays a selectbox for a settings field
518
+ *
519
+ * @param array $args settings field args
520
+ */
521
+ public function select_element_callback( $args ) {
522
+ $menu = $args['menu'];
523
+ $id = $args['id'];
524
+
525
+ $options = get_option( $menu );
526
+
527
+ if ( isset( $options[$id] ) ) {
528
+ $current = $options[$id];
529
+ } else {
530
+ $current = isset( $args['default'] ) ? $args['default'] : '';
531
+ }
532
+
533
+ $disabled = (isset( $args['disabled'] )) ? ' disabled' : '';
534
+
535
+ $html = sprintf( '<select name="%1$s[%2$s]" id="%1$s[%2$s]"%3$s>', $menu, $id, $disabled );
536
+ $html .= sprintf( '<option value="%s"%s>%s</option>', '0', selected( $current, '0', false ), '' );
537
+
538
+ foreach ( $args['options'] as $key => $label ) {
539
+ $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label );
540
+ }
541
+ $html .= sprintf( '</select>' );
542
+
543
+ if ( isset( $args['description'] ) ) {
544
+ $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
545
+ }
546
+
547
+ if (isset( $args['disabled'] )) {
548
+ $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartflyout">Menu Cart Pro</a></i></span>';
549
+ $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
550
+ $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
551
+ }
552
+
553
+ echo $html;
554
+ }
555
+
556
+ /**
557
+ * Displays a multiple selectbox for a settings field
558
+ *
559
+ * @param array $args settings field args
560
+ */
561
+ public function menus_select_element_callback( $args ) {
562
+ $menu = $args['menu'];
563
+ $id = $args['id'];
564
+
565
+ $options = get_option( $menu );
566
+ $menus = $options['menu_slugs'];
567
+
568
+ for ( $x = 1; $x <= 3; $x++ ) {
569
+ $html = '';
570
+ if ( isset( $options[$id][$x] ) ) {
571
+ $current = $options[$id][$x];
572
+ } else {
573
+ $current = isset( $args['default'] ) ? $args['default'] : '';
574
+ }
575
+
576
+ $disabled = ($x == 1) ? '' : ' disabled';
577
+
578
+ $html .= sprintf( '<select name="%1$s[%2$s][%3$s]" id="%1$s[%2$s][%3$s]"%4$s>', $menu, $id, $x, $disabled);
579
+ $html .= sprintf( '<option value="%s"%s>%s</option>', '0', selected( $current, '0', false ), '' );
580
+
581
+ foreach ( (array) $args['options'] as $key => $label ) {
582
+ $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $current, $key, false ), $label );
583
+ }
584
+ $html .= '</select>';
585
+
586
+ if ( isset( $args['description'] ) ) {
587
+ $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
588
+ }
589
+ if ( $x > 1 ) {
590
+ $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartmultiplemenus">Menu Cart Pro</a></i></span>';
591
+ $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
592
+ $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
593
+ }
594
+
595
+ $html .= '<br />';
596
+ echo $html;
597
+ }
598
+
599
+ }
600
+
601
+ /**
602
+ * Checkbox field callback.
603
+ *
604
+ * @param array $args Field arguments.
605
+ *
606
+ * @return string Checkbox field.
607
+ */
608
+ public function checkbox_element_callback( $args ) {
609
+ $menu = $args['menu'];
610
+ $id = $args['id'];
611
+
612
+ $options = get_option( $menu );
613
+
614
+ if ( isset( $options[$id] ) ) {
615
+ $current = $options[$id];
616
+ } else {
617
+ $current = isset( $args['default'] ) ? $args['default'] : '';
618
+ }
619
+
620
+ $disabled = (isset( $args['disabled'] )) ? ' disabled' : '';
621
+ $html = sprintf( '<input type="checkbox" id="%1$s" name="%2$s[%1$s]" value="1"%3$s %4$s/>', $id, $menu, checked( 1, $current, false ), $disabled );
622
+
623
+ // Displays option description.
624
+ if ( isset( $args['description'] ) ) {
625
+ $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
626
+ }
627
+
628
+ if (isset( $args['disabled'] )) {
629
+ $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartflyout">Menu Cart Pro</a></i></span>';
630
+ $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
631
+ $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
632
+ }
633
+
634
+ echo $html;
635
+ }
636
+
637
+ /**
638
+ * Displays a multicheckbox a settings field
639
+ *
640
+ * @param array $args settings field args
641
+ */
642
+ public function radio_element_callback( $args ) {
643
+ $menu = $args['menu'];
644
+ $id = $args['id'];
645
+
646
+ $options = get_option( $menu );
647
+
648
+ if ( isset( $options[$id] ) ) {
649
+ $current = $options[$id];
650
+ } else {
651
+ $current = isset( $args['default'] ) ? $args['default'] : '';
652
+ }
653
+
654
+ $html = '';
655
+ foreach ( $args['options'] as $key => $label ) {
656
+ $html .= sprintf( '<input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s"%4$s />', $menu, $id, $key, checked( $current, $key, false ) );
657
+ $html .= sprintf( '<label for="%1$s[%2$s][%3$s]"> %4$s</label><br>', $menu, $id, $key, $label);
658
+ }
659
+
660
+ // Displays option description.
661
+ if ( isset( $args['description'] ) ) {
662
+ $html .= sprintf( '<p class="description">%s</p>', $args['description'] );
663
+ }
664
+
665
+ if (isset( $args['disabled'] )) {
666
+ $html .= ' <span style="display:none;" class="pro-feature"><i>'. __('This feature only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucartflyout">Menu Cart Pro</a></i></span>';
667
+ $html .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input"></div>';
668
+ $html = '<div style="display:inline-block; position:relative;">'.$html.'</div>';
669
+ }
670
+
671
+ echo $html;
672
+ }
673
+
674
+ /**
675
+ * Displays a multicheckbox a settings field
676
+ *
677
+ * @param array $args settings field args
678
+ */
679
+ public function icons_radio_element_callback( $args ) {
680
+ $menu = $args['menu'];
681
+ $id = $args['id'];
682
+
683
+ $options = get_option( $menu );
684
+
685
+ if ( isset( $options[$id] ) ) {
686
+ $current = $options[$id];
687
+ } else {
688
+ $current = isset( $args['default'] ) ? $args['default'] : '';
689
+ }
690
+
691
+ $icons = '';
692
+ $radios = '';
693
+
694
+ foreach ( $args['options'] as $key => $iconnumber ) {
695
+ if ($key == 0) {
696
+ $icons .= sprintf( '<td style="padding-bottom:0;font-size:16pt;" align="center"><label for="%1$s[%2$s][%3$s]"><i class="wpmenucart-icon-shopping-cart-%4$s"></i></label></td>', $menu, $id, $key, $iconnumber);
697
+ $radios .= sprintf( '<td style="padding-top:0" align="center"><input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s"%4$s /></td>', $menu, $id, $key, checked( $current, $key, false ) );
698
+ } else {
699
+ $icons .= sprintf( '<td style="padding-bottom:0;font-size:16pt;" align="center"><label for="%1$s[%2$s][%3$s]"><img src="%4$scart-icon-%5$s.png" /></label></td>', $menu, $id, $key, plugins_url( 'images/', dirname(__FILE__) ), $iconnumber);
700
+ $radio = sprintf( '<input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" disabled />', $menu, $id, $key);
701
+ $radio .= '<div style="position:absolute; left:0; right:0; top:0; bottom:0; background-color:white; -moz-opacity: 0; opacity:0;filter: alpha(opacity=0);" class="hidden-input-icon"></div>';
702
+ $radio = '<div style="display:inline-block; position:relative;">'.$radio.'</div>';
703
+
704
+ $radios .= '<td style="padding-top:0" align="center">'.$radio.'</td>';
705
+ }
706
+ }
707
+
708
+ $profeature = '<span style="display:none;" class="pro-icon"><i>'. __('Additional icons are only available in', 'wp-menu-cart' ) .' <a href="https://wpovernight.com/downloads/menu-cart-pro?utm_source=wordpress&utm_medium=menucartfree&utm_campaign=menucarticons">Menu Cart Pro</a></i></span>';
709
+
710
+ $html = '<table><tr>'.$icons.'</tr><tr>'.$radios.'</tr></table>'.$profeature;
711
+
712
+ echo $html;
713
+ }
714
+
715
+ /**
716
+ * Section null callback.
717
+ *
718
+ * @return void.
719
+ */
720
+ public function section_options_callback() {
721
+
722
+ }
723
+
724
+ /**
725
+ * Validate/sanitize options input
726
+ */
727
+ public function wpmenucart_options_validate( $input ) {
728
+ // Create our array for storing the validated options.
729
+ $output = array();
730
+
731
+ // Loop through each of the incoming options.
732
+ foreach ( $input as $key => $value ) {
733
+
734
+ // Check to see if the current option has a value. If so, process it.
735
+ if ( isset( $input[$key] ) ) {
736
+ // Strip all HTML and PHP tags and properly handle quoted strings.
737
+ if ( is_array( $input[$key] ) ) {
738
+ foreach ( $input[$key] as $sub_key => $sub_value ) {
739
+ $output[$key][$sub_key] = strip_tags( stripslashes( $input[$key][$sub_key] ) );
740
+ }
741
+
742
+ } else {
743
+ $output[$key] = strip_tags( stripslashes( $input[$key] ) );
744
+ }
745
+ }
746
+ }
747
+
748
+ // Return the array processing any additional functions filtered by this action.
749
+ return apply_filters( 'wpmenucart_validate_input', $output, $input );
750
+ }
751
+
752
+ public function wpmenucart_add_meta_box() {
753
+ add_meta_box(
754
+ 'wpmenucart-meta-box',
755
+ __('Menu Cart'),
756
+ array( &$this, 'wpmenucart_menu_item_meta_box' ),
757
+ 'nav-menus',
758
+ 'side',
759
+ 'default'
760
+ );
761
+ }
762
+
763
+ public function wpmenucart_menu_item_meta_box() {
764
+ global $_nav_menu_placeholder, $nav_menu_selected_id;
765
+ $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
766
+
767
+ ?>
768
+ <p>
769
+ <input value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" type="text" />
770
+ <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" value="" />
771
+ <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" title="<?php esc_attr_e('Menu Item'); ?>" />
772
+ </p>
773
+
774
+ <p class="wpmenucart-meta-box" id="wpmenucart-meta-box">
775
+ <span class="add-to-menu">
776
+ <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="menucart-menu-item" id="menucart-menu-item" />
777
+ <span class="spinner"></span>
778
+ </span>
779
+ </p>
780
+ <?php
781
+ }
782
+
783
+
784
  }
javascript/wpmenucart-ajax-assist.js CHANGED
@@ -1,27 +1,27 @@
1
- /* This script is intended for sites with server side caching enabled - normally the classes in the menu would follow the cart state */
2
- jQuery( function( $ ) {
3
- /* Cart Hiding */
4
- if ( typeof wpmenucart_ajax_assist.shop_plugin !== 'undefined' && wpmenucart_ajax_assist.shop_plugin.toLowerCase() == 'woocommerce' ) {
5
- // update on page load
6
- wpmenucart_update_menu_classes();
7
- // update when cart is updated
8
- $( document.body ).on( 'adding_to_cart updated_wc_div', wpmenucart_update_menu_classes );
9
- }
10
-
11
- function wpmenucart_update_menu_classes() {
12
- if ( typeof window.Cookies !== 'undefined' ) { // WC3.0
13
- items_in_cart = Cookies.get( 'woocommerce_items_in_cart' );
14
- } else if ( typeof $.cookie !== 'undefined' && $.isFunction($.cookie) ){ // WC2.X
15
- items_in_cart = $.cookie( 'woocommerce_items_in_cart' );
16
- } else {
17
- return; // no business here
18
- }
19
-
20
- if ( items_in_cart > 0 ) {
21
- $('.empty-wpmenucart').removeClass('empty-wpmenucart');
22
- } else if ( !(wpmenucart_ajax_assist.always_display) ) {
23
- $('.wpmenucartli').addClass('empty-wpmenucart');
24
- $('.wpmenucart-shortcode').addClass('empty-wpmenucart');
25
- }
26
- }
27
  });
1
+ /* This script is intended for sites with server side caching enabled - normally the classes in the menu would follow the cart state */
2
+ jQuery( function( $ ) {
3
+ /* Cart Hiding */
4
+ if ( typeof wpmenucart_ajax_assist.shop_plugin !== 'undefined' && wpmenucart_ajax_assist.shop_plugin.toLowerCase() == 'woocommerce' ) {
5
+ // update on page load
6
+ wpmenucart_update_menu_classes();
7
+ // update when cart is updated
8
+ $( document.body ).on( 'adding_to_cart added_to_cart updated_wc_div', wpmenucart_update_menu_classes );
9
+ }
10
+
11
+ function wpmenucart_update_menu_classes() {
12
+ if ( typeof window.Cookies !== 'undefined' ) { // WC3.0
13
+ items_in_cart = Cookies.get( 'woocommerce_items_in_cart' );
14
+ } else if ( typeof $.cookie !== 'undefined' && $.isFunction($.cookie) ){ // WC2.X
15
+ items_in_cart = $.cookie( 'woocommerce_items_in_cart' );
16
+ } else {
17
+ return; // no business here
18
+ }
19
+
20
+ if ( items_in_cart > 0 ) {
21
+ $('.empty-wpmenucart').removeClass('empty-wpmenucart');
22
+ } else if ( !(wpmenucart_ajax_assist.always_display) ) {
23
+ $('.wpmenucartli').addClass('empty-wpmenucart');
24
+ $('.wpmenucart-shortcode').addClass('empty-wpmenucart');
25
+ }
26
+ }
27
  });
readme.txt CHANGED
@@ -1,278 +1,283 @@
1
- === WooCommerce Menu Cart ===
2
- Contributors: jprummer, pomegranate
3
- Donate link: https://www.wpovernight.com/
4
- Tags: woocommerce, menu, bar, cart, basket, header, shopping cart, navigation, edd, ecommerce, eshop, wp-ecommerce, jigoshop, wpec
5
- Requires at least: 3.4
6
- Tested up to: 4.9
7
- Requires PHP: 5.3
8
- Stable tag: 2.7.0
9
-
10
- Automatically displays a shopping cart in your menu bar. Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop
11
-
12
- == Description ==
13
-
14
- **Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop**
15
-
16
- This plugin installs a shopping cart button in the navigation bar. The plugin takes less than a minute to setup,
17
- and includes the following options:
18
-
19
- * Display cart icon, or only items/prices.
20
- * Display items only, price only, or both.
21
- * Display always, or only when there are items in the cart.
22
- * Float left, float right, or use your menu's default settings.
23
- * Customize your own CSS
24
-
25
- Pro Version Includes:
26
-
27
- * A choice of over 10 cart icons
28
- * A fully featured cart details flyout
29
- * Ability to add cart + flyout for unlimited menus
30
- * Ability to add a custom css class
31
- * Automatic updates on any great new features
32
- * Shortcode to display cart *anywhere* on your site
33
- * Quick and thorough support
34
-
35
- **Download the Pro version here - https://wpovernight.com/downloads/menu-cart-pro/**
36
-
37
- Finally, the cart automatically conforms to your site's styles, leaving you with no extra work.
38
-
39
- Compatibility:
40
-
41
- * WooCommerce
42
- * Easy Digital Downloads
43
- * Eshop
44
- * WP-Ecommerce
45
- * Jigoshop
46
-
47
- Translations:
48
-
49
- * Brazilian Portuguese
50
- * Danish
51
- * Dutch
52
- * Croatian
53
- * Czech
54
- * English
55
- * French
56
- * German
57
- * Greek
58
- * Hebrew
59
- * Hungarian
60
- * Italian
61
- * Norwegian
62
- * Persian
63
- * Polish
64
- * Portuguese
65
- * Russian
66
- * Spanish[1]
67
- * Swedish
68
- * Turkish
69
- * Vietnamese
70
-
71
- [1] WebHostingHub
72
- == Installation ==
73
-
74
- Delete any old installations of the plugin. Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
75
-
76
- Once the plugin is activated navigate to Settings > Menu Cart Setup. Select your options, save and you're ready to go. It's that easy!
77
-
78
- == Screenshots ==
79
-
80
- 1. Shows menu before and after Menu Cart.
81
- 2. 3 different display style options to choose from.
82
- 3. Shows settings page.
83
-
84
- == Frequently Asked Questions ==
85
-
86
- == Changelog ==
87
-
88
- = 2.7.0 =
89
-
90
- * Feature: Full integration with wordpress.org language packs (finally!)
91
- * Feature (WooCommerce): Option to display either total (including fees) or subtotal (total of products)
92
- * Feature (EDD): Native integration with EDD AJAX
93
- * Fix: Several improvements & fixes to WooCommerce AJAX integration for sites with server side caching
94
- * Fix: Cart icon on settings page
95
- * Translations: added Turkish
96
-
97
- = 2.6.1 =
98
-
99
- * Feature: Option to hide theme cart from Storefront or Divi
100
- * Feature: Improved WooCommerce AJAX compatibility
101
- * Fix: Updated FontAwesome to 4.7.0
102
- * Tweak: load FontAwesome in separate CSS file to allow dequeueing
103
- * Translations: Updated pt_BR
104
-
105
- = 2.6.0 =
106
-
107
- * WooCommerce 3.0 compatibility
108
- * Translations: updated Swedish
109
-
110
- = 2.5.8 =
111
-
112
- * Translations: Added Croatian, Hebrew, Hungarian (updated) & Vietnamese
113
- * Fix: Built-in AJAX for multiple menus
114
- * Fix: Textdomain definition and allow custom translations
115
- * Tweak: prevent loading cart when WooCommerce not loaded
116
-
117
- = 2.5.7 =
118
-
119
- * Fix: Improved JS in Easy Digital Downloads
120
- * New: Hungarian translation
121
- * Tweak: Use css dash instead of hard-coded dash
122
-
123
- = 2.5.6 =
124
-
125
- * New: Slovak Translation
126
- * New: Option to use built in js
127
- * Tweak: Moved JS to footer
128
- * Tweak: improved css positioning
129
- * Tweak: added js selectors
130
- * Tweak: Brazilian Portuguese Translation
131
-
132
- = 2.5.5 =
133
-
134
- * New: Norwegian Translation
135
-
136
- = 2.5.4 =
137
-
138
- * New: Czech Translations
139
- * New: Greek Translations
140
- * Tweak: Seperated Item Classes
141
- * Tweak: Removed Unnecessary submenu classes
142
- * Tweak: Use get_total() instead of get_cart_total()
143
- * Fix: Prices show tax if cart prices are set to display including tax
144
- * Fix: Updated Font Awesome
145
-
146
- = 2.5.3 =
147
-
148
- * Fix: Ubermenu
149
- * Added: Greek Translation
150
-
151
- = 2.5.2 =
152
-
153
- *Tweak: Merged menu cart versions
154
-
155
- = 2.5.1 =
156
-
157
- * WPML String Translation fix
158
-
159
- = 2.5 =
160
-
161
- * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
162
- * Added: Shop detection for Multisite
163
- * Added: WPML String Translation setting
164
- * Added: Persian translations
165
- * Updated: Font Awesome
166
- * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
167
- * Fix: PHP strict warnings
168
- * Fix: CSS for Twenty Twelve & Twenty Fourteen
169
-
170
- = 2.2.2 =
171
-
172
- * Jigoshop Bug Fix
173
-
174
- = 2.2.1 =
175
-
176
- * WPML bug fixes
177
-
178
- = 2.2.0 =
179
-
180
- * Several bugfixes & improvements
181
- * Better AJAX integration with EDD & eShop
182
- * Various filters added for better theme integration & easier customization
183
- * DOMHtml warnings surpressed
184
-
185
- = 2.1.5 =
186
-
187
- Fix: Edd and WP e-Commerce ajax.
188
-
189
- = 2.1.4 =
190
-
191
- Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
192
-
193
- = 2.1.3 =
194
-
195
- EDD total price bug fixed
196
-
197
- = 2.1.2 =
198
-
199
- Added WP-Ecommerce and EDD
200
-
201
- = 2.1.0 =
202
-
203
- Initial Release
204
-
205
- == Upgrade Notice ==
206
-
207
- = 2.5.5 =
208
-
209
- * New: Norwegian Translation
210
-
211
- = 2.5.4 =
212
-
213
- * New: Czech Translations
214
- * New: Greek Translations
215
- * Tweak: Seperated Item Classes
216
- * Tweak: Removed Unnecessary submenu classes
217
- * Tweak: Use get_total() instead of get_cart_total()
218
- * Fix: Prices show tax if cart prices are set to display including tax
219
- * Fix: Updated Font Awesome
220
-
221
- = 2.5.3 =
222
-
223
- * Fix: Ubermenu
224
- * Added: Greek Translation
225
-
226
- = 2.5.2 =
227
-
228
- *Tweak: Merged menu cart versions
229
-
230
- = 2.5.1 =
231
-
232
- * WPML String Translation fix
233
-
234
- = 2.5 =
235
-
236
- * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
237
- * Added: Shop detection for Multisite
238
- * Added: WPML String Translation setting
239
- * Added: Persian translations
240
- * Updated: Font Awesome
241
- * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
242
- * Fix: PHP strict warnings
243
- * Fix: CSS for Twenty Twelve & Twenty Fourteen
244
-
245
- = 2.2.2 =
246
-
247
- * Jigoshop Bug Fix
248
-
249
- = 2.2.1 =
250
-
251
- * WPML bug fixes
252
-
253
- = 2.2.0 =
254
-
255
- * Several bugfixes & improvements
256
- * Better AJAX integration with EDD & eShop
257
- * Various filters added for better theme integration & easier customization
258
- * DOMHtml warnings surpressed
259
-
260
- = 2.1.5 =
261
-
262
- Fix: Edd and WP e-Commerce ajax.
263
-
264
- = 2.1.4 =
265
-
266
- Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
267
-
268
- = 2.1.3 =
269
-
270
- EDD total price bug fixed
271
-
272
- = 2.1.2 =
273
-
274
- Added WP-Ecommerce and EDD
275
-
276
- = 2.1.0 =
277
-
 
 
 
 
 
278
  Initial Release
1
+ === WooCommerce Menu Cart ===
2
+ Contributors: jprummer, pomegranate
3
+ Donate link: https://www.wpovernight.com/
4
+ Tags: woocommerce, menu, bar, cart, basket, header, shopping cart, navigation, edd, ecommerce, eshop, wp-ecommerce, jigoshop, wpec
5
+ Requires at least: 3.4
6
+ Tested up to: 4.9
7
+ Requires PHP: 5.3
8
+ Stable tag: 2.7.1
9
+
10
+ Automatically displays a shopping cart in your menu bar. Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop
11
+
12
+ == Description ==
13
+
14
+ **Works with WooCommerce, WP-Ecommerce, EDD, Eshop and Jigoshop**
15
+
16
+ This plugin installs a shopping cart button in the navigation bar. The plugin takes less than a minute to setup,
17
+ and includes the following options:
18
+
19
+ * Display cart icon, or only items/prices.
20
+ * Display items only, price only, or both.
21
+ * Display always, or only when there are items in the cart.
22
+ * Float left, float right, or use your menu's default settings.
23
+ * Customize your own CSS
24
+
25
+ Pro Version Includes:
26
+
27
+ * A choice of over 10 cart icons
28
+ * A fully featured cart details flyout
29
+ * Ability to add cart + flyout for unlimited menus
30
+ * Ability to add a custom css class
31
+ * Automatic updates on any great new features
32
+ * Shortcode to display cart *anywhere* on your site
33
+ * Quick and thorough support
34
+
35
+ **Download the Pro version here - https://wpovernight.com/downloads/menu-cart-pro/**
36
+
37
+ Finally, the cart automatically conforms to your site's styles, leaving you with no extra work.
38
+
39
+ Compatibility:
40
+
41
+ * WooCommerce
42
+ * Easy Digital Downloads
43
+ * Eshop
44
+ * WP-Ecommerce
45
+ * Jigoshop
46
+
47
+ Translations:
48
+
49
+ * Brazilian Portuguese
50
+ * Danish
51
+ * Dutch
52
+ * Croatian
53
+ * Czech
54
+ * English
55
+ * French
56
+ * German
57
+ * Greek
58
+ * Hebrew
59
+ * Hungarian
60
+ * Italian
61
+ * Norwegian
62
+ * Persian
63
+ * Polish
64
+ * Portuguese
65
+ * Russian
66
+ * Spanish[1]
67
+ * Swedish
68
+ * Turkish
69
+ * Vietnamese
70
+
71
+ [1] WebHostingHub
72
+ == Installation ==
73
+
74
+ Delete any old installations of the plugin. Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
75
+
76
+ Once the plugin is activated navigate to Settings > Menu Cart Setup. Select your options, save and you're ready to go. It's that easy!
77
+
78
+ == Screenshots ==
79
+
80
+ 1. Shows menu before and after Menu Cart.
81
+ 2. 3 different display style options to choose from.
82
+ 3. Shows settings page.
83
+
84
+ == Frequently Asked Questions ==
85
+
86
+ == Changelog ==
87
+
88
+ = 2.7.1 =
89
+
90
+ * fix label on price to display setting
91
+ * Fix live updating cart for first product with 'Always display cart' setting enabled
92
+
93
+ = 2.7.0 =
94
+
95
+ * Feature: Full integration with wordpress.org language packs (finally!)
96
+ * Feature (WooCommerce): Option to display either total (including fees) or subtotal (total of products)
97
+ * Feature (EDD): Native integration with EDD AJAX
98
+ * Fix: Several improvements & fixes to WooCommerce AJAX integration for sites with server side caching
99
+ * Fix: Cart icon on settings page
100
+ * Translations: added Turkish
101
+
102
+ = 2.6.1 =
103
+
104
+ * Feature: Option to hide theme cart from Storefront or Divi
105
+ * Feature: Improved WooCommerce AJAX compatibility
106
+ * Fix: Updated FontAwesome to 4.7.0
107
+ * Tweak: load FontAwesome in separate CSS file to allow dequeueing
108
+ * Translations: Updated pt_BR
109
+
110
+ = 2.6.0 =
111
+
112
+ * WooCommerce 3.0 compatibility
113
+ * Translations: updated Swedish
114
+
115
+ = 2.5.8 =
116
+
117
+ * Translations: Added Croatian, Hebrew, Hungarian (updated) & Vietnamese
118
+ * Fix: Built-in AJAX for multiple menus
119
+ * Fix: Textdomain definition and allow custom translations
120
+ * Tweak: prevent loading cart when WooCommerce not loaded
121
+
122
+ = 2.5.7 =
123
+
124
+ * Fix: Improved JS in Easy Digital Downloads
125
+ * New: Hungarian translation
126
+ * Tweak: Use css dash instead of hard-coded dash
127
+
128
+ = 2.5.6 =
129
+
130
+ * New: Slovak Translation
131
+ * New: Option to use built in js
132
+ * Tweak: Moved JS to footer
133
+ * Tweak: improved css positioning
134
+ * Tweak: added js selectors
135
+ * Tweak: Brazilian Portuguese Translation
136
+
137
+ = 2.5.5 =
138
+
139
+ * New: Norwegian Translation
140
+
141
+ = 2.5.4 =
142
+
143
+ * New: Czech Translations
144
+ * New: Greek Translations
145
+ * Tweak: Seperated Item Classes
146
+ * Tweak: Removed Unnecessary submenu classes
147
+ * Tweak: Use get_total() instead of get_cart_total()
148
+ * Fix: Prices show tax if cart prices are set to display including tax
149
+ * Fix: Updated Font Awesome
150
+
151
+ = 2.5.3 =
152
+
153
+ * Fix: Ubermenu
154
+ * Added: Greek Translation
155
+
156
+ = 2.5.2 =
157
+
158
+ *Tweak: Merged menu cart versions
159
+
160
+ = 2.5.1 =
161
+
162
+ * WPML String Translation fix
163
+
164
+ = 2.5 =
165
+
166
+ * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
167
+ * Added: Shop detection for Multisite
168
+ * Added: WPML String Translation setting
169
+ * Added: Persian translations
170
+ * Updated: Font Awesome
171
+ * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
172
+ * Fix: PHP strict warnings
173
+ * Fix: CSS for Twenty Twelve & Twenty Fourteen
174
+
175
+ = 2.2.2 =
176
+
177
+ * Jigoshop Bug Fix
178
+
179
+ = 2.2.1 =
180
+
181
+ * WPML bug fixes
182
+
183
+ = 2.2.0 =
184
+
185
+ * Several bugfixes & improvements
186
+ * Better AJAX integration with EDD & eShop
187
+ * Various filters added for better theme integration & easier customization
188
+ * DOMHtml warnings surpressed
189
+
190
+ = 2.1.5 =
191
+
192
+ Fix: Edd and WP e-Commerce ajax.
193
+
194
+ = 2.1.4 =
195
+
196
+ Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
197
+
198
+ = 2.1.3 =
199
+
200
+ EDD total price bug fixed
201
+
202
+ = 2.1.2 =
203
+
204
+ Added WP-Ecommerce and EDD
205
+
206
+ = 2.1.0 =
207
+
208
+ Initial Release
209
+
210
+ == Upgrade Notice ==
211
+
212
+ = 2.5.5 =
213
+
214
+ * New: Norwegian Translation
215
+
216
+ = 2.5.4 =
217
+
218
+ * New: Czech Translations
219
+ * New: Greek Translations
220
+ * Tweak: Seperated Item Classes
221
+ * Tweak: Removed Unnecessary submenu classes
222
+ * Tweak: Use get_total() instead of get_cart_total()
223
+ * Fix: Prices show tax if cart prices are set to display including tax
224
+ * Fix: Updated Font Awesome
225
+
226
+ = 2.5.3 =
227
+
228
+ * Fix: Ubermenu
229
+ * Added: Greek Translation
230
+
231
+ = 2.5.2 =
232
+
233
+ *Tweak: Merged menu cart versions
234
+
235
+ = 2.5.1 =
236
+
237
+ * WPML String Translation fix
238
+
239
+ = 2.5 =
240
+
241
+ * Major Code refactor: CLEANER, FASTER, MORE FLEXIBLE!
242
+ * Added: Shop detection for Multisite
243
+ * Added: WPML String Translation setting
244
+ * Added: Persian translations
245
+ * Updated: Font Awesome
246
+ * Updated: Spanish, Portugese, Brazilian, French & Polish Translations
247
+ * Fix: PHP strict warnings
248
+ * Fix: CSS for Twenty Twelve & Twenty Fourteen
249
+
250
+ = 2.2.2 =
251
+
252
+ * Jigoshop Bug Fix
253
+
254
+ = 2.2.1 =
255
+
256
+ * WPML bug fixes
257
+
258
+ = 2.2.0 =
259
+
260
+ * Several bugfixes & improvements
261
+ * Better AJAX integration with EDD & eShop
262
+ * Various filters added for better theme integration & easier customization
263
+ * DOMHtml warnings surpressed
264
+
265
+ = 2.1.5 =
266
+
267
+ Fix: Edd and WP e-Commerce ajax.
268
+
269
+ = 2.1.4 =
270
+
271
+ Fixed WP e-Commerce ajax conflict and uploaded proper French translation.
272
+
273
+ = 2.1.3 =
274
+
275
+ EDD total price bug fixed
276
+
277
+ = 2.1.2 =
278
+
279
+ Added WP-Ecommerce and EDD
280
+
281
+ = 2.1.0 =
282
+
283
  Initial Release
wp-menu-cart.php CHANGED
@@ -1,586 +1,586 @@
1
- <?php
2
- /**
3
- * Plugin Name: WooCommerce Menu Cart
4
- * Plugin URI: www.wpovernight.com/plugins
5
- * Description: Extension for WooCommerce that places a cart icon with number of items and total cost in the menu bar. Activate the plugin, set your options and you're ready to go! Will automatically conform to your theme styles.
6
- * Version: 2.7.0
7
- * Author: Jeremiah Prummer, Ewout Fernhout
8
- * Author URI: www.wpovernight.com/
9
- * License: GPL2
10
- * Text Domain: wp-menu-cart
11
- * WC requires at least: 2.0.0
12
- * WC tested up to: 3.3.0
13
- */
14
-
15
- class WpMenuCart {
16
-
17
- public static $plugin_slug;
18
- public static $plugin_basename;
19
-
20
- /**
21
- * Construct.
22
- */
23
- public function __construct() {
24
- self::$plugin_slug = basename(dirname(__FILE__));
25
- self::$plugin_basename = plugin_basename(__FILE__);
26
-
27
- $this->options = get_option('wpmenucart');
28
-
29
- // load the localisation & classes
30
- add_action( 'plugins_loaded', array( &$this, 'languages' ), 0 ); // or use init?
31
- add_filter( 'load_textdomain_mofile', array( $this, 'textdomain_fallback' ), 10, 2 );
32
- add_action( 'init', array( &$this, 'wpml' ), 0 );
33
- add_action( 'init', array( $this, 'load_classes' ) );
34
-
35
- // enqueue scripts & ajax
36
- add_action( 'wp_enqueue_scripts', array( &$this, 'load_scripts_styles' ) ); // Load scripts
37
- add_action( 'wp_ajax_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
38
- add_action( 'wp_ajax_nopriv_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
39
-
40
- // add filters to selected menus to add cart item <li>
41
- add_action( 'init', array( $this, 'filter_nav_menus' ) );
42
- // $this->filter_nav_menus();
43
- }
44
-
45
- /**
46
- * Load classes
47
- * @return void
48
- */
49
- public function load_classes() {
50
- include_once( 'includes/wpmenucart-settings.php' );
51
- $this->settings = new WpMenuCart_Settings();
52
-
53
- if ( $this->good_to_go() ) {
54
- if (isset($this->options['shop_plugin'])) {
55
- switch ($this->options['shop_plugin']) {
56
- case 'woocommerce':
57
- include_once( 'includes/wpmenucart-woocommerce.php' );
58
- $this->shop = new WPMenuCart_WooCommerce();
59
- if ( !isset($this->options['builtin_ajax']) ) {
60
- if ( defined('WOOCOMMERCE_VERSION') && version_compare( WOOCOMMERCE_VERSION, '2.7', '>=' ) ) {
61
- add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
62
- } else {
63
- add_filter( 'add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
64
- }
65
- }
66
- break;
67
- case 'jigoshop':
68
- include_once( 'includes/wpmenucart-jigoshop.php' );
69
- $this->shop = new WPMenuCart_Jigoshop();
70
- if ( !isset($this->options['builtin_ajax']) ) {
71
- add_filter( 'add_to_cart_fragments', array( &$this, 'woocommerce_ajax_fragments' ) );
72
- }
73
- break;
74
- case 'wp-e-commerce':
75
- include_once( 'includes/wpmenucart-wpec.php' );
76
- $this->shop = new WPMenuCart_WPEC();
77
- break;
78
- case 'eshop':
79
- include_once( 'includes/wpmenucart-eshop.php' );
80
- $this->shop = new WPMenuCart_eShop();
81
- break;
82
- case 'easy-digital-downloads':
83
- include_once( 'includes/wpmenucart-edd.php' );
84
- $this->shop = new WPMenuCart_EDD();
85
- if ( !isset($this->options['builtin_ajax']) ) {
86
- add_action("wp_enqueue_scripts", array( &$this, 'load_edd_ajax' ), 0 );
87
- }
88
- break;
89
- }
90
- if ( isset( $this->options['builtin_ajax'] ) || in_array( $this->options['shop_plugin'], array( 'WP e-Commerce', 'wp-e-commerce', 'eShop', 'eshop' ) ) ) {
91
- add_action("wp_enqueue_scripts", array( &$this, 'load_custom_ajax' ), 0 );
92
- }
93
-
94
- }
95
- }
96
- }
97
-
98
- /**
99
- * Check if a shop is active or if conflicting old versions of the plugin are active
100
- * @return boolean
101
- */
102
- public function good_to_go() {
103
- $wpmenucart_shop_check = get_option( 'wpmenucart_shop_check' );
104
- $active_plugins = $this->get_active_plugins();
105
-
106
- // check for shop plugins
107
- if ( !$this->is_shop_active() && $wpmenucart_shop_check != 'hide' ) {
108
- add_action( 'admin_notices', array ( $this, 'need_shop' ) );
109
- return FALSE;
110
- }
111
-
112
- // check for old versions
113
- if ( count( $this->get_active_old_versions() ) > 0 ) {
114
- add_action( 'admin_notices', array ( $this, 'woocommerce_version_active' ) );
115
- return FALSE;
116
- }
117
-
118
- // we made it! good to go :o)
119
- return TRUE;
120
- }
121
-
122
- /**
123
- * Return true if one ore more shops are activated.
124
- * @return boolean
125
- */
126
- public function is_shop_active() {
127
- if ( count($this->get_active_shops()) > 0 ) {
128
- return TRUE;
129
- } else {
130
- return FALSE;
131
- }
132
-
133
- }
134
-
135
- /**
136
- * Get an array of all active plugins, including multisite
137
- * @return array active plugin paths
138
- */
139
- public static function get_active_plugins() {
140
- $active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
141
- if (is_multisite()) {
142
- // get_site_option( 'active_sitewide_plugins', array() ) returns a 'reversed list'
143
- // like [hello-dolly/hello.php] => 1369572703 so we do array_keys to make the array
144
- // compatible with $active_plugins
145
- $active_sitewide_plugins = (array) array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
146
- // merge arrays and remove doubles
147
- $active_plugins = (array) array_unique( array_merge( $active_plugins, $active_sitewide_plugins ) );
148
- }
149
-
150
- return $active_plugins;
151
- }
152
-
153
- /**
154
- * Get array of active shop plugins
155
- *
156
- * @return array plugin name => plugin path
157
- */
158
- public static function get_active_shops() {
159
- $active_plugins = self::get_active_plugins();
160
-
161
- $shop_plugins = array (
162
- 'WooCommerce' => 'woocommerce/woocommerce.php',
163
- 'Jigoshop' => 'jigoshop/jigoshop.php',
164
- 'WP e-Commerce' => 'wp-e-commerce/wp-shopping-cart.php',
165
- 'eShop' => 'eshop/eshop.php',
166
- 'Easy Digital Downloads' => 'easy-digital-downloads/easy-digital-downloads.php',
167
- );
168
-
169
- // filter shop plugins & add shop names as keys
170
- $active_shop_plugins = array_intersect( $shop_plugins, $active_plugins );
171
-
172
- return $active_shop_plugins;
173
- }
174
-
175
- /**
176
- * Get array of active old WooCommerce Menu Cart plugins
177
- *
178
- * @return array plugin paths
179
- */
180
- public function get_active_old_versions() {
181
- $active_plugins = $this->get_active_plugins();
182
-
183
- $old_versions = array (
184
- 'woocommerce-menu-bar-cart/wc_cart_nav.php', //first version
185
- 'woocommerce-menu-bar-cart/woocommerce-menu-cart.php', //last free version
186
- 'woocommerce-menu-cart/woocommerce-menu-cart.php', //never actually released? just in case...
187
- 'woocommerce-menu-cart-pro/woocommerce-menu-cart-pro.php', //old pro version
188
- );
189
-
190
- $active_old_plugins = array_intersect( $old_versions, $active_plugins );
191
-
192
- return $active_old_plugins;
193
- }
194
-
195
- /**
196
- * Fallback admin notices
197
- *
198
- * @return string Fallack notice.
199
- */
200
- public function need_shop() {
201
- $error = __( 'WP Menu Cart could not detect an active shop plugin. Make sure you have activated at least one of the supported plugins.' , 'wp-menu-cart' );
202
- $message = sprintf('<div class="error"><p>%1$s <a href="%2$s">%3$s</a></p></div>', $error, add_query_arg( 'hide_wpmenucart_shop_check', 'true' ), __( 'Hide this notice', 'wp-menu-cart' ) );
203
- echo $message;
204
- }
205
-
206
- public function woocommerce_version_active() {
207
- $error = __( 'An old version of WooCommerce Menu Cart is currently activated, you need to disable or uninstall it for WP Menu Cart to function properly' , 'wp-menu-cart' );
208
- $message = '<div class="error"><p>' . $error . '</p></div>';
209
- echo $message;
210
- }
211
-
212
- /**
213
- * Load translations.
214
- */
215
- public function languages() {
216
- $locale = apply_filters( 'plugin_locale', get_locale(), 'wp-menu-cart' );
217
- $dir = trailingslashit( WP_LANG_DIR );
218
-
219
- /**
220
- * Frontend/global Locale. Looks in:
221
- *
222
- * - WP_LANG_DIR/wp-menu-cart/wp-menu-cart-LOCALE.mo
223
- * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
224
- * - wp-menu-cart/languages/wp-menu-cart-LOCALE.mo (which if not found falls back to:)
225
- * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
226
- */
227
- load_textdomain( 'wp-menu-cart', $dir . 'wp-menu-cart/wp-menu-cart-' . $locale . '.mo' );
228
- load_textdomain( 'wp-menu-cart', $dir . 'plugins/wp-menu-cart-' . $locale . '.mo' );
229
- load_plugin_textdomain( 'wp-menu-cart', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
230
- }
231
-
232
- /**
233
- * Maintain textdomain compatibility between main plugin (wp-menu-cart) and WooCommerce version (woocommerce-menu-bar-cart)
234
- * so that wordpress.org language packs can be used for both
235
- */
236
- public function textdomain_fallback( $mofile, $textdomain ) {
237
- $main_domain = 'wp-menu-cart';
238
- $wc_domain = 'woocommerce-menu-bar-cart';
239
-
240
- // check if this is filtering the mofile for this plugin
241
- if ( $textdomain === $main_domain ) {
242
- $wc_mofile = str_replace( "{$textdomain}-", "{$wc_domain}-", $mofile ); // with trailing dash to target file and not folder
243
- if ( file_exists( $wc_mofile ) ) {
244
- // we have a wc override - use it
245
- return $wc_mofile;
246
- }
247
- }
248
-
249
- return $mofile;
250
- }
251
-
252
- /**
253
- * Register strings for WPML String Translation
254
- */
255
- public function wpml() {
256
- if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_register_string' ) ) {
257
- icl_register_string('WP Menu Cart', 'item text', 'item');
258
- icl_register_string('WP Menu Cart', 'items text', 'items');
259
- icl_register_string('WP Menu Cart', 'empty cart text', 'your cart is currently empty');
260
- icl_register_string('WP Menu Cart', 'hover text', 'View your shopping cart');
261
- icl_register_string('WP Menu Cart', 'empty hover text', 'Start shopping');
262
- }
263
- }
264
-
265
-
266
- /**
267
- * Load custom ajax
268
- */
269
- public function load_custom_ajax() {
270
- wp_enqueue_script(
271
- 'wpmenucart',
272
- plugins_url( '/javascript/wpmenucart.js' , __FILE__ ),
273
- array( 'jquery' ),
274
- '2.7.0',
275
- true
276
- );
277
-
278
- // get URL to WordPress ajax handling page
279
- if ( $this->options['shop_plugin'] == 'easy-digital-downloads' && function_exists( 'edd_get_ajax_url' ) ) {
280
- // use EDD function to prevent SSL issues http://git.io/V7w76A
281
- $ajax_url = edd_get_ajax_url();
282
- } else {
283
- $ajax_url = admin_url( 'admin-ajax.php' );
284
- }
285
-
286
- wp_localize_script(
287
- 'wpmenucart',
288
- 'wpmenucart_ajax',
289
- array(
290
- 'ajaxurl' => $ajax_url,
291
- 'nonce' => wp_create_nonce('wpmenucart')
292
- )
293
- );
294
- }
295
-
296
- /**
297
- * Load EDD ajax helper
298
- */
299
- public function load_edd_ajax() {
300
- wp_enqueue_script(
301
- 'wpmenucart-edd-ajax',
302
- plugins_url( '/javascript/wpmenucart-edd-ajax.js', __FILE__ ),
303
- array( 'jquery' ),
304
- '2.7.0'
305
- );
306
-
307
- wp_localize_script(
308
- 'wpmenucart-edd-ajax',
309
- 'wpmenucart_ajax',
310
- array(
311
- 'ajaxurl' => function_exists( 'edd_get_ajax_url' ) ? edd_get_ajax_url() : admin_url( 'admin-ajax.php' ),
312
- 'nonce' => wp_create_nonce('wpmenucart'),
313
- 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
314
- )
315
- );
316
- }
317
-
318
-
319
- /**
320
- * Load CSS
321
- */
322
- public function load_scripts_styles() {
323
- if (isset($this->options['icon_display'])) {
324
- wp_register_style( 'wpmenucart-icons', plugins_url( '/css/wpmenucart-icons.css', __FILE__ ), array(), '', 'all' );
325
- wp_enqueue_style( 'wpmenucart-icons' );
326
- wp_register_style( 'wpmenucart-fontawesome', plugins_url( '/css/wpmenucart-fontawesome.css', __FILE__ ), array(), '', 'all' );
327
- wp_enqueue_style( 'wpmenucart-fontawesome' );
328
- }
329
-
330
- $css = file_exists( get_stylesheet_directory() . '/wpmenucart-main.css' )
331
- ? get_stylesheet_directory_uri() . '/wpmenucart-main.css'
332
- : plugins_url( '/css/wpmenucart-main.css', __FILE__ );
333
-
334
- wp_register_style( 'wpmenucart', $css, array(), '', 'all' );
335
- wp_enqueue_style( 'wpmenucart' );
336
-
337
- // Hide built-in theme carts
338
- if ( isset($this->options['hide_theme_cart']) ) {
339
- wp_add_inline_style( 'wpmenucart', '.et-cart-info { display:none !important; } .site-header-cart { display:none !important; }' );
340
- }
341
-
342
- //Load Stylesheet if twentytwelve is active
343
- if ( wp_get_theme() == 'Twenty Twelve' ) {
344
- wp_register_style( 'wpmenucart-twentytwelve', plugins_url( '/css/wpmenucart-twentytwelve.css', __FILE__ ), array(), '', 'all' );
345
- wp_enqueue_style( 'wpmenucart-twentytwelve' );
346
- }
347
-
348
- //Load Stylesheet if twentyfourteen is active
349
- if ( wp_get_theme() == 'Twenty Fourteen' ) {
350
- wp_register_style( 'wpmenucart-twentyfourteen', plugins_url( '/css/wpmenucart-twentyfourteen.css', __FILE__ ), array(), '', 'all' );
351
- wp_enqueue_style( 'wpmenucart-twentyfourteen' );
352
- }
353
-
354
- // extra script that improves AJAX behavior when 'Always display cart' is disabled
355
- wp_enqueue_script(
356
- 'wpmenucart-ajax-assist',
357
- plugins_url( '/javascript/wpmenucart-ajax-assist.js', __FILE__ ),
358
- array( 'jquery' )
359
- );
360
- wp_localize_script(
361
- 'wpmenucart-ajax-assist',
362
- 'wpmenucart_ajax_assist',
363
- array(
364
- 'shop_plugin' => isset($this->options['shop_plugin']) ? $this->options['shop_plugin'] : '',
365
- 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
366
- )
367
- );
368
-
369
- }
370
-
371
- /**
372
- * Add filters to selected menus to add cart item <li>
373
- */
374
- public function filter_nav_menus() {
375
- // exit if no shop class is active
376
- if ( !isset($this->shop) )
377
- return;
378
-
379
- // exit if no menus set
380
- if ( !isset( $this->options['menu_slugs'] ) || empty( $this->options['menu_slugs'] ) )
381
- return;
382
-
383
- if ( $this->options['menu_slugs'][1] != '0' ) {
384
- add_filter( 'wp_nav_menu_' . $this->options['menu_slugs'][1] . '_items', array( &$this, 'add_itemcart_to_menu' ) , 10, 2 );
385
- }
386
- }
387
-
388
- /**
389
- * Add Menu Cart to menu
390
- *
391
- * @return menu items + Menu Cart item
392
- */
393
- public function add_itemcart_to_menu( $items ) {
394
- // WooCommerce specific: check if woocommerce cart object is actually loaded
395
- if ( isset($this->options['shop_plugin']) && $this->options['shop_plugin'] == 'woocommerce' ) {
396
- global $woocommerce;
397
- if (empty($woocommerce) || !is_object($woocommerce) || !isset($woocommerce->cart) || !is_object($woocommerce->cart)) {
398
- return $items; // nothing to load data from, return menu without cart item
399
- }
400
- }
401
-
402
- $classes = 'wpmenucartli wpmenucart-display-'.$this->options['items_alignment'];
403
-
404
- if ($this->get_common_li_classes($items) != '')
405
- $classes .= ' ' . $this->get_common_li_classes($items);
406
-
407
- $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
408
-
409
- // Filter for <li> item classes
410
- /* Usage (in the themes functions.php):
411
- add_filter('wpmenucart_menu_item_classes', 'add_wpmenucart_item_class', 1, 1);
412
- function add_wpmenucart_item_class ($classes) {
413
- $classes .= ' yourclass';
414
- return $classes;
415
- }
416
- */
417
- $classes = apply_filters( 'wpmenucart_menu_item_classes', $classes );
418
- $this->menu_items['menu']['menu_item_li_classes'] = $classes;
419
-
420
- // DEPRECATED: These filters are now deprecated in favour of the more precise filters in the functions!
421
- $wpmenucart_menu_item = apply_filters( 'wpmenucart_menu_item_filter', $this->wpmenucart_menu_item() );
422
-
423
- $item_data = $this->shop->menu_item();
424
-
425
- $menu_item_li = '<li class="'.$classes.'" id="wpmenucartli">' . $wpmenucart_menu_item . '</li>';
426
-
427
- if ( apply_filters('wpmenucart_prepend_menu_item', false) ) {
428
- $items = apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li ) . $items;
429
- } else {
430
- $items .= apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li );
431
- }
432
-
433
- return $items;
434
- }
435
-
436
- /**
437
- * Get a flat list of common classes from all menu items in a menu
438
- * @param string $items nav_menu HTML containing all <li> menu items
439
- * @return string flat (imploded) list of common classes
440
- */
441
- public function get_common_li_classes($items) {
442
- if (empty($items)) return '';
443
- if (!class_exists('DOMDocument')) return '';
444
-
445
- $libxml_previous_state = libxml_use_internal_errors(true); // enable user error handling
446
-
447
- $dom_items = new DOMDocument;
448
- $dom_items->loadHTML( $items );
449
- $lis = $dom_items->getElementsByTagName('li');
450
-
451
- if (empty($lis)) {
452
- libxml_clear_errors();
453
- libxml_use_internal_errors($libxml_previous_state);
454
- return;
455
- }
456
-
457
- foreach($lis as $li) {
458
- if ($li->parentNode->tagName != 'ul')
459
- $li_classes[] = explode( ' ', $li->getAttribute('class') );
460
- }
461
-
462
- // Uncomment to dump DOM errors / warnings
463
- //$errors = libxml_get_errors();
464
- //print_r ($errors);
465
-
466
- // clear errors and reset to previous error handling state
467
- libxml_clear_errors();
468
- libxml_use_internal_errors($libxml_previous_state);
469
-
470
- if ( !empty($li_classes) ) {
471
- $common_li_classes = array_shift($li_classes);
472
- foreach ($li_classes as $li_class) {
473
- $common_li_classes = array_intersect($li_class, $common_li_classes);
474
- }
475
- $common_li_classes_flat = implode(' ', $common_li_classes);
476
- } else {
477
- $common_li_classes_flat = '';
478
- }
479
- return $common_li_classes_flat;
480
- }
481
-
482
- /**
483
- * Ajaxify Menu Cart
484
- */
485
- public function woocommerce_ajax_fragments( $fragments ) {
486
- if ( ! defined('WOOCOMMERCE_CART') ) {
487
- define( 'WOOCOMMERCE_CART', true );
488
- }
489
-
490
- $fragments['a.wpmenucart-contents'] = $this->wpmenucart_menu_item();
491
- return $fragments;
492
- }
493
-
494
- /**
495
- * Create HTML for Menu Cart item
496
- */
497
- public function wpmenucart_menu_item() {
498
- $item_data = $this->shop->menu_item();
499
-
500
- // Check empty cart settings
501
- if ($item_data['cart_contents_count'] == 0 && ( !isset($this->options['always_display']) ) ) {
502
- $empty_menu_item = '<a class="wpmenucart-contents empty-wpmenucart" style="display:none">&nbsp;</a>';
503
- return $empty_menu_item;
504
- }
505
-
506
- if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_t' ) ) {
507
- //use WPML
508
- $viewing_cart = icl_t('WP Menu Cart', 'hover text', 'View your shopping cart');
509
- $start_shopping = icl_t('WP Menu Cart', 'empty hover text', 'Start shopping');
510
- $cart_contents = $item_data['cart_contents_count'] .' '. ( $item_data['cart_contents_count'] == 1 ? icl_t('WP Menu Cart', 'item text', 'item') : icl_t('WP Menu Cart', 'items text', 'items') );
511
- } else {
512
- //use regular WP i18n
513
- $viewing_cart = __('View your shopping cart', 'wp-menu-cart');
514
- $start_shopping = __('Start shopping', 'wp-menu-cart');
515
- $cart_contents = sprintf(_n('%d item', '%d items', $item_data['cart_contents_count'], 'wp-menu-cart'), $item_data['cart_contents_count']);
516
- }
517
-
518
- $this->menu_items['menu']['cart_contents'] = $cart_contents;
519
-
520
- if ($item_data['cart_contents_count'] == 0) {
521
- $menu_item_href = apply_filters ('wpmenucart_emptyurl', $item_data['shop_page_url'] );
522
- $menu_item_title = apply_filters ('wpmenucart_emptytitle', $start_shopping );
523
- $menu_item_classes = 'wpmenucart-contents empty-wpmenucart-visible';
524
- } else {
525
- $menu_item_href = apply_filters ('wpmenucart_fullurl', $item_data['cart_url'] );
526
- $menu_item_title = apply_filters ('wpmenucart_fulltitle', $viewing_cart );
527
- $menu_item_classes = 'wpmenucart-contents';
528
- }
529
-
530
- $this->menu_items['menu']['menu_item_href'] = $menu_item_href;
531
- $this->menu_items['menu']['menu_item_title'] = $menu_item_title;
532
-
533
- if(defined('UBERMENU_VERSION') && (version_compare(UBERMENU_VERSION, '3.0.0') >= 0)){
534
- $menu_item_classes .= ' ubermenu-target';
535
- }
536
-
537
- $menu_item = '<a class="'.$menu_item_classes.'" href="'.$menu_item_href.'" title="'.$menu_item_title.'">';
538
-
539
- $menu_item_a_content = '';
540
- if (isset($this->options['icon_display'])) {
541
- $icon = isset($this->options['cart_icon']) ? $this->options['cart_icon'] : '0';
542
- $menu_item_icon = '<i class="wpmenucart-icon-shopping-cart-'.$icon.'"></i>';
543
- $menu_item_a_content .= $menu_item_icon;
544
- }
545
-
546
- switch ($this->options['items_display']) {
547
- case 1: //items only
548
- $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span>';
549
- break;
550
- case 2: //price only
551
- $menu_item_a_content .= '<span class="amount">'.$item_data['cart_total'].'</span>';
552
- break;
553
- case 3: //items & price
554
- $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span><span class="amount">'.$item_data['cart_total'].'</span>';
555
- break;
556
- }
557
- $menu_item_a_content = apply_filters ('wpmenucart_menu_item_a_content', $menu_item_a_content, $menu_item_icon, $cart_contents, $item_data );
558
-
559
- $this->menu_items['menu']['menu_item_a_content'] = $menu_item_a_content;
560
-
561
- $menu_item .= $menu_item_a_content . '</a>';
562
-
563
- $menu_item = apply_filters ('wpmenucart_menu_item_a', $menu_item, $item_data, $this->options, $menu_item_a_content, $viewing_cart, $start_shopping, $cart_contents);
564
-
565
- if( !empty( $menu_item ) ) return $menu_item;
566
- }
567
-
568
- public function wpmenucart_ajax() {
569
- check_ajax_referer( 'wpmenucart', 'security' );
570
-
571
- $variable = $this->wpmenucart_menu_item();
572
- echo $variable;
573
- die();
574
- }
575
-
576
- }
577
-
578
- $wpMenuCart = new WpMenuCart();
579
-
580
- /**
581
- * Hide notifications
582
- */
583
-
584
- if ( ! empty( $_GET['hide_wpmenucart_shop_check'] ) ) {
585
- update_option( 'wpmenucart_shop_check', 'hide' );
586
  }
1
+ <?php
2
+ /**
3
+ * Plugin Name: WooCommerce Menu Cart
4
+ * Plugin URI: www.wpovernight.com/plugins
5
+ * Description: Extension for your e-commerce plugin (WooCommerce, WP-Ecommerce, Easy Digital Downloads, Eshop or Jigoshop) that places a cart icon with number of items and total cost in the menu bar. Activate the plugin, set your options and you're ready to go! Will automatically conform to your theme styles.
6
+ * Version: 2.7.1
7
+ * Author: Jeremiah Prummer, Ewout Fernhout
8
+ * Author URI: www.wpovernight.com/
9
+ * License: GPL2
10
+ * Text Domain: wp-menu-cart
11
+ * WC requires at least: 2.0.0
12
+ * WC tested up to: 3.3.0
13
+ */
14
+
15
+ class WpMenuCart {
16
+
17
+ public static $plugin_slug;
18
+ public static $plugin_basename;
19
+
20
+ /**
21
+ * Construct.
22
+ */
23
+ public function __construct() {
24
+ self::$plugin_slug = basename(dirname(__FILE__));
25
+ self::$plugin_basename = plugin_basename(__FILE__);
26
+
27
+ $this->options = get_option('wpmenucart');
28
+
29
+ // load the localisation & classes
30
+ add_action( 'plugins_loaded', array( &$this, 'languages' ), 0 ); // or use init?
31
+ add_filter( 'load_textdomain_mofile', array( $this, 'textdomain_fallback' ), 10, 2 );
32
+ add_action( 'init', array( &$this, 'wpml' ), 0 );
33
+ add_action( 'init', array( $this, 'load_classes' ) );
34
+
35
+ // enqueue scripts & ajax
36
+ add_action( 'wp_enqueue_scripts', array( &$this, 'load_scripts_styles' ) ); // Load scripts
37
+ add_action( 'wp_ajax_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
38
+ add_action( 'wp_ajax_nopriv_wpmenucart_ajax', array( &$this, 'wpmenucart_ajax' ), 0 );
39
+
40
+ // add filters to selected menus to add cart item <li>
41
+ add_action( 'init', array( $this, 'filter_nav_menus' ) );
42
+ // $this->filter_nav_menus();
43
+ }
44
+
45
+ /**
46
+ * Load classes
47
+ * @return void
48
+ */
49
+ public function load_classes() {
50
+ include_once( 'includes/wpmenucart-settings.php' );
51
+ $this->settings = new WpMenuCart_Settings();
52
+
53
+ if ( $this->good_to_go() ) {
54
+ if (isset($this->options['shop_plugin'])) {
55
+ switch ($this->options['shop_plugin']) {
56
+ case 'woocommerce':
57
+ include_once( 'includes/wpmenucart-woocommerce.php' );
58
+ $this->shop = new WPMenuCart_WooCommerce();
59
+ if ( !isset($this->options['builtin_ajax']) ) {
60
+ if ( defined('WOOCOMMERCE_VERSION') && version_compare( WOOCOMMERCE_VERSION, '2.7', '>=' ) ) {
61
+ add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
62
+ } else {
63
+ add_filter( 'add_to_cart_fragments', array( $this, 'woocommerce_ajax_fragments' ) );
64
+ }
65
+ }
66
+ break;
67
+ case 'jigoshop':
68
+ include_once( 'includes/wpmenucart-jigoshop.php' );
69
+ $this->shop = new WPMenuCart_Jigoshop();
70
+ if ( !isset($this->options['builtin_ajax']) ) {
71
+ add_filter( 'add_to_cart_fragments', array( &$this, 'woocommerce_ajax_fragments' ) );
72
+ }
73
+ break;
74
+ case 'wp-e-commerce':
75
+ include_once( 'includes/wpmenucart-wpec.php' );
76
+ $this->shop = new WPMenuCart_WPEC();
77
+ break;
78
+ case 'eshop':
79
+ include_once( 'includes/wpmenucart-eshop.php' );
80
+ $this->shop = new WPMenuCart_eShop();
81
+ break;
82
+ case 'easy-digital-downloads':
83
+ include_once( 'includes/wpmenucart-edd.php' );
84
+ $this->shop = new WPMenuCart_EDD();
85
+ if ( !isset($this->options['builtin_ajax']) ) {
86
+ add_action("wp_enqueue_scripts", array( &$this, 'load_edd_ajax' ), 0 );
87
+ }
88
+ break;
89
+ }
90
+ if ( isset( $this->options['builtin_ajax'] ) || in_array( $this->options['shop_plugin'], array( 'WP e-Commerce', 'wp-e-commerce', 'eShop', 'eshop' ) ) ) {
91
+ add_action("wp_enqueue_scripts", array( &$this, 'load_custom_ajax' ), 0 );
92
+ }
93
+
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Check if a shop is active or if conflicting old versions of the plugin are active
100
+ * @return boolean
101
+ */
102
+ public function good_to_go() {
103
+ $wpmenucart_shop_check = get_option( 'wpmenucart_shop_check' );
104
+ $active_plugins = $this->get_active_plugins();
105
+
106
+ // check for shop plugins
107
+ if ( !$this->is_shop_active() && $wpmenucart_shop_check != 'hide' ) {
108
+ add_action( 'admin_notices', array ( $this, 'need_shop' ) );
109
+ return FALSE;
110
+ }
111
+
112
+ // check for old versions
113
+ if ( count( $this->get_active_old_versions() ) > 0 ) {
114
+ add_action( 'admin_notices', array ( $this, 'woocommerce_version_active' ) );
115
+ return FALSE;
116
+ }
117
+
118
+ // we made it! good to go :o)
119
+ return TRUE;
120
+ }
121
+
122
+ /**
123
+ * Return true if one ore more shops are activated.
124
+ * @return boolean
125
+ */
126
+ public function is_shop_active() {
127
+ if ( count($this->get_active_shops()) > 0 ) {
128
+ return TRUE;
129
+ } else {
130
+ return FALSE;
131
+ }
132
+
133
+ }
134
+
135
+ /**
136
+ * Get an array of all active plugins, including multisite
137
+ * @return array active plugin paths
138
+ */
139
+ public static function get_active_plugins() {
140
+ $active_plugins = (array) apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
141
+ if (is_multisite()) {
142
+ // get_site_option( 'active_sitewide_plugins', array() ) returns a 'reversed list'
143
+ // like [hello-dolly/hello.php] => 1369572703 so we do array_keys to make the array
144
+ // compatible with $active_plugins
145
+ $active_sitewide_plugins = (array) array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
146
+ // merge arrays and remove doubles
147
+ $active_plugins = (array) array_unique( array_merge( $active_plugins, $active_sitewide_plugins ) );
148
+ }
149
+
150
+ return $active_plugins;
151
+ }
152
+
153
+ /**
154
+ * Get array of active shop plugins
155
+ *
156
+ * @return array plugin name => plugin path
157
+ */
158
+ public static function get_active_shops() {
159
+ $active_plugins = self::get_active_plugins();
160
+
161
+ $shop_plugins = array (
162
+ 'WooCommerce' => 'woocommerce/woocommerce.php',
163
+ 'Jigoshop' => 'jigoshop/jigoshop.php',
164
+ 'WP e-Commerce' => 'wp-e-commerce/wp-shopping-cart.php',
165
+ 'eShop' => 'eshop/eshop.php',
166
+ 'Easy Digital Downloads' => 'easy-digital-downloads/easy-digital-downloads.php',
167
+ );
168
+
169
+ // filter shop plugins & add shop names as keys
170
+ $active_shop_plugins = array_intersect( $shop_plugins, $active_plugins );
171
+
172
+ return $active_shop_plugins;
173
+ }
174
+
175
+ /**
176
+ * Get array of active old WooCommerce Menu Cart plugins
177
+ *
178
+ * @return array plugin paths
179
+ */
180
+ public function get_active_old_versions() {
181
+ $active_plugins = $this->get_active_plugins();
182
+
183
+ $old_versions = array (
184
+ 'woocommerce-menu-bar-cart/wc_cart_nav.php', //first version
185
+ 'woocommerce-menu-bar-cart/woocommerce-menu-cart.php', //last free version
186
+ 'woocommerce-menu-cart/woocommerce-menu-cart.php', //never actually released? just in case...
187
+ 'woocommerce-menu-cart-pro/woocommerce-menu-cart-pro.php', //old pro version
188
+ );
189
+
190
+ $active_old_plugins = array_intersect( $old_versions, $active_plugins );
191
+
192
+ return $active_old_plugins;
193
+ }
194
+
195
+ /**
196
+ * Fallback admin notices
197
+ *
198
+ * @return string Fallack notice.
199
+ */
200
+ public function need_shop() {
201
+ $error = __( 'WP Menu Cart could not detect an active shop plugin. Make sure you have activated at least one of the supported plugins.' , 'wp-menu-cart' );
202
+ $message = sprintf('<div class="error"><p>%1$s <a href="%2$s">%3$s</a></p></div>', $error, add_query_arg( 'hide_wpmenucart_shop_check', 'true' ), __( 'Hide this notice', 'wp-menu-cart' ) );
203
+ echo $message;
204
+ }
205
+
206
+ public function woocommerce_version_active() {
207
+ $error = __( 'An old version of WooCommerce Menu Cart is currently activated, you need to disable or uninstall it for WP Menu Cart to function properly' , 'wp-menu-cart' );
208
+ $message = '<div class="error"><p>' . $error . '</p></div>';
209
+ echo $message;
210
+ }
211
+
212
+ /**
213
+ * Load translations.
214
+ */
215
+ public function languages() {
216
+ $locale = apply_filters( 'plugin_locale', get_locale(), 'wp-menu-cart' );
217
+ $dir = trailingslashit( WP_LANG_DIR );
218
+
219
+ /**
220
+ * Frontend/global Locale. Looks in:
221
+ *
222
+ * - WP_LANG_DIR/wp-menu-cart/wp-menu-cart-LOCALE.mo
223
+ * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
224
+ * - wp-menu-cart/languages/wp-menu-cart-LOCALE.mo (which if not found falls back to:)
225
+ * - WP_LANG_DIR/plugins/wp-menu-cart-LOCALE.mo
226
+ */
227
+ load_textdomain( 'wp-menu-cart', $dir . 'wp-menu-cart/wp-menu-cart-' . $locale . '.mo' );
228
+ load_textdomain( 'wp-menu-cart', $dir . 'plugins/wp-menu-cart-' . $locale . '.mo' );
229
+ load_plugin_textdomain( 'wp-menu-cart', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
230
+ }
231
+
232
+ /**
233
+ * Maintain textdomain compatibility between main plugin (wp-menu-cart) and WooCommerce version (woocommerce-menu-bar-cart)
234
+ * so that wordpress.org language packs can be used for both
235
+ */
236
+ public function textdomain_fallback( $mofile, $textdomain ) {
237
+ $main_domain = 'wp-menu-cart';
238
+ $wc_domain = 'woocommerce-menu-bar-cart';
239
+
240
+ // check if this is filtering the mofile for this plugin
241
+ if ( $textdomain === $main_domain ) {
242
+ $wc_mofile = str_replace( "{$textdomain}-", "{$wc_domain}-", $mofile ); // with trailing dash to target file and not folder
243
+ if ( file_exists( $wc_mofile ) ) {
244
+ // we have a wc override - use it
245
+ return $wc_mofile;
246
+ }
247
+ }
248
+
249
+ return $mofile;
250
+ }
251
+
252
+ /**
253
+ * Register strings for WPML String Translation
254
+ */
255
+ public function wpml() {
256
+ if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_register_string' ) ) {
257
+ icl_register_string('WP Menu Cart', 'item text', 'item');
258
+ icl_register_string('WP Menu Cart', 'items text', 'items');
259
+ icl_register_string('WP Menu Cart', 'empty cart text', 'your cart is currently empty');
260
+ icl_register_string('WP Menu Cart', 'hover text', 'View your shopping cart');
261
+ icl_register_string('WP Menu Cart', 'empty hover text', 'Start shopping');
262
+ }
263
+ }
264
+
265
+
266
+ /**
267
+ * Load custom ajax
268
+ */
269
+ public function load_custom_ajax() {
270
+ wp_enqueue_script(
271
+ 'wpmenucart',
272
+ plugins_url( '/javascript/wpmenucart.js' , __FILE__ ),
273
+ array( 'jquery' ),
274
+ '2.7.1',
275
+ true
276
+ );
277
+
278
+ // get URL to WordPress ajax handling page
279
+ if ( $this->options['shop_plugin'] == 'easy-digital-downloads' && function_exists( 'edd_get_ajax_url' ) ) {
280
+ // use EDD function to prevent SSL issues http://git.io/V7w76A
281
+ $ajax_url = edd_get_ajax_url();
282
+ } else {
283
+ $ajax_url = admin_url( 'admin-ajax.php' );
284
+ }
285
+
286
+ wp_localize_script(
287
+ 'wpmenucart',
288
+ 'wpmenucart_ajax',
289
+ array(
290
+ 'ajaxurl' => $ajax_url,
291
+ 'nonce' => wp_create_nonce('wpmenucart')
292
+ )
293
+ );
294
+ }
295
+
296
+ /**
297
+ * Load EDD ajax helper
298
+ */
299
+ public function load_edd_ajax() {
300
+ wp_enqueue_script(
301
+ 'wpmenucart-edd-ajax',
302
+ plugins_url( '/javascript/wpmenucart-edd-ajax.js', __FILE__ ),
303
+ array( 'jquery' ),
304
+ '2.7.1'
305
+ );
306
+
307
+ wp_localize_script(
308
+ 'wpmenucart-edd-ajax',
309
+ 'wpmenucart_ajax',
310
+ array(
311
+ 'ajaxurl' => function_exists( 'edd_get_ajax_url' ) ? edd_get_ajax_url() : admin_url( 'admin-ajax.php' ),
312
+ 'nonce' => wp_create_nonce('wpmenucart'),
313
+ 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
314
+ )
315
+ );
316
+ }
317
+
318
+
319
+ /**
320
+ * Load CSS
321
+ */
322
+ public function load_scripts_styles() {
323
+ if (isset($this->options['icon_display'])) {
324
+ wp_register_style( 'wpmenucart-icons', plugins_url( '/css/wpmenucart-icons.css', __FILE__ ), array(), '', 'all' );
325
+ wp_enqueue_style( 'wpmenucart-icons' );
326
+ wp_register_style( 'wpmenucart-fontawesome', plugins_url( '/css/wpmenucart-fontawesome.css', __FILE__ ), array(), '', 'all' );
327
+ wp_enqueue_style( 'wpmenucart-fontawesome' );
328
+ }
329
+
330
+ $css = file_exists( get_stylesheet_directory() . '/wpmenucart-main.css' )
331
+ ? get_stylesheet_directory_uri() . '/wpmenucart-main.css'
332
+ : plugins_url( '/css/wpmenucart-main.css', __FILE__ );
333
+
334
+ wp_register_style( 'wpmenucart', $css, array(), '', 'all' );
335
+ wp_enqueue_style( 'wpmenucart' );
336
+
337
+ // Hide built-in theme carts
338
+ if ( isset($this->options['hide_theme_cart']) ) {
339
+ wp_add_inline_style( 'wpmenucart', '.et-cart-info { display:none !important; } .site-header-cart { display:none !important; }' );
340
+ }
341
+
342
+ //Load Stylesheet if twentytwelve is active
343
+ if ( wp_get_theme() == 'Twenty Twelve' ) {
344
+ wp_register_style( 'wpmenucart-twentytwelve', plugins_url( '/css/wpmenucart-twentytwelve.css', __FILE__ ), array(), '', 'all' );
345
+ wp_enqueue_style( 'wpmenucart-twentytwelve' );
346
+ }
347
+
348
+ //Load Stylesheet if twentyfourteen is active
349
+ if ( wp_get_theme() == 'Twenty Fourteen' ) {
350
+ wp_register_style( 'wpmenucart-twentyfourteen', plugins_url( '/css/wpmenucart-twentyfourteen.css', __FILE__ ), array(), '', 'all' );
351
+ wp_enqueue_style( 'wpmenucart-twentyfourteen' );
352
+ }
353
+
354
+ // extra script that improves AJAX behavior when 'Always display cart' is disabled
355
+ wp_enqueue_script(
356
+ 'wpmenucart-ajax-assist',
357
+ plugins_url( '/javascript/wpmenucart-ajax-assist.js', __FILE__ ),
358
+ array( 'jquery' )
359
+ );
360
+ wp_localize_script(
361
+ 'wpmenucart-ajax-assist',
362
+ 'wpmenucart_ajax_assist',
363
+ array(
364
+ 'shop_plugin' => isset($this->options['shop_plugin']) ? $this->options['shop_plugin'] : '',
365
+ 'always_display' => isset($this->options['always_display']) ? $this->options['always_display'] : '',
366
+ )
367
+ );
368
+
369
+ }
370
+
371
+ /**
372
+ * Add filters to selected menus to add cart item <li>
373
+ */
374
+ public function filter_nav_menus() {
375
+ // exit if no shop class is active
376
+ if ( !isset($this->shop) )
377
+ return;
378
+
379
+ // exit if no menus set
380
+ if ( !isset( $this->options['menu_slugs'] ) || empty( $this->options['menu_slugs'] ) )
381
+ return;
382
+
383
+ if ( $this->options['menu_slugs'][1] != '0' ) {
384
+ add_filter( 'wp_nav_menu_' . $this->options['menu_slugs'][1] . '_items', array( &$this, 'add_itemcart_to_menu' ) , 10, 2 );
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Add Menu Cart to menu
390
+ *
391
+ * @return menu items + Menu Cart item
392
+ */
393
+ public function add_itemcart_to_menu( $items ) {
394
+ // WooCommerce specific: check if woocommerce cart object is actually loaded
395
+ if ( isset($this->options['shop_plugin']) && $this->options['shop_plugin'] == 'woocommerce' ) {
396
+ global $woocommerce;
397
+ if (empty($woocommerce) || !is_object($woocommerce) || !isset($woocommerce->cart) || !is_object($woocommerce->cart)) {
398
+ return $items; // nothing to load data from, return menu without cart item
399
+ }
400
+ }
401
+
402
+ $classes = 'wpmenucartli wpmenucart-display-'.$this->options['items_alignment'];
403
+
404
+ if ($this->get_common_li_classes($items) != '')
405
+ $classes .= ' ' . $this->get_common_li_classes($items);
406
+
407
+ $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
408
+
409
+ // Filter for <li> item classes
410
+ /* Usage (in the themes functions.php):
411
+ add_filter('wpmenucart_menu_item_classes', 'add_wpmenucart_item_class', 1, 1);
412
+ function add_wpmenucart_item_class ($classes) {
413
+ $classes .= ' yourclass';
414
+ return $classes;
415
+ }
416
+ */
417
+ $classes = apply_filters( 'wpmenucart_menu_item_classes', $classes );
418
+ $this->menu_items['menu']['menu_item_li_classes'] = $classes;
419
+
420
+ // DEPRECATED: These filters are now deprecated in favour of the more precise filters in the functions!
421
+ $wpmenucart_menu_item = apply_filters( 'wpmenucart_menu_item_filter', $this->wpmenucart_menu_item() );
422
+
423
+ $item_data = $this->shop->menu_item();
424
+
425
+ $menu_item_li = '<li class="'.$classes.'" id="wpmenucartli">' . $wpmenucart_menu_item . '</li>';
426
+
427
+ if ( apply_filters('wpmenucart_prepend_menu_item', false) ) {
428
+ $items = apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li ) . $items;
429
+ } else {
430
+ $items .= apply_filters( 'wpmenucart_menu_item_wrapper', $menu_item_li );
431
+ }
432
+
433
+ return $items;
434
+ }
435
+
436
+ /**
437
+ * Get a flat list of common classes from all menu items in a menu
438
+ * @param string $items nav_menu HTML containing all <li> menu items
439
+ * @return string flat (imploded) list of common classes
440
+ */
441
+ public function get_common_li_classes($items) {
442
+ if (empty($items)) return '';
443
+ if (!class_exists('DOMDocument')) return '';
444
+
445
+ $libxml_previous_state = libxml_use_internal_errors(true); // enable user error handling
446
+
447
+ $dom_items = new DOMDocument;
448
+ $dom_items->loadHTML( $items );
449
+ $lis = $dom_items->getElementsByTagName('li');
450
+
451
+ if (empty($lis)) {
452
+ libxml_clear_errors();
453
+ libxml_use_internal_errors($libxml_previous_state);
454
+ return;
455
+ }
456
+
457
+ foreach($lis as $li) {
458
+ if ($li->parentNode->tagName != 'ul')
459
+ $li_classes[] = explode( ' ', $li->getAttribute('class') );
460
+ }
461
+
462
+ // Uncomment to dump DOM errors / warnings
463
+ //$errors = libxml_get_errors();
464
+ //print_r ($errors);
465
+
466
+ // clear errors and reset to previous error handling state
467
+ libxml_clear_errors();
468
+ libxml_use_internal_errors($libxml_previous_state);
469
+
470
+ if ( !empty($li_classes) ) {
471
+ $common_li_classes = array_shift($li_classes);
472
+ foreach ($li_classes as $li_class) {
473
+ $common_li_classes = array_intersect($li_class, $common_li_classes);
474
+ }
475
+ $common_li_classes_flat = implode(' ', $common_li_classes);
476
+ } else {
477
+ $common_li_classes_flat = '';
478
+ }
479
+ return $common_li_classes_flat;
480
+ }
481
+
482
+ /**
483
+ * Ajaxify Menu Cart
484
+ */
485
+ public function woocommerce_ajax_fragments( $fragments ) {
486
+ if ( ! defined('WOOCOMMERCE_CART') ) {
487
+ define( 'WOOCOMMERCE_CART', true );
488
+ }
489
+
490
+ $fragments['a.wpmenucart-contents'] = $this->wpmenucart_menu_item();
491
+ return $fragments;
492
+ }
493
+
494
+ /**
495
+ * Create HTML for Menu Cart item
496
+ */
497
+ public function wpmenucart_menu_item() {
498
+ $item_data = $this->shop->menu_item();
499
+
500
+ // Check empty cart settings
501
+ if ($item_data['cart_contents_count'] == 0 && ( !isset($this->options['always_display']) ) ) {
502
+ $empty_menu_item = '<a class="wpmenucart-contents empty-wpmenucart" style="display:none">&nbsp;</a>';
503
+ return $empty_menu_item;
504
+ }
505
+
506
+ if ( isset($this->options['wpml_string_translation']) && function_exists( 'icl_t' ) ) {
507
+ //use WPML
508
+ $viewing_cart = icl_t('WP Menu Cart', 'hover text', 'View your shopping cart');
509
+ $start_shopping = icl_t('WP Menu Cart', 'empty hover text', 'Start shopping');
510
+ $cart_contents = $item_data['cart_contents_count'] .' '. ( $item_data['cart_contents_count'] == 1 ? icl_t('WP Menu Cart', 'item text', 'item') : icl_t('WP Menu Cart', 'items text', 'items') );
511
+ } else {
512
+ //use regular WP i18n
513
+ $viewing_cart = __('View your shopping cart', 'wp-menu-cart');
514
+ $start_shopping = __('Start shopping', 'wp-menu-cart');
515
+ $cart_contents = sprintf(_n('%d item', '%d items', $item_data['cart_contents_count'], 'wp-menu-cart'), $item_data['cart_contents_count']);
516
+ }
517
+
518
+ $this->menu_items['menu']['cart_contents'] = $cart_contents;
519
+
520
+ if ($item_data['cart_contents_count'] == 0) {
521
+ $menu_item_href = apply_filters ('wpmenucart_emptyurl', $item_data['shop_page_url'] );
522
+ $menu_item_title = apply_filters ('wpmenucart_emptytitle', $start_shopping );
523
+ $menu_item_classes = 'wpmenucart-contents empty-wpmenucart-visible';
524
+ } else {
525
+ $menu_item_href = apply_filters ('wpmenucart_fullurl', $item_data['cart_url'] );
526
+ $menu_item_title = apply_filters ('wpmenucart_fulltitle', $viewing_cart );
527
+ $menu_item_classes = 'wpmenucart-contents';
528
+ }
529
+
530
+ $this->menu_items['menu']['menu_item_href'] = $menu_item_href;
531
+ $this->menu_items['menu']['menu_item_title'] = $menu_item_title;
532
+
533
+ if(defined('UBERMENU_VERSION') && (version_compare(UBERMENU_VERSION, '3.0.0') >= 0)){
534
+ $menu_item_classes .= ' ubermenu-target';
535
+ }
536
+
537
+ $menu_item = '<a class="'.$menu_item_classes.'" href="'.$menu_item_href.'" title="'.$menu_item_title.'">';
538
+
539
+ $menu_item_a_content = '';
540
+ if (isset($this->options['icon_display'])) {
541
+ $icon = isset($this->options['cart_icon']) ? $this->options['cart_icon'] : '0';
542
+ $menu_item_icon = '<i class="wpmenucart-icon-shopping-cart-'.$icon.'"></i>';
543
+ $menu_item_a_content .= $menu_item_icon;
544
+ }
545
+
546
+ switch ($this->options['items_display']) {
547
+ case 1: //items only
548
+ $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span>';
549
+ break;
550
+ case 2: //price only
551
+ $menu_item_a_content .= '<span class="amount">'.$item_data['cart_total'].'</span>';
552
+ break;
553
+ case 3: //items & price
554
+ $menu_item_a_content .= '<span class="cartcontents">'.$cart_contents.'</span><span class="amount">'.$item_data['cart_total'].'</span>';
555
+ break;
556
+ }
557
+ $menu_item_a_content = apply_filters ('wpmenucart_menu_item_a_content', $menu_item_a_content, $menu_item_icon, $cart_contents, $item_data );
558
+
559
+ $this->menu_items['menu']['menu_item_a_content'] = $menu_item_a_content;
560
+
561
+ $menu_item .= $menu_item_a_content . '</a>';
562
+
563
+ $menu_item = apply_filters ('wpmenucart_menu_item_a', $menu_item, $item_data, $this->options, $menu_item_a_content, $viewing_cart, $start_shopping, $cart_contents);
564
+
565
+ if( !empty( $menu_item ) ) return $menu_item;
566
+ }
567
+
568
+ public function wpmenucart_ajax() {
569
+ check_ajax_referer( 'wpmenucart', 'security' );
570
+
571
+ $variable = $this->wpmenucart_menu_item();
572
+ echo $variable;
573
+ die();
574
+ }
575
+
576
+ }
577
+
578
+ $wpMenuCart = new WpMenuCart();
579
+
580
+ /**
581
+ * Hide notifications
582
+ */
583
+
584
+ if ( ! empty( $_GET['hide_wpmenucart_shop_check'] ) ) {
585
+ update_option( 'wpmenucart_shop_check', 'hide' );
586
  }