locations.php
53.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // disable direct access.
}
if ( ! class_exists( 'Mega_Menu_Locations' ) ) :
/**
* Handles the Mega Menu > Menu Settings page
*/
class Mega_Menu_Locations {
/**
* Constructor
*
* @since 2.8
*/
public function __construct() {
add_action( 'admin_post_megamenu_add_menu_location', array( $this, 'add_menu_location' ) );
add_action( 'admin_post_megamenu_delete_menu_location', array( $this, 'delete_menu_location' ) );
add_action( 'admin_post_megamenu_save_menu_location', array( $this, 'save_menu_location' ) );
add_action( 'admin_post_megamenu_sandbox', array( $this, 'sandbox' ) );
add_action( 'wp_print_scripts', array( $this, 'sandbox_remove_unnecessary_scripts' ) );
add_action( 'wp_print_styles', array( $this, 'sandbox_remove_unnecessary_styles' ) );
add_filter( 'megamenu_menu_tabs', array( $this, 'add_locations_tab' ), 1 );
add_action( 'megamenu_page_menu_locations', array( $this, 'menu_locations_page' ) );
}
/**
* Add the Menu Locations tab to our available tabs
*
* @param array $tabs array of available tabs.
* @since 2.8
*/
public function add_locations_tab( $tabs ) {
$tabs['menu_locations'] = __( 'Menu Locations', 'megamenu' );
return $tabs;
}
/**
* Add a new menu location.
*
* @since 2.8
*/
public function add_menu_location() {
check_admin_referer( 'megamenu_add_menu_location' );
$locations = get_option( 'megamenu_locations' );
$next_id = $this->get_next_menu_location_id();
$new_menu_location_id = 'max_mega_menu_' . $next_id;
$title = 'Max Mega Menu Location ' . $next_id;
if ( isset( $_POST['title'] ) ) {
$title = esc_attr( wp_unslash( $_POST['title'] ) );
}
$locations[ $new_menu_location_id ] = esc_attr( $title );
update_option( 'megamenu_locations', $locations );
$menu_id = 0;
if ( isset( $_POST['menu_id'] ) ) {
$menu_id = absint( $_POST['menu_id'] );
}
if ( $menu_id > 0 ) {
$locations = get_theme_mod( 'nav_menu_locations' );
$locations[ $new_menu_location_id ] = $menu_id;
set_theme_mod( 'nav_menu_locations', $locations );
}
do_action( 'megamenu_after_add_menu_location' );
$redirect_url = add_query_arg(
array(
'page' => 'maxmegamenu',
'location_added' => 'true',
'location' => $new_menu_location_id,
),
admin_url( 'admin.php' )
);
$this->redirect( $redirect_url );
}
/**
* Delete a menu location.
*
* @since 2.8
*/
public function delete_menu_location() {
check_admin_referer( 'megamenu_delete_menu_location' );
$locations = get_option( 'megamenu_locations' );
$location_to_delete = esc_attr( $_GET['location'] );
if ( isset( $locations[ $location_to_delete ] ) ) {
unset( $locations[ $location_to_delete ] );
update_option( 'megamenu_locations', $locations );
}
do_action( 'megamenu_after_delete_menu_location' );
do_action( 'megamenu_delete_cache' );
$redirect_url = add_query_arg(
array(
'page' => 'maxmegamenu',
'delete_location' => 'true',
),
admin_url( 'admin.php' )
);
$this->redirect( $redirect_url );
}
/**
* Save a menu location
*
* @since 2.0
*/
public function save_menu_location() {
check_admin_referer( 'megamenu_save_menu_location' );
$location = false;
if ( isset( $_POST['location'] ) ) {
$location = esc_attr( $_POST['location'] );
}
if ( $location ) {
$submitted_settings = apply_filters( 'megamenu_submitted_settings_meta', $_POST['megamenu_meta'] );
if ( isset( $submitted_settings[ $location ]['enabled'] ) ) {
$submitted_settings[ $location ]['enabled'] = '1';
}
if ( ! isset( $submitted_settings[ $location ]['unbind'] ) ) {
$submitted_settings[ $location ]['unbind'] = 'disabled';
}
if ( ! isset( $submitted_settings[ $location ]['descriptions'] ) ) {
$submitted_settings[ $location ]['descriptions'] = 'disabled';
}
if ( ! isset( $submitted_settings[ $location ]['prefix'] ) ) {
$submitted_settings[ $location ]['prefix'] = 'disabled';
}
if ( ! get_option( 'megamenu_settings' ) ) {
update_option( 'megamenu_settings', $submitted_settings );
} else {
$existing_settings = get_option( 'megamenu_settings' );
$new_settings = array_merge( $existing_settings, $submitted_settings );
update_option( 'megamenu_settings', $new_settings );
}
do_action( 'megamenu_after_save_settings' );
do_action( 'megamenu_delete_cache' );
}
/* Save custom location description **/
if ( isset( $_POST['custom_location'] ) && is_array( $_POST['custom_location'] ) ) {
$custom_location = array_map( 'sanitize_text_field', $_POST['custom_location'] );
$locations = get_option( 'megamenu_locations' );
$new_locations = array_merge( (array) $locations, $custom_location );
update_option( 'megamenu_locations', $new_locations );
}
$args = array(
'page' => 'maxmegamenu',
'location' => urlencode( $location ),
'save_location' => 'true',
);
if ( ! isset( $submitted_settings[ $location ]['enabled'] ) ) {
unset( $args['location'] );
}
$redirect_url = add_query_arg(
$args,
admin_url( 'admin.php' )
);
$this->redirect( $redirect_url );
}
/**
* Redirect and exit
*
* @since 2.8
*/
public function redirect( $url ) {
wp_redirect( $url );
exit;
}
/**
* Returns the next available menu location ID
*
* @since 2.8
*/
public function get_next_menu_location_id() {
$last_id = 0;
if ( $locations = get_option( 'megamenu_locations' ) ) {
foreach ( $locations as $key => $value ) {
if ( strpos( $key, 'max_mega_menu_' ) !== false ) {
$parts = explode( '_', $key );
$menu_id = end( $parts );
if ( $menu_id > $last_id ) {
$last_id = $menu_id;
}
}
}
}
$next_id = $last_id + 1;
return $next_id;
}
/**
* Content for Menu Locations page
*
* @since 2.8
*/
public function menu_locations_page( $saved_settings ) {
if ( isset( $_GET['add_location'] ) ) {
$this->add_location_page();
return;
}
$all_locations = $this->get_registered_locations();
$enabled_locations = array();
$disabled_locations = array();
foreach ( $all_locations as $id => $description ) {
if ( max_mega_menu_is_enabled( $id ) ) {
$enabled_locations[ $id ] = $description;
} else {
$disabled_locations[ $id ] = $description;
}
}
?>
<div class='menu_settings menu_settings_menu_locations'>
<?php $this->print_messages(); ?>
<h3 class='first'><span class='dashicons dashicons-location'></span><?php esc_html_e( 'Menu Locations', 'megamenu' ); ?></h3>
<table>
<tr>
<td class='mega-name'>
<?php esc_html_e( 'Menu Location Settings', 'megamenu' ); ?>
<div class='mega-description'>
<p><?php esc_html_e( 'This is an overview of the menu locations supported by your theme.', 'megamenu' ); ?></p>
<p><?php esc_html_e( 'Use these options to enable Max Mega Menu and define the behaviour of each menu location.', 'megamenu' ); ?></p>
</div>
</td>
<td class='mega-value mega-vartical-align-top'>
<?php
if ( ! count( $enabled_locations + $disabled_locations ) ) {
echo '<p>';
esc_html_e( 'Add a new menu location below, then display the menu using the Max Mega Menu block, widget or shortcode.', 'megamenu' );
echo '</p>';
}
echo "<div class='mega-enabled-locations'>";
if ( count( $enabled_locations ) ) {
foreach ( $enabled_locations as $location => $description ) {
$this->show_location_accordion_header( $all_locations, $location, $description, $saved_settings );
}
}
echo "</div>";
echo "<div class='mega-disabled-locations'>";
if ( count( $disabled_locations ) ) {
foreach ( $disabled_locations as $location => $description ) {
$this->show_location_accordion_header( $all_locations, $location, $description, $saved_settings );
}
}
echo "</div>";
$add_location_url = esc_url(
add_query_arg(
array(
'page' => 'maxmegamenu',
'add_location' => 'true',
),
admin_url( 'admin.php' )
)
);
echo "<p><a class='button button-secondary mega-add-location' href='{$add_location_url}'>" . esc_html__( 'Add another menu location', 'megamenu' ) . '</a></p>';
?>
</td>
</tr>
</table>
<?php do_action( 'megamenu_menu_locations', $saved_settings ); ?>
</div>
<?php
}
/**
* Output the HTML for a location accordion header
*
* @param array $locations All available locations
* @param array $location the current location
* @param string $description the location description
*/
private function show_location_accordion_header( $locations, $location, $description, $saved_settings ) {
$open_class = ( isset( $_GET['location'] ) && $_GET['location'] === $location ) ? ' mega-accordion-open' : '';
$is_enabled_class = 'mega-location-disabled';
$tooltip = '';
if ( max_mega_menu_is_enabled( $location ) ) {
$is_enabled_class = 'mega-location-enabled';
} elseif ( ! has_nav_menu( $location ) ) {
$is_enabled_class .= ' mega-location-disabled-assign-menu';
}
$has_active_location_class = '';
$active_instance = 0;
if ( isset( $saved_settings[ $location ]['active_instance'] ) ) {
$active_instance = $saved_settings[ $location ]['active_instance'];
} elseif ( isset( $saved_settings['instances'][ $location ] ) ) {
$active_instance = $saved_settings['instances'][ $location ];
}
if ( $active_instance > 0 ) {
$has_active_location_class = ' mega-has-active-location';
$tooltip = __( 'Active for Instance' ) . ' ' . esc_attr( $active_instance );
}
?>
<div class='mega-location <?php echo esc_attr( $is_enabled_class ); ?><?php echo esc_attr( $has_active_location_class ); ?>'>
<div class='mega-accordion-title<?php echo esc_attr( $open_class ); ?>'>
<h4><?php echo esc_html( $description ); ?></h4>
<?php
$tooltip_attr = '';
if ( strlen( $tooltip ) > 0 ) {
$tooltip_attr = " data-tooltip='{$tooltip}'";
}
?>
<span class='mega-tooltip'<?php echo $tooltip_attr; ?>>
<span class='dashicons dashicons-yes'></span>
</span>
<div class='mega-ellipsis'>
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false">
<path d="M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"></path>
</svg>
<ul class='mega-ellipsis-content'>
<li><?php echo $this->assigned_menu_link( $location ); ?></li>
<li><?php echo $this->sandbox_link( $location ); ?></li>
<?php
if ( strpos( $location, 'max_mega_menu_' ) !== false ) {
echo '<li>' . $this->delete_location_link( $location ) . '</li>';
}
?>
</ul>
</div>
</div>
<div class='mega-accordion-content'>
<?php
// if no menu has been assigned to the location
if ( ! has_nav_menu( $location ) ) {
echo "<p class='mega-warning'><span class='dashicons dashicons-warning'></span>";
echo " <a href='" . admin_url( 'nav-menus.php?action=locations' ) . "'>" . esc_html__( 'Assign a menu', 'megamenu' ) . '</a> ';
echo __( 'to this location to enable these options.', 'megamenu' );
echo '</p>';
} else {
$this->show_menu_locations_options( $locations, $location, $description );
}
?>
</div>
</div>
<?php
}
/**
* Content for Menu Locations page
*
* @since 2.8
*/
public function add_location_page() {
?>
<div class='menu_settings menu_settings_add_location'>
<h3 class='first'><?php esc_html_e( 'Add Menu Location', 'megamenu' ); ?></h3>
<form action="<?php echo esc_attr( admin_url( 'admin-post.php' ) ); ?>" method="post">
<input type="hidden" name="action" value="megamenu_add_menu_location" />
<?php wp_nonce_field( 'megamenu_add_menu_location' ); ?>
<table>
<tr>
<td class='mega-name'>
<?php esc_html_e( 'Location Name', 'megamenu' ); ?>
<div class='mega-description'>
<p><?php esc_html_e( 'Give the location a name that describes where the menu will be displayed on your site.', 'megamenu' ); ?></p>
</div>
</td>
<td class='mega-value mega-vartical-align-top'>
<input class='wide' type='text' name='title' required='required' placeholder='<?php esc_attr_e( 'E.g. Footer, Blog Sidebar, Header', 'megamenu' ); ?>' />
</td>
</tr>
<tr>
<td class='mega-name'>
<?php esc_html_e( 'Assign a menu', 'megamenu' ); ?>
<div class='mega-description'>
<p><?php esc_html_e( 'Select a menu to be assigned to this location. This can be changed later using the Appearance > Menus > Manage Location page.', 'megamenu' ); ?></p>
</div>
</td>
<td class='mega-value mega-vartical-align-top'>
<?php
$menus = wp_get_nav_menus();
if ( count( $menus ) ) {
foreach ( $menus as $menu ) {
echo '<div class="mega-radio-row"><input type="radio" id="' . esc_attr( $menu->slug ) . '" name="menu_id" value="' . esc_attr( $menu->term_id ) . '" /><label for="' . esc_attr( $menu->slug ) . '">' . esc_attr( $menu->name ) . '</label></div>';
}
}
echo '<div class="mega-radio-row"><input checked="checked" type="radio" id="0" name="menu_id" value="0" /><label for="0">' . esc_html__( "Skip - I'll assign a menu later", 'megamenu' ) . '</label></div>';
?>
</td>
</tr>
</table>
<?php submit_button( __( 'Add menu location', 'megamenu' ) ); ?>
</form>
</div>
<?php
}
/**
* Display a link showing the menu assigned to the specified location
*
* @param string $location
* @since 2.8
*/
public function assigned_menu_link( $location ) {
$menu_id = $this->get_menu_id_for_location( $location );
if ( $menu_id ) {
return "<a href='" . admin_url( "nav-menus.php?action=edit&menu={$menu_id}" ) . "'><span class='dashicons dashicons-menu-alt2'></span>" . esc_html( $this->get_menu_name_for_location( $location ) ) . '</a>';
} else {
return "<a href='" . admin_url( 'nav-menus.php?action=locations' ) . "'><span class='dashicons dashicons-menu-alt2'></span>" . esc_html__( 'Assign a menu', 'megamenu' ) . '</a>';
}
}
/**
* Display a link showing the menu assigned to the specified location
*
* @param string $location
* @since 2.8
*/
public function sandbox_link( $location ) {
return "<a target='megamenu_sandbox' href='" . admin_url( "admin-post.php?action=megamenu_sandbox&location={$location}" ) . "'><span class='dashicons dashicons-external'></span>" . esc_html__( 'View in Sandbox', 'megamenu' ) . '</a>';
}
/**
* Display a link showing the menu assigned to the specified location
*
* @param string $location
* @since 2.8
*/
public function delete_location_link( $location ) {
$delete_location_url = esc_url(
add_query_arg(
array(
'action' => 'megamenu_delete_menu_location',
'location' => $location,
),
wp_nonce_url( admin_url( 'admin-post.php' ), 'megamenu_delete_menu_location' )
)
);
return "<a class='confirm' href='{$delete_location_url}'><span class='dashicons dashicons-trash'></span>" . esc_html__( 'Delete location', 'megamenu' ) . '</a>';
}
/**
* Remove unnecessary scripts from the sandbox page
*
* @since 2.9
*/
public function sandbox_remove_unnecessary_scripts() {
if ( isset( $_GET['action'] ) && $_GET['action'] === 'megamenu_sandbox' ) {
global $wp_scripts;
$queue_items = $wp_scripts->queue;
$wp_scripts->queue = array();
do_action( 'megamenu_enqueue_scripts' );
}
}
/**
* Remove unnecessary styles from the sandbox page
*
* @since 2.9
*/
public function sandbox_remove_unnecessary_styles() {
if ( isset( $_GET['action'] ) && $_GET['action'] === 'megamenu_sandbox' ) {
global $wp_styles;
$queue_items = $wp_styles->queue;
$wp_styles->queue = array();
do_action( 'megamenu_enqueue_styles' );
}
}
/**
* Content for Sandbox page
*
* @since 2.9
*/
public function sandbox() {
remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
remove_action( 'wp_head', '_admin_bar_bump_cb' );
if ( isset( $_GET['location'] ) ) {
$location = esc_attr( $_GET['location'] );
?>
<!DOCTYPE html>
<html>
<head>
<title>Sandbox: <?php echo $location; ?></title>
<style type='text/css'>
body, html {
margin: 0;
padding: 0;
min-height: 200vh;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
background-image:
linear-gradient(45deg, #eee 25%, transparent 25%),
linear-gradient(135deg, #eee 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #eee 75%),
linear-gradient(135deg, transparent 75%, #eee 75%);
background-size:25px 25px;
background-position:0 0, 12.5px 0, 12.5px -12.5px, 0px 12.5px;
}
#query-monitor-main {
display: none;
}
.menu_wrapper {
max-width: 1280px;
margin: 0 auto;
margin-top: 20px;
}
</style>
<?php wp_head(); ?>
</head>
<body>
<div class='menu_wrapper'>
<?php echo do_shortcode( "[maxmegamenu location={$location}]" ); ?>
</div>
<?php wp_footer(); ?>
</body>
</html>
<?php
}
die();
}
/**
* Content for Menu Location options
*
* @since 2.8
*/
public function show_menu_locations_options( $all_locations, $location, $description ) {
$menu_id = $this->get_menu_id_for_location( $location );
$is_custom_location = strpos( $location, 'max_mega_menu_' ) !== false;
$plugin_settings = get_option( 'megamenu_settings' );
$location_settings = isset( $plugin_settings[ $location ] ) ? $plugin_settings[ $location ] : array();
?>
<form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post">
<input type="hidden" name="action" value="megamenu_save_menu_location" />
<input type="hidden" name="location" value="<?php echo esc_attr( $location ); ?>" />
<?php wp_nonce_field( 'megamenu_save_menu_location' ); ?>
<?php
$settings = apply_filters(
'megamenu_location_settings',
array(
'general' => array(
'priority' => 10,
'title' => __( 'General Settings', 'megamenu' ),
'settings' => array(
'enabled' => array(
'priority' => 10,
'title' => __( 'Enabled', 'megamenu' ),
'description' => __( 'Enable Max Mega Menu for this menu location?', 'megamenu' ),
'settings' => array(
array(
'type' => 'checkbox_enabled',
'key' => 'enabled',
'value' => isset( $location_settings['enabled'] ) ? $location_settings['enabled'] : 0,
),
),
),
'event' => array(
'priority' => 20,
'title' => __( 'Event', 'megamenu' ),
'description' => __( 'Select the event to trigger sub menus', 'megamenu' ),
'settings' => array(
array(
'type' => 'event',
'key' => 'event',
'value' => isset( $location_settings['event'] ) ? $location_settings['event'] : 'hover',
),
),
),
'effect' => array(
'priority' => 30,
'title' => __( 'Effect', 'megamenu' ),
'description' => __( 'Select the sub menu animation type', 'megamenu' ),
'settings' => array(
array(
'type' => 'effect',
'key' => 'effect',
'value' => isset( $location_settings['effect'] ) ? $location_settings['effect'] : 'fade_up',
'title' => __( 'Animation', 'megamenu' ),
),
array(
'type' => 'effect_speed',
'key' => 'effect_speed',
'value' => isset( $location_settings['effect_speed'] ) ? $location_settings['effect_speed'] : '200',
'title' => __( 'Speed', 'megamenu' ),
),
),
),
'effect_mobile' => array(
'priority' => 40,
'title' => __( 'Effect (Mobile)', 'megamenu' ),
'description' => __( 'Choose a style for your mobile menu', 'megamenu' ),
'settings' => array(
array(
'type' => 'effect_mobile',
'key' => 'effect_mobile',
'value' => isset( $location_settings['effect_mobile'] ) ? $location_settings['effect_mobile'] : 'none',
'title' => __( 'Style', 'megamenu' ),
),
array(
'type' => 'effect_speed_mobile',
'key' => 'effect_speed_mobile',
'value' => isset( $location_settings['effect_speed_mobile'] ) ? $location_settings['effect_speed_mobile'] : '200',
'title' => __( 'Speed', 'megamenu' ),
),
),
),
'theme' => array(
'priority' => 50,
'title' => __( 'Theme', 'megamenu' ),
'description' => __( 'Select a theme to be applied to the menu', 'megamenu' ),
'settings' => array(
array(
'type' => 'theme_selector',
'key' => 'theme',
'value' => isset( $location_settings['theme'] ) ? $location_settings['theme'] : 'default',
),
),
),
),
),
'advanced' => array(
'priority' => 25,
'title' => __( 'Advanced', 'megamenu' ),
'settings' => array(
'click_behaviour' => array(
'priority' => 10,
'title' => __( 'Click Event Behaviour', 'megamenu' ),
'description' => __( "Define what should happen when the event is set to 'click'. This also applies to mobiles.", 'megamenu' ),
'settings' => array(
array(
'type' => 'click_behaviour',
'key' => 'click_behaviour',
'value' => $plugin_settings,
),
),
),
'mobile_behaviour' => array(
'priority' => 20,
'title' => __( 'Mobile Sub Menu Behaviour', 'megamenu' ),
'description' => __( 'Define the sub menu toggle behaviour for the mobile menu.', 'megamenu' ),
'settings' => array(
array(
'type' => 'mobile_behaviour',
'key' => 'mobile_behaviour',
'value' => $plugin_settings,
),
),
),
'mobile_state' => array(
'priority' => 20,
'title' => __( 'Mobile Sub Menu Default State', 'megamenu' ),
'description' => __( 'Define the default state of the sub menus when the mobile menu is visible.', 'megamenu' ),
'settings' => array(
array(
'type' => 'mobile_state',
'key' => 'mobile_state',
'value' => $plugin_settings,
),
),
),
'descriptions' => array(
'priority' => 20,
'title' => __( 'Menu Item Descriptions', 'megamenu' ),
'description' => __( 'Enable output of menu item descriptions.', 'megamenu' ),
'settings' => array(
array(
'type' => 'descriptions',
'key' => 'descriptions',
'value' => $plugin_settings,
),
),
),
'unbind' => array(
'priority' => 20,
'title' => __( 'Unbind JavaScript Events', 'megamenu' ),
'description' => __( 'To avoid conflicts with theme menu systems, JavaScript events which have been added to menu items will be removed by default.', 'megamenu' ),
'settings' => array(
array(
'type' => 'unbind',
'key' => 'unbind',
'value' => $plugin_settings,
),
),
),
'prefix' => array(
'priority' => 20,
'title' => __( 'Prefix Menu Item Classes', 'megamenu' ),
'description' => __( "Prefix custom menu item classes with 'mega-'?", 'megamenu' ),
'settings' => array(
array(
'type' => 'prefix',
'key' => 'prefix',
'value' => $plugin_settings,
),
),
),
'container' => array(
'priority' => 20,
'title' => __( 'Container', 'megamenu' ),
'description' => __( 'Use nav or div element for menu wrapper?', 'megamenu' ),
'settings' => array(
array(
'type' => 'container',
'key' => 'container',
'value' => $plugin_settings,
),
),
),
'active_instance' => array(
'priority' => 30,
'title' => __( 'Active Menu Instance', 'megamenu' ),
'info' => array( __( '0: Apply to all instances. 1: Apply to first instance. 2: Apply to second instance', 'megamenu' ) . '…' ),
'description' => __( 'Some themes will output this menu location multiple times on the same page. For example, it may be output once for the main menu, then again for the mobile menu. This setting can be used to make sure Max Mega Menu is only applied to one of those instances.', 'megamenu' ),
'settings' => array(
array(
'type' => 'active_instance',
'key' => 'active_instance',
'value' => $plugin_settings,
),
),
),
),
),
'output_options' => array(
'priority' => 30,
'title' => __( 'Display Options', 'megamenu' ),
'settings' => array(
'location_block' => array(
'priority' => 10,
'title' => __( 'Block (Gutenberg)', 'megamenu' ),
'description' => __( 'Display this menu location in any block supported area.', 'megamenu' ),
'settings' => array(
array(
'type' => 'location_block',
'key' => 'location_block',
'value' => $location,
),
),
),
'location_php_function' => array(
'priority' => 10,
'title' => __( 'PHP Function', 'megamenu' ),
'description' => __( 'Display this menu location in a theme template (usually header.php).', 'megamenu' ),
'settings' => array(
array(
'type' => 'location_php_function',
'key' => 'location_php_function',
'value' => $location,
),
),
),
'location_shortcode' => array(
'priority' => 20,
'title' => __( 'Shortcode', 'megamenu' ),
'description' => __( 'Display this menu location in a post or page.', 'megamenu' ),
'settings' => array(
array(
'type' => 'location_shortcode',
'key' => 'location_shortcode',
'value' => $location,
),
),
),
'location_widget' => array(
'priority' => 30,
'title' => __( 'Widget', 'megamenu' ),
'description' => __( 'Display this menu location in a widget area.', 'megamenu' ),
'settings' => array(
array(
'type' => 'location_widget',
'key' => 'location_widget',
'value' => $location,
),
),
),
),
),
),
$location,
$plugin_settings
);
if ( $is_custom_location ) {
$settings['general']['settings']['location_description'] = array(
'priority' => 15,
'title' => __( 'Location Description', 'megamenu' ),
'description' => __( 'Update the custom location description', 'megamenu' ),
'settings' => array(
array(
'type' => 'location_description',
'key' => 'location_description',
'value' => $description,
),
),
);
}
$initial_version = get_option( 'megamenu_initial_version' );
if ( $initial_version && version_compare( $initial_version, '2.8', '>' ) ) {
//unset( $settings['advanced']['settings']['prefix'] ); // users who started out with 2.8.1+ will not see this option.
}
echo "<div class='mega-accordion-content-wrapper'>";
echo "<h2 class='nav-tab-wrapper'>";
$is_first = true;
uasort( $settings, array( $this, 'compare_elems' ) );
foreach ( $settings as $section_id => $section ) {
if ( $is_first ) {
$active = 'nav-tab-active';
$is_first = false;
} else {
$active = '';
}
echo "<a class='mega-tab nav-tab {$active}' data-tab='mega-tab-content-{$section_id}'>" . esc_html( $section['title'] ) . '</a>';
}
echo '</h2>';
$is_first = true;
foreach ( $settings as $section_id => $section ) {
if ( $is_first ) {
$display = 'block';
$is_first = false;
} else {
$display = 'none';
}
echo "<div class='mega-tab-content mega-tab-content-{$section_id}' style='display: {$display}'>";
if ( $section_id == 'output_options' && ! $is_custom_location ) {
echo "<p class='mega-warning '><span class='dashicons dashicons-warning'></span>" . __( 'This menu location is registered by your theme. Your theme should already include the code required to display this menu location on your site.', 'megamenu' ) . '</p>';
}
echo "<table class='{$section_id}'>";
// order the fields by priority
uasort( $section['settings'], array( $this, 'compare_elems' ) );
foreach ( $section['settings'] as $group_id => $group ) {
echo "<tr class='" . esc_attr( 'mega-' . $group_id ) . "'>";
if ( isset( $group['settings'] ) ) {
echo "<td class='mega-name'>";
if ( isset( $group['icon'] ) ) {
echo "<span class='dashicons dashicons-" . esc_html( $group['icon'] ) . "'></span>";
}
echo esc_html( $group['title'] );
echo "<div class='mega-description'>" . esc_html( $group['description'] ) . '</div>';
echo '</td>';
echo "<td class='mega-value'>";
foreach ( $group['settings'] as $setting_id => $setting ) {
echo "<label class='" . esc_attr( 'mega-' . $setting['key'] ) . "'>";
if ( isset( $setting['title'] ) ) {
echo "<span class='mega-short-desc'>" . esc_html( $setting['title'] ) . '</span>';
}
switch ( $setting['type'] ) {
case 'freetext':
$this->print_location_freetext_option( $location, $setting['key'], $setting['value'] );
break;
case 'textarea':
$this->print_location_textarea_option( $location, $setting['key'] );
break;
case 'checkbox_enabled':
$this->print_location_enabled_option( $location, $setting['key'], $setting['value'] );
break;
case 'event':
$this->print_location_event_option( $location, $setting['key'], $setting['value'] );
break;
case 'effect':
$this->print_location_effect_option( $location, $setting['key'], $setting['value'] );
break;
case 'effect_speed':
$this->print_location_effect_speed_option( $location, $setting['key'], $setting['value'] );
break;
case 'effect_mobile':
$this->print_location_effect_mobile_option( $location, $setting['key'], $setting['value'] );
break;
case 'effect_speed_mobile':
$this->print_location_effect_speed_mobile_option( $location, $setting['key'], $setting['value'] );
break;
case 'theme_selector':
$this->print_location_theme_selector_option( $location, $setting['key'], $setting['value'] );
break;
case 'location_description':
$this->print_location_description_option( $location, $setting['key'], $setting['value'] );
break;
case 'checkbox':
$this->print_location_checkbox_option( $location, $setting['key'], $setting['value'] );
break;
case 'location_block':
$this->print_location_block_option( $location, $setting['key'], $setting['value'] );
break;
case 'location_php_function':
$this->print_location_php_function_option( $location, $setting['value'] );
break;
case 'location_shortcode':
$this->print_location_shortcode_option( $location, $setting['value'] );
break;
case 'location_widget':
$this->print_location_widget_option( $location, $setting['key'], $setting['value'] );
break;
case 'active_instance':
$this->print_active_instance_option( $location, $setting['value'] );
break;
case 'click_behaviour':
$this->print_click_behaviour_option( $location, $setting['value'] );
break;
case 'mobile_behaviour':
$this->print_mobile_behaviour_option( $location, $setting['value'] );
break;
case 'mobile_state':
$this->print_mobile_state_option( $location, $setting['value'] );
break;
case 'container':
$this->print_container_option( $location, $setting['value'] );
break;
case 'descriptions':
$this->print_descriptions_option( $location, $setting['value'] );
break;
case 'unbind':
$this->print_unbind_option( $location, $setting['value'] );
break;
case 'prefix':
$this->print_prefix_option( $location, $setting['value'] );
break;
default:
do_action( "megamenu_print_location_option_{$setting['type']}", $setting['key'], $this->id );
break;
}
echo '</label>';
}
if ( isset( $group['info'] ) ) {
foreach ( $group['info'] as $paragraph ) {
echo "<div class='mega-info'>{$paragraph}</div>";
}
}
echo '</td>';
} else {
echo "<td colspan='2'><h5>{$group['title']}</h5></td>";
}
echo '</tr>';
}
if ( $section_id == 'general' ) {
do_action( 'megamenu_settings_table', $location, $plugin_settings );
}
echo '</table>';
echo '</div>';
}
?>
</div>
<div class='megamenu_submit'>
<?php submit_button( $text = null ); ?>
</div>
</form>
<?php
}
/**
* Return a list of all registed menu locations
*
* @since 2.8
* @return array
*/
public function get_registered_locations() {
$all_locations = get_registered_nav_menus();
// PolyLang - remove auto created/translated menu locations
if ( function_exists( 'pll_default_language' ) ) {
$default_lang = pll_default_language( 'name' );
foreach ( $all_locations as $loc => $description ) {
if ( false !== strpos( $loc, '___' ) ) {
// Remove locations created by Polylang
unregister_nav_menu( $loc );
} else {
// Remove the language name appended to the original locations
register_nav_menu( $loc, str_replace( ' ' . $default_lang, '', $description ) );
}
}
$all_locations = get_registered_nav_menus();
}
$locations = array();
$custom_locations = get_option( 'megamenu_locations' );
if ( is_array( $custom_locations ) ) {
$all_locations = array_merge( $custom_locations, $all_locations );
}
if ( count( $all_locations ) ) {
$megamenu_locations = array();
// reorder locations so custom MMM locations are listed at the bottom
foreach ( $all_locations as $location => $val ) {
if ( strpos( $location, 'max_mega_menu_' ) === false ) {
$locations[ $location ] = $val;
} else {
$megamenu_locations[ $location ] = $val;
}
}
$locations = array_merge( $locations, $megamenu_locations );
}
return $locations;
}
/**
* Returns the menu ID for a specified menu location, defaults to 0
*
* @since 2.8
* @param string $location
*/
private function get_menu_id_for_location( $location ) {
$locations = get_nav_menu_locations();
$id = isset( $locations[ $location ] ) ? $locations[ $location ] : 0;
return $id;
}
/**
* Returns the menu name for a specified menu location
*
* @since 2.8
* @param string $location
*/
private function get_menu_name_for_location( $location ) {
$id = $this->get_menu_id_for_location( $location );
$menus = wp_get_nav_menus();
foreach ( $menus as $menu ) {
if ( $menu->term_id == $id ) {
return $menu->name;
}
}
return false;
}
/**
* Display messages to the user
*
* @since 2.0
*/
public function print_messages() {
if ( isset( $_GET['location_added'] ) ) {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'New Menu Location Created', 'megamenu' ) ?></p>
</div>
<?php
}
if ( isset( $_GET['delete_location'] ) ) {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'Menu Location Deleted', 'megamenu' ) ?></p>
</div>
<?php
}
if ( isset( $_GET['save_location'] ) ) {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'Menu Location Saved', 'megamenu' ) ?></p>
</div>
<?php
}
}
/**
* Print a checkbox option for enabling/disabling MMM for a specific location
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_enabled_option( $location, $key, $value ) {
?>
<input type='checkbox' name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]' <?php checked( $value, '1' ); ?> />
<?php
}
/**
* Print a generic checkbox option
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_checkbox_option( $location, $key, $value ) {
?>
<input type='checkbox' value='true' name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]' <?php checked( $value, 'true' ); ?> />
<?php
}
/**
* Print the active instance option
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_active_instance_option( $location, $plugin_settings ) {
$active_instance = 0;
if ( isset( $plugin_settings[ $location ]['active_instance'] ) ) {
$active_instance = $plugin_settings[ $location ]['active_instance'];
} elseif ( isset( $plugin_settings['instances'][ $location ] ) ) {
$active_instance = $plugin_settings['instances'][ $location ];
}
?>
<input type='text' name='megamenu_meta[<?php echo esc_attr( $location ); ?>][active_instance]' value='<?php echo esc_attr( $active_instance ); ?>' />
<?php
}
/**
* Print the click behaviour option
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_click_behaviour_option( $location, $plugin_settings ) {
$second_click = 'go';
if ( isset( $plugin_settings[ $location ]['second_click'] ) ) {
$second_click = $plugin_settings[ $location ]['second_click'];
} elseif ( isset( $plugin_settings['second_click'] ) ) {
$second_click = $plugin_settings['second_click'];
}
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][second_click]'>
<option value='close' <?php echo selected( $second_click == 'close' ); ?>><?php _e( 'First click will open the sub menu, second click will close the sub menu.', 'megamenu' ); ?></option>
<option value='go' <?php echo selected( $second_click == 'go' ); ?>><?php _e( 'First click will open the sub menu, second click will follow the link.', 'megamenu' ); ?></option>
<option value='disabled' <?php echo selected( $second_click == 'disabled' ); ?>><?php _e( 'First click will follow the link (the arrow must be used to toggle sub menu visiblity).', 'megamenu' ); ?></option>
<select>
<?php
}
/**
* Print the mobile menu behaviour option
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_mobile_behaviour_option( $location, $plugin_settings ) {
$mobile_behaviour = 'standard';
if ( isset( $plugin_settings[ $location ]['mobile_behaviour'] ) ) {
$mobile_behaviour = $plugin_settings[ $location ]['mobile_behaviour'];
} elseif ( isset( $plugin_settings['mobile_behaviour'] ) ) {
$mobile_behaviour = $plugin_settings['mobile_behaviour'];
}
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][mobile_behaviour]'>
<option value='standard' <?php echo selected( $mobile_behaviour == 'standard' ); ?>><?php _e( 'Standard - Open sub menus will remain open until closed by the user.', 'megamenu' ); ?></option>
<option value='accordion' <?php echo selected( $mobile_behaviour == 'accordion' ); ?>><?php _e( 'Accordion - Open sub menus will automatically close when another one is opened.', 'megamenu' ); ?></option>
<select>
<?php
}
/**
* Print the mobile menu behaviour option
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_mobile_state_option( $location, $plugin_settings ) {
$mobile_state = 'collapse_all';
if ( isset( $plugin_settings[ $location ]['mobile_state'] ) ) {
$mobile_state = $plugin_settings[ $location ]['mobile_state'];
}
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][mobile_state]'>
<option value='collapse_all' <?php echo selected( $mobile_state == 'collapse_all' ); ?>><?php _e( 'Collapse all', 'megamenu' ); ?></option>
<option value='expand_all' <?php echo selected( $mobile_state == 'expand_all' ); ?>><?php _e( 'Expand all', 'megamenu' ); ?></option>
<option value='expand_active' <?php echo selected( $mobile_state == 'expand_active' ); ?>><?php _e( 'Expand active parents', 'megamenu' ); ?></option>
<select>
<?php
}
/**
* Print the container option select box
*
* @since 2.9
* @param string $key
* @param string $value
*/
public function print_container_option( $location, $plugin_settings ) {
$container = 'div';
if ( isset( $plugin_settings[ $location ]['container'] ) ) {
$container = $plugin_settings[ $location ]['container'];
}
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][container]'>
<option value='div' <?php echo selected( $container == 'div' ); ?>><div></option>
<option value='nav' <?php echo selected( $container == 'nav' ); ?>><nav></option>
<select>
<?php
}
/**
* Print the checkbox option for enabling menu item descriptions
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_descriptions_option( $location, $plugin_settings ) {
$descriptions = 'disabled';
if ( isset( $plugin_settings[ $location ]['descriptions'] ) ) {
$descriptions = $plugin_settings[ $location ]['descriptions'];
} elseif ( isset( $plugin_settings['descriptions'] ) ) {
$descriptions = $plugin_settings['descriptions'];
}
?>
<input type='checkbox' value='enabled' name='megamenu_meta[<?php echo esc_attr( $location ); ?>][descriptions]' <?php checked( $descriptions, 'enabled' ); ?> />
<?php
}
/**
* Print the checkbox option for prefixing menu items with 'mega-'
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_prefix_option( $location, $plugin_settings ) {
$prefix = 'disabled';
if ( isset( $plugin_settings[ $location ]['prefix'] ) ) {
$prefix = $plugin_settings[ $location ]['prefix'];
} elseif ( isset( $plugin_settings['prefix'] ) ) {
$prefix = $plugin_settings['prefix'];
}
?>
<input type='checkbox' value='enabled' name='megamenu_meta[<?php echo esc_attr( $location ); ?>][prefix]' <?php checked( $prefix, 'enabled' ); ?> />
<?php
}
/**
* Print the checkbox option for the Unbind JavaScript Events option
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_unbind_option( $location, $plugin_settings ) {
$unbind = 'enabled';
if ( isset( $plugin_settings[ $location ]['unbind'] ) ) {
$unbind = $plugin_settings[ $location ]['unbind'];
} elseif ( isset( $plugin_settings['unbind'] ) ) {
$unbind = $plugin_settings['unbind'];
}
?>
<input type='checkbox' value='enabled' name='megamenu_meta[<?php echo esc_attr( $location ); ?>][unbind]' <?php checked( $unbind, 'enabled' ); ?> />
<?php
}
/**
* Print a select box containing all available sub menu trigger events
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_event_option( $location, $key, $value ) {
$options = apply_filters(
'megamenu_event_options',
array(
'hover' => __( 'Hover Intent', 'megamenu' ),
'hover_' => __( 'Hover', 'megamenu' ),
'click' => __( 'Click', 'megamenu' ),
)
);
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]'>
<?php
foreach ( $options as $type => $name ) {
echo "<option value='" . esc_attr( $type ) . "' " . selected( $value, $type, false ) . '>' . esc_html( $name ) . '</option>';
}
echo '</select>';
}
/**
* Print a select box containing all available sub menu animation options
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_effect_option( $location, $key, $value ) {
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]'>
<?php
$selected = strlen( $value ) ? $value : 'fade_up';
$options = apply_filters(
'megamenu_transition_effects',
array(
'disabled' => array(
'label' => __( 'None', 'megamenu' ),
'selected' => $selected == 'disabled',
),
'fade' => array(
'label' => __( 'Fade', 'megamenu' ),
'selected' => $selected == 'fade',
),
'fade_up' => array(
'label' => __( 'Fade Up', 'megamenu' ),
'selected' => $selected == 'fade_up' || $selected == 'fadeUp',
),
'slide' => array(
'label' => __( 'Slide', 'megamenu' ),
'selected' => $selected == 'slide',
),
'slide_up' => array(
'label' => __( 'Slide Up', 'megamenu' ),
'selected' => $selected == 'slide_up',
),
),
$selected
);
foreach ( $options as $key => $value ) {
echo "<option value='" . esc_attr( $key ) . "' " . selected( $value['selected'] ) . '>' . esc_html( $value['label'] ) . '</option>';
}
echo '</select>';
}
/**
* Print a select box containing all available effect speeds (desktop)
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_effect_speed_option( $location, $key, $value ) {
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]'>
<?php
$selected = strlen( $value ) ? $value : '200';
$options = apply_filters(
'megamenu_effect_speed',
array(
'600' => __( 'Slow', 'megamenu' ),
'400' => __( 'Med', 'megamenu' ),
'200' => __( 'Fast', 'megamenu' ),
),
$selected
);
ksort( $options );
foreach ( $options as $key => $value ) {
echo "<option value='" . esc_attr( $key ) . "' " . selected( $selected, $key ) . '>' . esc_html( $value ) . '</option>';
}
echo '</select>';
}
/**
* Print the textbox containing the various mobile menu options
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_effect_mobile_option( $location, $key, $value ) {
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]'>
<?php
$selected = strlen( $value ) ? $value : 'disabled';
$options = apply_filters(
'megamenu_transition_effects_mobile',
array(
'disabled' => array(
'label' => __( 'None', 'megamenu' ),
'selected' => $selected == 'disabled',
),
'slide' => array(
'label' => __( 'Slide Down', 'megamenu' ),
'selected' => $selected == 'slide',
),
'slide_left' => array(
'label' => __( 'Slide Left (Off Canvas)', 'megamenu' ),
'selected' => $selected == 'slide_left',
),
'slide_right' => array(
'label' => __( 'Slide Right (Off Canvas)', 'megamenu' ),
'selected' => $selected == 'slide_right',
),
),
$selected
);
foreach ( $options as $key => $value ) {
echo "<option value='" . esc_attr( $key ) . "' " . selected( $value['selected'] ) . '>' . esc_html( $value['label'] ) . '</option>';
}
echo '</select>';
}
/**
* Print a select box containing all available effect speeds (mobile)
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_effect_speed_mobile_option( $location, $key, $value ) {
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]'>
<?php
$selected = strlen( $value ) ? $value : '200';
$options = apply_filters(
'megamenu_effect_speed_mobile',
array(
'600' => __( 'Slow', 'megamenu' ),
'400' => __( 'Med', 'megamenu' ),
'200' => __( 'Fast', 'megamenu' ),
),
$selected
);
ksort( $options );
foreach ( $options as $key => $value ) {
echo "<option value='" . esc_attr( $key ) . "' " . selected( $selected, $key ) . '>' . esc_html( $value ) . '</option>';
}
echo '</select>';
}
/**
* Print a select box containing all available menu themes
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_theme_selector_option( $location, $key, $value ) {
?>
<select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][<?php echo esc_attr( $key ); ?>]'>
<?php
$style_manager = new Mega_Menu_Style_Manager();
$themes = $style_manager->get_themes();
$selected_theme = strlen( $value ) ? $value : 'default';
foreach ( $themes as $key => $theme ) {
$edit_theme_url = esc_url(
add_query_arg(
array(
'page' => 'maxmegamenu_theme_editor',
'theme' => $key,
),
admin_url( 'admin.php' )
)
);
echo "<option data-url='" . esc_attr($edit_theme_url) . "' value='" . esc_attr( $key ) . "' " . selected( $selected_theme, $key ) . '>' . esc_html( $theme['title'] ) . '</option>';
}
echo '</select>';
echo "<span class='dashicons dashicons-edit megamenu-edit-theme'>";
}
/**
* Print the textbox containing the sample PHP code to output a menu location
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_php_function_option( $location, $value ) {
?>
<textarea readonly="readonly"><?php wp_nav_menu( array( 'theme_location' => '<?php echo esc_attr( $value ); ?>' ) ); ?></textarea>
<?php
}
/**
* Print the textbox containing the sample shortcode to output a menu location
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_shortcode_option( $location, $value ) {
?>
<textarea readonly="readonly">[maxmegamenu location=<?php echo esc_attr( $value ); ?>]</textarea>
<?php
}
/**
* Print the textbox containing instructions on how to display this menu location using a widget
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_widget_option( $location, $value ) {
?>
<textarea readonly="readonly"><?php _e( "Add the 'Max Mega Menu' widget to a widget area.", 'megamenu' ); ?></textarea>
<?php
}
/**
* Print the textbox containing instructions on how to display this menu location using a widget
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_block_option( $location, $value ) {
?>
<textarea readonly="readonly"><?php _e( "Add the 'Max Mega Menu' block to any block enabled area.", 'megamenu' ); ?></textarea>
<?php
}
/**
* Print a standard text input box
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_freetext_option( $location, $key, $value ) {
echo "<input class='" . esc_attr( 'mega-setting-' . $key ) . "' type='text' name='megamenu_meta[$location][$key]' value='" . esc_attr( $value ) . "' />";
}
/**
* Print a text input box allowing the user to change the name of a custom menu location
*
* @since 2.8
* @param string $key
* @param string $value
*/
public function print_location_description_option( $location, $key, $value ) {
echo "<input class='" . esc_attr( 'mega-setting-' . $key ) . " wide' type='text' name='custom_location[$location]' value='" . esc_attr( $value ) . "' />";
}
/**
* Compare array values
*
* @since 2.8
* @param array $elem1
* @param array $elem2
* @return bool
*/
private function compare_elems( $elem1, $elem2 ) {
if ( $elem1['priority'] > $elem2['priority'] ) {
return 1;
}
return 0;
}
}
endif;