functions.php
117 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
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
<?php
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M');
@ini_set( 'max_execution_time', '300' );
require_once __DIR__ . '/vendor/autoload.php';
require_once 'simple_html_dom.php';
add_action('wp_enqueue_scripts', 'theme_broker_enqueue_scripts');
function theme_broker_enqueue_scripts()
{
if (
is_page_template("broker_landing_page.php")
|| is_page_template("broker_pages.php")
|| is_page_template("login-page.php")
|| is_page_template("default.php")
|| is_page_template("general.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("SearchWp.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| is_page_template("marketing_masters.php")
|| get_post_type() == 'notifications'
|| get_post_type() == 'sfwd-courses'
|| get_post_type() == 'sfwd-lessons'
|| get_post_type() == 'sfwd-quiz'
|| get_post_type() == 'badges'
) {
wp_enqueue_style('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css');
wp_enqueue_style('fontawsome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css');
wp_enqueue_style('Material', 'https://fonts.googleapis.com/icon?family=Material+Icons');
wp_enqueue_style('bxslider', get_bloginfo('template_url') . '/styles/vendor/jquery.bxslider.css');
wp_enqueue_script(
'bxslider',
get_bloginfo('template_url') . '/scripts/vendor/jquery.bxslider.js',
[],
"0.0.1",
true
);
wp_enqueue_script('cookies', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js');
wp_enqueue_script('moblie_menu', get_bloginfo('template_url') . '/scripts/moblie_menu.js');
wp_enqueue_script('jQmobile', get_bloginfo('template_url') . '/scripts/vendor/jquery.mobile.custom.min.js');
wp_enqueue_script('colorbox', '//cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.6.4/jquery.colorbox.js');
wp_enqueue_script(
'bootstrap',
'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js',
[],
false,
true
);
// qTip
wp_enqueue_style('qtip', get_bloginfo('template_url') . '/styles/vendor/jquery.qtip.css');
wp_enqueue_script('qtip', get_bloginfo('template_url') . '/scripts/vendor/jquery.qtip.js', [], "0.0.1", true);
wp_enqueue_style('jqdataTables', 'https://cdn.datatables.net/1.10.18/css/dataTables.bootstrap.min.css');
wp_enqueue_script('jqdataTables', 'https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTables', 'https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttons', 'https://cdn.datatables.net/buttons/1.7.0/js/dataTables.buttons.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttonshtml5', 'https://cdn.datatables.net/buttons/1.7.0/js/buttons.html5.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablespdf', 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttonsfonts', 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttonszip', 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js', [], "0.0.1", true);
// Tooltipster
wp_enqueue_style('tooltipster', get_bloginfo('template_url') . '/styles/vendor/tooltipster.bundle.min.css');
wp_enqueue_script(
'tooltipster',
get_bloginfo('template_url') . '/scripts/vendor/tooltipster.bundle.min.js',
[],
"0.0.1",
true
);
wp_enqueue_script('show-more', get_bloginfo('template_url') . '/scripts/show-more.js', [], "0.0.3", true);
wp_enqueue_script('accessibility_script', get_bloginfo('template_url') . '/scripts/accessibility.js', true);
wp_enqueue_style('input_skins', get_bloginfo('template_url') . '/styles/input_skins/all.css', [], "0.0.61");
wp_enqueue_script('icheck', get_bloginfo('template_url') . '/scripts/icheck.min.js', [], "0.0.1", true);
wp_enqueue_script('script', get_bloginfo('template_url') . '/scripts/script.js', [], "0.11", true);
}
if (
is_page_template("broker_landing_page.php")
|| is_page_template("login-page.php")
|| is_page_template("default.php")
|| is_page_template("general.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| get_post_type() == 'notifications'
) {
wp_enqueue_style('global', get_bloginfo('template_url') . '/styles/brokers/landing-page/broker_landing.css', [], "0.0.67");
wp_enqueue_style('broker_new', get_bloginfo('template_url') . '/styles/broker_new.css', [], "0.0.71");
wp_enqueue_script('script', get_bloginfo('template_url') . '/scripts/script.js', [], "0.0.12", true);
wp_enqueue_style('main', get_bloginfo('template_url') . '/styles/main.css', [], "0.0.830");
}
if (
is_page_template("broker_landing_page.php")
|| is_page_template("broker_pages.php")
|| is_page_template("login-page.php")
|| is_page_template("default.php")
|| is_page_template("general.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("SearchWp.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| is_page_template("marketing_masters.php")
|| get_post_type() == 'notifications'
|| get_post_type() == 'sfwd-courses'
|| get_post_type() == 'sfwd-lessons'
|| get_post_type() == 'sfwd-quiz'
|| get_post_type() == 'badges'
) {
wp_enqueue_style('global', get_bloginfo('template_url') . '/styles/brokers/secondary-page/broker.css', array(), '0.0.64');
wp_enqueue_style('broker_new', get_bloginfo('template_url') . '/styles/broker_new.css', [], "0.0.7");
}
if (
is_page_template("broker_landing_page.php")
|| is_page_template("broker_pages.php")
|| is_page_template("login-page.php")
|| is_page_template("default.php")
|| is_page_template("general.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| is_page_template("marketing_masters.php")
|| get_post_type() == 'notifications'
|| get_post_type() == 'sfwd-courses'
|| get_post_type() == 'sfwd-lessons'
|| get_post_type() == 'sfwd-quiz'
|| get_post_type() == 'badges'
) {
wp_enqueue_style('mobile_menu', get_bloginfo('template_url') . '/styles/brokers/mobile/broker_moblie_menu.css');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script('jquery-ui-position');
}
}
add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');
function theme_enqueue_scripts()
{
if (
is_page_template("broker_landing_page.php")
|| is_page_template("broker_pages.php")
|| is_page_template("login-page.php")
|| is_page_template("default.php")
|| is_page_template("general.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| is_page_template("marketing_masters.php")
|| get_post_type() == 'notifications'
|| get_post_type() == 'sfwd-courses'
|| get_post_type() == 'sfwd-lessons'
|| get_post_type() == 'sfwd-quiz'
|| get_post_type() == 'badges'
) {
wp_enqueue_script('require', get_bloginfo('template_url') . '/scripts/vendor/r.js', [], false, true);
}
wp_enqueue_script('global', get_bloginfo('template_url') . '/scripts/optimized.min.js', ['require'], false, true);
wp_enqueue_style('global', get_bloginfo('template_url') . '/styles/global.css');
}
if (is_page_template("badge-share.php"))
{
wp_enqueue_script('sharerbox', get_bloginfo('template_url') . '/scripts/sharerbox.js', [], false, true);
}
add_action('admin_enqueue_scripts', 'enqueue_admin_store_locator_my_scripts');
function wp_disable_emojis()
{
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
add_filter('wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2);
}
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles(){
if ( ! is_user_logged_in() ) {
wp_deregister_style( 'dashicons' );
}
}
add_action('init', 'wp_disable_emojis');
add_filter('the_content', 'attachment_image_link_remove_filter');
function attachment_image_link_remove_filter($content)
{
$content =
preg_replace(
array(
'{<a(.*?)(wp-att|wp-content/uploads)[^>]*><img}',
'{ wp-image-[0-9]*" /></a>}',
),
array('<img', '" />'),
$content
);
return $content;
}
/**
* WP: Unwrap images from <p> tag
* @param $content
* @return mixed
*/
function so226099_filter_p_tags_on_images($content)
{
$content = preg_replace('/<p>\\s*?(<a .*?><img.*?>
<\\/a>| <img.*?>)?\\s*<\\/p>/s', '\1', $content);
return $content;
}
add_filter('the_content', 'so226099_filter_p_tags_on_images'); //Add Featured Image Support add_theme_support('post-thumbnails'); // Clean up the <head>
function removeHeadLinks()
{
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
}
add_action('init', 'removeHeadLinks');
remove_action('wp_head', 'wp_generator');
function register_menus()
{
register_nav_menus(
[
'broker-header' => 'Broker Header',
'broker-header-mobile' => 'Broker Header Mobile',
'broker-menu' => 'Broker Menu',
'broker-footer' => 'Broker Footer',
]
);
}
add_theme_support( 'post-thumbnails' );
add_theme_support('custom-header');
add_action('init', 'register_menus');
function menu_has_children($sorted_menu_items, $args)
{
$last_top = 0;
foreach ($sorted_menu_items as $key => $obj) {
// it is a top lv item?
if (0 == $obj->menu_item_parent) {
// set the key of the parent
$last_top = $key;
} else {
$sorted_menu_items[$last_top]->classes['has-children'] = 'has-children';
}
}
return $sorted_menu_items;
}
add_filter('wp_nav_menu_objects', 'menu_has_children', 10, 2);
function register_widgets()
{
register_sidebar(array(
'name' => 'Footer Sidebar 1',
'id' => 'footer-sidebar-1',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => 'Footer Sidebar 2',
'id' => 'footer-sidebar-2',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => 'Footer Sidebar 3',
'id' => 'footer-sidebar-3',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
}
add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.ui-widget.ui-widget-content{
z-index: 99999;
}
</style>';
}
//end register_widgets()
add_action('widgets_init', 'register_widgets');
/**
* To login with either username or Email address
*/
add_filter('authenticate', 'bainternet_allow_email_login', 20, 3);
/**
* bainternet_allow_email_login filter to the authenticate filter hook, to fetch a username based on entered email
*
* @param obj $user
* @param string $username [description]
* @param string $password [description]
*
* @return boolean
*/
function bainternet_allow_email_login($user, $username, $password)
{
if (is_email($username)) {
$user = get_user_by_email($username);
if ($user) {
$username = $user->user_login;
}
}
return wp_authenticate_username_password(null, $username, $password);
}
add_filter('gettext', 'addEmailToLogin', 20, 3);
/**
* addEmailToLogin function to add email address to the username label
*
* @param string $translated_text translated text
* @param string $text original text
* @param string $domain text domain
*/
function addEmailToLogin($translated_text, $text, $domain)
{
if ("Username" == $translated_text) {
$translated_text .= __(' Or Email');
}
return $translated_text;
}
function send_headers()
{
if (is_user_logged_in() && is_page(399)) {
wp_redirect(get_permalink(6104));
exit;
}
}
add_action('template_redirect', 'send_headers');
/**
* Add login authentication function to use either username or email address
*/
//add_action('wp_authenticate', 'my_front_end_login_fail', 1, 2);
//add_action('wp_login_failed', 'my_front_end_login_fail', 1, 1);
function my_front_end_login_fail($user, $pwd = '')
{
// reasons to stop here
// $user is not empty
// $user is not a wp-error object
// $pwd is not empty
if (!empty($user) && !empty($pwd) && !is_wp_error($user)) {
return false;
}
// if a referer is set, use it. else setup the standard login file
$referrer = (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER']
: home_url('wp-login.php'); // take the safe one, use home_url()
/*
* since PHP5 we can parse an url
* @see http://php.net/manual/en/function.parse-url.php
*
* parse_url( 'http://www.example.com/wp-login.php?login=failed&foo=bar' ) gives us something like that:
*
* array (
* 'scheme' => 'http'
* 'host' => 'www.example.com'
* 'path' => '/wp-login.php'
* 'query' => 'login=failed&foo=bar'
* )
*/
$parsed_url = parse_url($referrer);
/*
* Another fine function is parse_str()
* @see: http://php.net/manual/en/function.parse-str.php
*
* parse( 'login=failed&foo=bar', $query ); results in
* array(
* 'login' => 'failed'
* 'foo' => 'bar'
* )
*
*/
parse_str($parsed_url['query'], $query);
// if there's a valid referrer, and it's not the default log-in screen
if (!strstr($parsed_url['path'], 'wp-login') && !strstr($parsed_url['path'], 'wp-admin')) {
// already has the failed don't appened it again
$redirect_to = $referrer;
if (!isset($query['login']) || 'failed' !== $query['login']) {
// add the failed
// but never ever use a simple string concaternation
// what will result if the referer is 'example.com?foo=bar'?
// it will result in 'example.com?foo=bar?login=failed' OUTCH!
$redirect_to = add_query_arg(['login' => 'failed_empty'], $referrer);
}
// you don't want to redirect to google or somewhere else, you want to redirect to your
// own domain. so use wp_safe_redirect()
wp_safe_redirect($redirect_to);
exit;
}
}
/**
* Redirect always homepage after logout
*/
add_filter('logout_url', 'projectivemotion_logout_home', 10, 2);
function projectivemotion_logout_home($logouturl, $redir)
{
$redir = get_option('siteurl');
return $logouturl . '&redirect_to=' . urlencode($redir);
}
/**
* Redirect login page to custom login page
*/
function redirect_login_page()
{
// Store for checking if this page equals wp-login.php
$page_viewed = basename($_SERVER['SCRIPT_NAME']);
// Where we want them to go
$login_page = site_url('/broker-login');
// Two things happen here, we make sure we are on the login page
// and we also make sure that the request isn't coming from a form
// this ensures that our scripts & users can still log in and out.
if ($page_viewed == "wp-login.php" && $_GET["action"] == 'rp') {
$key = $_GET["key"];
$login = $_GET["login"];
$password_reset = site_url('/password-reset/?action=rp&key=' . $key . '&login=' . $login);
// And away they go...
wp_redirect($password_reset);
exit();
}
if ($page_viewed == "wp-login.php" && $_GET["action"] == 'lostpassword') {
$lost = site_url('/lost-password/');
// And away they go...
wp_redirect($lost);
exit();
}
if ($page_viewed == "wp-login.php" && $_GET["action"] == 'logout') {
wp_logout();
}
if ($page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
// And away they go...
wp_redirect($login_page);
exit();
}
}
//add_action('init', 'redirect_login_page');
function my_login_redirect($redirect_to, $request, $user)
{
//is there a user to check?
global $user;
if (isset($user->roles) && is_array($user->roles)) {
//check for admins
if (in_array("administrator", $user->roles)) {
// redirect them to the default place
// return home_url();
return $redirect_to; //get rid of this for testing purposes
} else {
return $redirect_to;
}
} else {
return $redirect_to;
}
}
//add_filter("login_redirect", "my_login_redirect", 10, 3);
// Change from email address
//add_filter('wp_mail_from', 'custom_wp_mail_from');
function custom_wp_mail_from($email)
{
//Make sure the email is from the same domain
//as your website to avoid being marked as spam.
return 'lost_password@thecommonwell.ca';
}
add_filter('mandrill_payload', 'sendEmailThroughMandrillSubaccount', 100);
function sendEmailThroughMandrillSubaccount(array $message)
{
$message['subaccount'] = 'Thecommonwell';
return $message;
}
add_filter('wp_mail_from_name', 'custom_wp_mail_from_name');
function custom_wp_mail_from_name($original_email_from)
{
return 'The Commonwell';
}
add_action('wp_ajax_nopriv_ajax-callback', 'ajax_callback');
add_action('wp_ajax_ajax-callback', 'ajax_callback');
// Disable password reset function
function remove_lostpassword_text($text)
{
if ($text == 'Lost your password?') {
$text = '';
}
return $text;
}
add_filter('gettext', 'remove_lostpassword_text');
/**
* Add custom user profile fields
*/
add_action('show_user_profile', 'add_custom_fields');
add_action('edit_user_profile', 'add_custom_fields');
add_action("user_new_form", "add_custom_fields");
define('WPSL_MARKER_URI', dirname(get_bloginfo('template_url')) . '/commonwell-corp/images/');
function add_custom_fields($user)
{
$brokerList = getBrokerageList();
$userBrokerId = esc_attr(get_the_author_meta('broker_id', $user->ID));
?>
<div class="broker-group">
<h3>Broker</h3>
<table class="form-table form-broker_id">
<tr class="form-field">
<th><label for="broker_id">Brokerage <span class="description">(required)</span></label></th>
<td>
<input type="text" style="position: absolute; opacity: 0; z-index: -1;" />
<select name="broker_id" id="broker_id">
<option value="">Select Broker</option>
<?php foreach ($brokerList as $broker): ?>
<?php
$isSelected = $userBrokerId === $broker['broker_id'] ? 'selected="selected"' : '';
?>
<option value="<?php echo $broker['broker_id']; ?>" <?php echo $isSelected; ?>><?php echo $broker['brokerage']; ?></option>
<?php endforeach;?>
</select>
</td>
</tr>
</table>
</div>
<?php
}
/**
* Save additional profile field
*/
add_action('personal_options_update', 'save_custom_fields');
add_action('edit_user_profile_update', 'save_custom_fields');
add_action('user_register', 'save_custom_fields');
function save_custom_fields($user_id)
{
# again do this only if you can
if (!current_user_can('administrator', $user_id)) {
return false;
}
$brokerList = getBrokerageList();
$brokerage = false;
foreach ($brokerList as $broker) {
if ($_POST['broker_id'] == $broker['broker_id']) {
$brokerage = $broker['brokerage'];
}
}
if ($brokerage) {
update_user_meta($user_id, 'brokerage', sanitize_text_field($brokerage));
}
update_user_meta($user_id, 'broker_id', sanitize_text_field($_POST['broker_id']));
}
add_action('admin_footer-user-new.php', 'addUAMField');
/**
* Add UAM field into a user registration form
*
* @param $user
*/
function addUAMField($user)
{
try {
global $userAccessManager, $wpdb;
$aUamUserGroups = $userAccessManager->getAccessHandler()->getUserGroups();
} catch(Throwable $e) {
error_log($e->getMessage());
return;
}
?>
<h3><?php echo TXT_UAM_GROUPS; ?></h3>
<table class="form-table">
<tbody>
<tr>
<th>
<label for="usergroups"><?php echo TXT_UAM_SET_UP_USERGROUPS; ?></label>
</th>
<td>
<input type="hidden" name="uam_update_groups" value="true" />
<ul class="uam_group_selection">
<?php
if (
!isset($sGroupsFormName)
|| $sGroupsFormName === null
) {
$sGroupsFormName = 'uam_usergroups';
}
foreach ($aUamUserGroups as $oUamUserGroup) {
$sAddition = '';
$sAttributes = '';
?>
<li>
<input type="checkbox" id="<?php echo $sGroupsFormName; ?>-<?php echo $oUamUserGroup->getId(); ?>" <?php echo $sAttributes; ?> value="<?php echo $oUamUserGroup->getId(); ?>" name="<?php echo $sGroupsFormName; ?>[]" data-name="<?php echo strtolower($oUamUserGroup->getGroupName()); ?>" />
<label for="<?php echo $sGroupsFormName; ?>-<?php echo $oUamUserGroup->getId(); ?>" class="selectit" style="display:inline;">
<?php echo $oUamUserGroup->getGroupName() . $sAddition; ?>
</label>
<a class="uam_group_info_link">(<?php echo TXT_UAM_INFO; ?>)</a>
<!-- Tool tip content-->
<div class="tooltip">
<ul class="uam_group_info">
<?php
global $userAccessManager;
foreach ($userAccessManager->getAccessHandler()->getAllObjectTypes() as $sCurObjectType) {
if (isset($aUserGroups[$oUamUserGroup->getId()])) {
$aRecursiveMembership = $aUserGroups[$oUamUserGroup->getId()]->getRecursiveMembershipForObjectType(
$sObjectType,
$iObjectId,
$sCurObjectType
);
if (count($aRecursiveMembership) > 0) {
?>
<li class="uam_group_info_head">
<?php echo constant(
'TXT_UAM_GROUP_MEMBERSHIP_BY_' . strtoupper($sCurObjectType)
); ?>:
<ul>
<?php
foreach ($aRecursiveMembership as $oObject) {
?>
<li class="recusiveTree"><?php echo walkPath(
$oObject,
$sCurObjectType
); ?></li>
<?php
}
?>
</ul>
</li>
<?php
}
}
}
?>
<li class="uam_group_info_head"><?php echo TXT_UAM_GROUP_INFO; ?>:
<ul>
<li><?php echo TXT_UAM_READ_ACCESS; ?>:
<?php
if ($oUamUserGroup->getReadAccess() == "all") {
echo TXT_UAM_ALL;
} elseif ($oUamUserGroup->getReadAccess() == "group") {
echo TXT_UAM_ONLY_GROUP_USERS;
}
?>
</li>
<li><?php echo TXT_UAM_WRITE_ACCESS; ?>:
<?php
if ($oUamUserGroup->getWriteAccess() == "all") {
echo TXT_UAM_ALL;
} elseif ($oUamUserGroup->getWriteAccess() == "group") {
echo TXT_UAM_ONLY_GROUP_USERS;
}
?>
</li>
<li>
<?php echo TXT_UAM_GROUP_ROLE; ?>: <?php
if ($oUamUserGroup->getObjectsFromType('role')) {
$sOut = '';
foreach ($oUamUserGroup->getObjectsFromType(
'role'
) as $sKey => $sRole) {
$sOut .= trim($sKey) . ', ';
}
echo rtrim($sOut, ', ');
} else {
echo TXT_UAM_NONE;
}
?>
</li>
</ul>
</li>
</ul>
</div>
</li>
<?php
}
?>
</ul>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action('user_register', 'saveUAMField');
/**
* Save the UAM field value
*
* @return bool
*/
function saveUAMField($user_id)
{
try {
# again do this only if you can
if (!current_user_can('administrator', $user_id)) {
return false;
}
global $userAccessManager;
$uamAccessHandler = $userAccessManager->getAccessHandler();
$aUserGroups = null;
$aFormData = array();
if (isset($_POST['uam_update_groups'])) {
$aFormData = $_POST;
} elseif (isset($_GET['uam_update_groups'])) {
$aFormData = $_GET;
}
if (isset($aFormData['uam_update_groups'])) {
if ($aUserGroups === null) {
$aUserGroups = isset($aFormData['uam_user_groups']) ? $aFormData['uam_user_groups'] : array();
}
foreach ($aUserGroups as $key => $value) {
if (isset($aUserGroups[$key]['id'])) {
$uamUserGroups = $uamAccessHandler->getUserGroups();
$uamUserGroup = $uamUserGroups[$key];
$uamUserGroup->addObject('_user_', $user_id);
$uamUserGroup->save();
}
}
}
} catch(Throwable $e) {
error_log("saveUAMField Error " . $e->getMessage() . ", for user_id = " . $user_id . " while updating group(s) " . $_REQUEST['uam_update_groups']);
}
}
/**
* Remove roles
*
* Author, Editor, Contributor
*
*/
$wp_roles = new WP_Roles();
$wp_roles->remove_role("author");
$wp_roles->remove_role("editor");
$wp_roles->remove_role("contributor");
/**
* Admin init function
*/
add_action('admin_footer-user-new.php', 'setUserProfileLogicNewUser');
add_action('admin_footer-user-edit.php', 'setUserProfileLogicEditUser');
function setUserProfileLogicNewUser($hook)
{
?>
<script>
(function($) {
var addNewUserForm = $('#createuser');
var roleSelectBox = $('#role');
var brokerIdSelectBox = $('#broker_id');
var brokerIdFormField = $('.form-broker_id .form-field');
var brokerCheckbox = $('.uam_group_selection input[type="checkbox"][id="uam_usergroups-1"]');
var brokerGroup = $('.broker-group');
// Role select
roleSelectBox.on(
'change',
function(e) {
var userRole = e.target.value;
// If broker is selected
// Check "Broker" user group
if (userRole === 'subscriber') {
brokerCheckbox[0].checked = true;
brokerGroup.slideDown(100);
} else {
brokerCheckbox[0].checked = false;
brokerGroup.slideUp(100);
brokerIdSelectBox[0].selectedIndex = 0;
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
}
}
).trigger('change');
// Organization
brokerIdSelectBox.on('change', function() {
var userRole = roleSelectBox.val();
// If Broker is selected, org is empty
// Show error message
if (userRole === 'subscriber') {
if (brokerIdSelectBox[0].selectedIndex !== 0) {
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
}
}
});
addNewUserForm.on('submit', function(e) {
var userRole = roleSelectBox.val();
// If Broker is selected, org is empty
// Show error message
if (userRole === 'subscriber') {
if (brokerIdSelectBox[0].selectedIndex == 0) {
brokerIdFormField.addClass('form-required');
} else {
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
}
} else {
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
}
});
})(jQuery);
</script>
<?php
}
function setUserProfileLogicEditUser($hook)
{
?>
<script>
(function($) {
var addEditUserForm = $('#your-profile');
var roleSelectBox = $('#role');
var brokerCheckbox = $('.uam_group_selection input[type="checkbox"][id="uam_usergroups-1"]');
var brokerIdFormField = $('.form-broker_id .form-field');
var brokerGroup = $('.broker-group');
var brokerSelectBox = $('#broker_id');
roleSelectBox.on(
'change',
function(e) {
var targetValue = e.target.value;
// If broker is selected
// Check "Broker" user group
if (targetValue === 'subscriber') {
brokerCheckbox[0].checked = true;
brokerGroup.slideDown(100);
} else {
brokerCheckbox[0].checked = false;
brokerGroup.slideUp(100);
brokerSelectBox[0].selectedIndex = 0;
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
}
}
).trigger('change');
// Organization
brokerSelectBox.on('change', function() {
var userRole = roleSelectBox.val();
// If Broker is selected, org is empty
// Show error message
if (userRole === 'subscriber') {
if (brokerSelectBox[0].selectedIndex !== 0) {
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
}
}
});
addEditUserForm.on('submit', function(e) {
var userRole = roleSelectBox.val();
// If Broker is selected, org is empty
// Show error message
if (userRole === 'subscriber') {
if (brokerSelectBox[0].selectedIndex == 0) {
brokerIdFormField.addClass('form-required');
brokerIdFormField.addClass('form-invalid');
return false;
} else {
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
return true;
}
} else {
brokerIdFormField.removeClass('form-required');
brokerIdFormField.removeClass('form-invalid');
return true;
}
});
})(jQuery);
</script>
<?php
}
add_action('init', 'handle_preflight');
function handle_preflight()
{
header("Access-Control-Allow-Origin: * ");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
// header("Access-Control-Allow-Credentials: true");
if ('OPTIONS' == $_SERVER['REQUEST_METHOD']) {
status_header(200);
exit();
}
}
add_role(
'cwl_staff',
__(
'CWL Staff'
),
array(
'read' => true, // Allows user to read
'create_posts' => true, // Allows user to create new posts
'edit_posts' => true, // Allows user to edit their own posts
)
);
add_action('show_user_profile', 'addCommonwellStaffInfo');
add_action('edit_user_profile', 'addCommonwellStaffInfo');
function addCommonwellStaffInfo($user)
{
$user_id = $_GET['user_id'];
if (user_can($user_id, 'cwl_staff')) {
$CommonwellTitle = get_user_meta($user_id, 'Commonwelltitle', true);
$CommonwellPersonalizedMesssage = get_user_meta($user_id, 'CommonwellPersonalizedMesssage', true);
$CommonwellTel = get_user_meta($user_id, 'CommonwellTel', true);
$VideoLink = get_user_meta($user_id, 'VideoLink', true);
?>
<h3>Commonwell Staff</h3>
<table class="form-table">
<tr>
<th><label for="organization_profile">Commonwell Title</label></th>
<td><input id="Commonwelltitle" type="text" name="Commonwelltitle" value="<?php echo $CommonwellTitle; ?>" class="regular-text" /></td>
</tr>
<tr>
<th><label for="organization_profile">Personalized Messsage</label></th>
<td><textarea id="CommonwellPersonalizedMesssage" name="CommonwellPersonalizedMesssage" />
<?php echo $CommonwellPersonalizedMesssage; ?>
</textarea></td>
</tr>
<tr>
<th><label for="organization_profile">Phone</label></th>
<td><input type='tel' id="CommonwellTel" name="CommonwellTel" class="regular-text" pattern='[\+]\d{1}[\(]\d{3}[\)-]\d{3}[\-]\d{4} [\ext]\d{3}' value=" <?php echo $CommonwellTel; ?>" title='Phone Number (Format: +9(999)-999-9999 ext 999)'>
(Format: +9(999)-999-9999 ext 999)
</td>
</tr>
<tr>
<th><label for="organization_profile">Video Link</label></th>
<td><input id="VideoLink" type="text" name="VideoLink" value="<?php echo $VideoLink; ?>" class="regular-text" /></td>
</tr>
</table>
<?php
}
}
/**
* Save additional profile field
*/
add_action('personal_options_update', 'saveCommonwellStaffInfo');
add_action('edit_user_profile_update', 'saveCommonwellStaffInfo');
function saveCommonwellStaffInfo($user_id)
{
update_user_meta($user_id, 'Commonwelltitle', sanitize_text_field($_POST['Commonwelltitle']));
update_user_meta(
$user_id,
'CommonwellPersonalizedMesssage',
sanitize_text_field($_POST['CommonwellPersonalizedMesssage'])
);
update_user_meta($user_id, 'CommonwellTel', sanitize_text_field($_POST['CommonwellTel']));
update_user_meta($user_id, 'VideoLink', sanitize_text_field($_POST['VideoLink']));
}
add_action('show_user_profile', 'my_show_extra_profile_fields');
add_action('edit_user_profile', 'my_show_extra_profile_fields');
function my_show_extra_profile_fields($user)
{
$user_id = $_GET['user_id'];
if (user_can($user_id, 'cwl_staff')) {
include_once $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-config.php';
global $wpdb;
$query = get_option('broker_list') ? unserialize(get_option('broker_list')) : [];
foreach ($query as $key => $row) {
$brokers[$row['id']]['id'] = $row['id'];
$brokers[$row['id']]['broker_id'] = $row['broker_id'];
$brokers[$row['id']]['name'] = $row['brokerage'];
}
$brokersSelected = 'select broker_id from wp_broker_staff where staff_id =' . $user_id;
foreach ($wpdb->get_results($brokersSelected) as $row) {
$brokersPicked[] = $row->broker_id;
unset($brokers[$row->broker_id]);
}
;
$brokersLeft = $brokers;
?>
<table class="form-table">
<form>
<fieldset>
<tr>
<th><label>Brokers Served</label></th>
</tr>
<tr>
<td width="30%" align="center">
YOUR LIST
<select style="width:100%;" name="brokerselected[]" id="select-to" multiple="multiple" size="5">
<?php
foreach ($query as $key => $row) {
//error_log(print_r($brokerPicked,true));
if (in_array($row['broker_id'], $brokersPicked)) {
?>
<option selected="selected" value="<?php echo $row['broker_id']; ?>"><?php echo $row['brokerage']; ?></option>
<?php }
}?>
</select>
</td>
<td width="20%">
<a href="JavaScript:void(0);" style="float:left;" id="btn-remove">Remove »</a>
<a href="JavaScript:void(0);" style="float:right;" id="btn-add">« Add </a>
</td>
<td width="30%" align="center">
BROKERS
<select style="width:100%;" name="selectfrom" id="select-from" multiple size="5">
<?php foreach ($brokersLeft as $brokerLeft) {?>
<option value="<?php echo $brokerLeft['broker_id']; ?>"><?php echo $brokerLeft['name']; ?></option>
<?php }?>
</select>
<td>
</tr>
</fieldset>
</form>
</td>
</tr>
</table>
<script>
jQuery(document).ready(
function($) {
$('#btn-add').click(
function() {
$('#select-from option:selected').each(
function() {
$('#select-to').append("<option selected='selected' value='" + $(this).val() + "'>" + $(this).text() + "</option>");
$(this).remove();
}
);
}
);
$('#btn-remove').click(
function() {
$('#select-to option:selected').each(
function() {
$('#select-from').append("<option value='" + $(this).val() + "'>" + $(this).text() + "</option>");
$(this).remove();
}
);
}
);
$(document).on(
'submit', '#your-profile',
function() {
$('#select-to option').each(
function() {
$(this).attr("selected", 1);
}
);
}
);
}
);
</script>
<?php }
}
add_action('personal_options_update', 'my_save_extra_profile_fields');
add_action('edit_user_profile_update', 'my_save_extra_profile_fields');
function my_save_extra_profile_fields()
{
global $wpdb;
global $user_id;
$wpdb->delete(
'wp_broker_staff',
array('staff_id' => $user_id)
);
foreach ($_POST['brokerselected'] as $brokerselected) {
//error_log($brokerselected);
$wpdb->insert(
'wp_broker_staff',
array(
'staff_id' => $user_id,
'broker_id' => $brokerselected,
)
);
}
}
// Our custom post type function
function create_posttype()
{
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x('Notifications', 'Post Type General Name', 'commonwell-corp'),
'singular_name' => _x('Notification', 'Post Type Singular Name', 'commonwell-corp'),
'menu_name' => __('Notifications', 'commonwell-corp'),
'parent_item_colon' => __('Parent Notification', 'commonwell-corp'),
'all_items' => __('All Notifications', 'commonwell-corp'),
'view_item' => __('View Notification', 'commonwell-corp'),
'add_new_item' => __('Add New Notification', 'commonwell-corp'),
'add_new' => __('Add New', 'commonwell-corp'),
'edit_item' => __('Edit Notification', 'commonwell-corp'),
'update_item' => __('Update Notification', 'commonwell-corp'),
'search_items' => __('Search Notification', 'commonwell-corp'),
'not_found' => __('Not Found', 'commonwell-corp'),
'not_found_in_trash' => __('Not found in Trash', 'commonwell-corp'),
);
// Set other options for Custom Post Type
$args = array(
'label' => __('notifications', 'twentythirteen'),
'description' => __('notification news and reviews', 'twentythirteen'),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array(
'title',
'editor',
'excerpt',
'author',
'thumbnail',
'comments',
'featured_image',
'set_featured_image',
'use_featured_image',
'revisions',
'custom-fields',
),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array('genres'),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
// Registering your Custom Post Type
register_post_type('notifications', $args);
}
// Hooking up our function to theme setup
add_action('init', 'create_posttype');
/*
* Creating a function to create our CPT
*/
add_action('after_setup_theme', 'ja_theme_setup');
function ja_theme_setup()
{
add_theme_support('post-thumbnails', array('post', 'notifications'));
}
function custom_post_type()
{
// Set UI labels for Custom Post Type
$labelsNewsandEvents = array(
'name' => _x('News', 'Post Type General Name', 'commonwell-corp'),
'singular_name' => _x('News', 'Post Type Singular Name', 'commonwell-corp'),
'menu_name' => __('Notifications', 'commonwell-corp'),
'parent_item_colon' => __('Parent News ', 'commonwell-corp'),
'all_items' => __('All News', 'commonwell-corp'),
'view_item' => __('View News', 'commonwell-corp'),
'add_new_item' => __('Add New News', 'commonwell-corp'),
'add_new' => __('Add New', 'commonwell-corp'),
'edit_item' => __('Edit News', 'commonwell-corp'),
'update_item' => __('Update News', 'commonwell-corp'),
'search_items' => __('Search News', 'commonwell-corp'),
'not_found' => __('Not Found', 'commonwell-corp'),
'not_found_in_trash' => __('Not found in Trash', 'commonwell-corp'),
);
// Set other options for Custom Post Type
$labelsNewsandEvents = array(
'label' => __('news', 'twentythirteen'),
'description' => __('notification news and reviews', 'twentythirteen'),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array(
'title',
'editor',
'excerpt',
'author',
'thumbnail',
'comments',
'revisions',
'custom-fields',
),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array('genres'),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
// Registering your Custom Post Type
register_post_type('new_and_events', $args);
}
global $post;
if ($post->type == 'Notifications') {
get_template_part(get_bloginfo('template_url') . '/broker_pages.php');
error_log('tre');
}
/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action('init', 'custom_post_type', 0);
function clean_custom_menus()
{
$menu_name = 'broker-menu'; // specify custom menu slug
$menu_list = '';
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
$menu = wp_get_nav_menu_object($locations[$menu_name]);
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list = '<nav class="col-sm-smallMenu">' . "\n";
$colCount = count($menu_items);
$colCount = 12 / $colCount;
if ($colCount == '2.4') {
$colCount = '5ths';
}
foreach ((array) $menu_items as $key => $menu_item) {
$title = $menu_item->title;
$url = $menu_item->url;
$classes = '';
// Getting the current post details
global $post;
// Checking if post ID exist...
if (isset($post->ID)) {
// Get the queried object and sanitize it
$current_page = sanitize_post($GLOBALS['wp_the_query']->get_queried_object());
// Get the page slug
$slug = $current_page->post_name;
// Getting the URL of the menu item
$menu_slug = strtolower(trim($url));
// If the menu item URL contains the current post types slug add the current-menu-item class
if (strpos($menu_slug, $slug) !== false) {
$classes .= 'current-menu-item';
}
}
foreach ($menu_item->classes as $class) {
$classes .= ' ' . $class;
}
//error_log(print_r( $menu_item,true));
$menu_list .= '<a href="' . $url . '" id="' . $post_title . '" class="col-xs-12 col-sm-' . $colCount . ' col-md-' . $colCount . ' tab_menu ' . $classes . ' ' . $menu_item->custom . '"><img src="' . $menu_item->custom_image . '"/><span class="tab_label">' . $title . '</span><span class="selected-arrow"></span></a>';
}
$menu_list .= "\t\t\t" . '</nav>' . "\n";
} else {
// $menu_list = '<!-- no list defined -->';
}
echo $menu_list;
}
function clean_custom_moblie_menus()
{
$current_user = wp_get_current_user();
$menu_name = 'broker-menu'; // specify custom menu slug
$menu_list = '';
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
$menu = wp_get_nav_menu_object($locations[$menu_name]);
$menu_items = wp_get_nav_menu_items($menu->term_id);
$classes = '';
$menu_list = '<nav id="mainNav" class="navbar col-sm-mobile navbar-default navbar-fixed-top">
<div class="container">
<div class="mobile_collapse" id="mobile_collapse" >
<ul class="nav navbar-nav navbar-right">
' . "\n";
foreach ((array) $menu_items as $key => $menu_item) {
$title = $menu_item->title;
$url = $menu_item->url;
foreach ($menu_item->classes as $classe) {
$classes .= ' ' . $classe;
}
$menu_list .= '<li><a href="' . $url . '" class="col-xs-12 col-sm-12 col-md-12 mobile_menu ' . $classes . ' ' . $menu_item->custom . '"><img src="' . $menu_item->custom_image . '"/><span class="tab_label">' . $title . '</span></a></li>';
}
$menu_list .= '</ul>';
$menu_name = 'broker-header-mobile';
$menu = wp_get_nav_menu_object($locations[$menu_name]);
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list .= '<ul class="header_background">';
foreach ((array) $menu_items as $key => $menu_item) {
$title = $menu_item->title;
$url = $menu_item->url;
$menu_list .= '<li><a href="' . $url . '">' . $title . '</a></li>';
}
$menu_list .= '</ul>';
$menu_list .= '<ul class="header_background2 grad_background"><li><h5>Account</h5></il><li>' . get_user_meta(
$current_user->ID,
'first_name',
true
) . ' ' . get_user_meta(
$current_user->ID,
'last_name',
true
) . '</li><li>' . $current_user->user_email . '</li></ul>';
$menu_list .= '<div class="arrow-up"></div>
</div>
<div id="seacrh_mobile">' . do_shortcode(
'[searchwp_search_form target="' . get_option('home') . '/search-results/" engine="default" var="searchvar" ]'
) . '
<div class="arrow-up-right"></div>
</div>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" onClick="toggle_mobile_menu();" >
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="' . get_option('home') . '/broker-landing-page/">
<img id="mobile-logo" src="' . get_bloginfo('template_url') . '/images/Commonwell-logo.svg" alt="Commonwell Mutual Insurance Group logo" />
</a>
<button onClick="showSearch();" type="button" class="search_icon_button" ><i class="search_icon material-icons"></i></button>
</div>
<div class="broker_mobile_hello">
<span class="username" style="text-transform:uppercase;">HI "' . esc_html($current_user->user_firstname) . '"</span><span class="greating"> - How can we help? <i id="tooltipmobile" class="material-icons" style="cursor: help;color:#229cde;top: 7px;position: relative; font-size: 20px;"></i></span>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
</div>
<!-- /.container-fluid -->
</nav>
' . "\n";
} else {
// $menu_list = '<!-- no list defined -->';
}
echo $menu_list;
}
function enable_extended_upload($mime_types = array())
{
// The MIME types listed here will be allowed in the media library.
// You can add as many MIME types as you want.
$mime_types['gz'] = 'application/x-gzip';
$mime_types['zip'] = 'application/zip';
$mime_types['rtf'] = 'application/rtf';
$mime_types['ppt'] = 'application/mspowerpoint';
$mime_types['ps'] = 'application/postscript';
$mime_types['flv'] = 'video/x-flv';
$mime_types['svg'] = 'image/svg+xml';
$mime_types['xlsm'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
// If you want to forbid specific file types which are otherwise allowed,
// specify them here. You can add as many as possible.
unset($mime_types['exe']);
unset($mime_types['bin']);
return $mime_types;
}
add_filter('upload_mimes', 'enable_extended_upload');
add_action('admin_menu', 'add_broker_options');
function add_broker_options()
{
add_options_page('Broker Options', 'Broker Options', 'manage_options', 'functions', 'broker_options');
add_settings_field('Info Message', 'Info Message', 'broker_info_message', __FILE__, 'main_section');
add_settings_field('No Team Meassage', 'No Team Meassage', 'no_team_message', __FILE__, 'main_section');
}
function broker_options()
{
?>
<div class="wrap">
<h2>Broker Options</h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options')?>
<p><strong>Info Message</strong><br />
<textarea type="textarea" name="broker_info_message" rows="10" cols="100">
<?php echo get_option('broker_info_message'); ?>
</textarea>
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="broker_info_message" />
</form>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options')?>
<p><strong>No Team Meassage</strong><br />
<textarea type="textarea" name="no_team_message" rows="10" cols="100">
<?php echo get_option('no_team_message'); ?>
</textarea>
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="no_team_message" />
</form>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options')?>
<p><strong>Fall Back Team</strong><br />
<input type="text" name="fall_back_team" value="<?php echo get_option('fall_back_team'); ?>" rows="10" cols="100">
</textarea>
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="fall_back_team" />
</form>
</div>
<?php
}
add_action("wp_ajax_seen_urgent_note", "seen_urgent_note");
function seen_urgent_note()
{
$user_id = get_current_user_id();
update_user_meta($user_id, 'seen_urgent_note', $_REQUEST["note_id"], false);
}
function my_searchwp_xpdf_path()
{
return '/usr/bin/pdftotext'; // path to the binary NOT A FOLDER
}
add_filter('searchwp_xpdf_path', 'my_searchwp_xpdf_path');
function my_force_direct_pdf_links($permalink)
{
global $post;
if (is_search() && 'application/pdf' == get_post_mime_type($post->ID)) {
// if the result is a PDF, link directly to the file not the attachment page
$permalink = wp_get_attachment_url($post->ID);
}
return esc_url($permalink);
}
add_filter('the_permalink', 'my_force_direct_pdf_links');
add_filter('attachment_link', 'my_force_direct_pdf_links');
/**
* @return array|mixed
*/
function getBrokerageList()
{
$brokerList = get_option('broker_list') ? unserialize(get_option('broker_list')) : [];
// Sort it by broker name
usort($brokerList, function ($a, $b) {
if ($a['brokerage'] == $b['brokerage']) {
return 0;
}
return ($a['brokerage'] < $b['brokerage']) ? -1 : 1;
});
return $brokerList;
}
function custom_pagination($numpages = '', $pagerange = '', $paged = '')
{
if (empty($pagerange)) {
$pagerange = 2;
}
/**
* This first part of our function is a fallback
* for custom pagination inside a regular loop that
* uses the global $paged and global $wp_query variables.
*
* It's good because we can now override default pagination
* in our theme, and use this function in default quries
* and custom queries.
*/
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if (!$numpages) {
$numpages = 1;
}
}
/**
* We construct the pagination arguments to enter into our paginate_links
* function.
*/
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => false,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => true,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
// echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
}
add_shortcode("NewsText", "NewsText");
function NewsText()
{
$custom_args = array(
'post_type' => 'new_and_events',
'posts_per_page' => 10,
'paged' => 1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'type',
'value' => 'NewsText',
'compare' => '=',
),
)
);
$custom_query = new WP_Query($custom_args);
if ($custom_query->have_posts()):
$news = '<h3>NEWS</h3>';
while ($custom_query->have_posts()): $custom_query->the_post();
$id = get_the_ID();
$post = get_post($id);
$news .= do_shortcode('[su_spoiler title="' . $post->post_title . '" icon="caret"]' . $post->post_content . '[/su_spoiler]');
endwhile;
$newspost = do_shortcode('[su_accordion]' . $news . '[/su_accordion]');
endif;
return $newspost;
}
add_shortcode("ImpactNews", "ImpactNews");
function ImpactNews()
{
$custom_args = array(
'post_type' => 'new_and_events',
'posts_per_page' => 10,
'paged' => 1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'type',
'value' => 'Impact',
'compare' => '=',
),
)
);
$custom_query = new WP_Query($custom_args);
if ($custom_query->have_posts()):
$news = '<div class="impact-news"><h3>(UPCOMING PROGRAM DATES)</h3><hr>';
while ($custom_query->have_posts()): $custom_query->the_post();
$id = get_the_ID();
$post = get_post($id);
$news .= '<h4>'.$post->post_title.'</h4><p>'. $post->post_content.'</p><hr>' ;
endwhile;
$newspost = $news.'</div>';
endif;
return $newspost;
}
add_shortcode("WaveButton", "WaveButton");
function WaveButton()
{
$button = '<div class="promer-banner-cont">';
$button .= '<div class="promer-banner">';
//$button .= '<div class="promer-text">GIVE “WAVE” A TRY</div>';
$button .= '<div class="promer-button" style="transform: matrix(1, 0, 0, 1, 0, 0);"><a href="http://rating.thecommonwell.ca" class="rating-engine-link-button" target="_blank">COMMERCIAL RATING TOOL</a></div></div></div>';
return $button;
}
// Hide admin bar for broker
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar()
{
if (current_user_can('subscriber')) {
show_admin_bar(false);
}
}
add_action('wp_ajax_nopriv_lost_pass', 'lost_pass_callback');
add_action('wp_ajax_lost_pass', 'lost_pass_callback');
/*
* @desc Process lost password
*/
function lost_pass_callback()
{
global $wpdb, $wp_hasher;
$nonce = $_POST['nonce'];
if (!wp_verify_nonce($nonce, 'rs_user_lost_password_action')) {
die('Security checked!');
}
//We shall SQL escape all inputs to avoid sql injection.
$user_login = $_POST['user_login'];
$errors = new WP_Error();
if (empty($user_login)) {
$errors->add('empty_username', __('ERROR: Enter a username or e-mail address.'));
} else if (strpos($user_login, '@')) {
$user_data = get_user_by('email', trim($user_login));
if (empty($user_data)) {
$errors->add('invalid_email', __('ERROR: There is no user registered with that email address.'));
}
} else {
$login = trim($user_login);
$user_data = get_user_by('login', $login);
}
/**
* Fires before errors are returned from a password reset request.
*
* @since 2.1.0
* @since 4.4.0 Added the `$errors` parameter.
*
* @param WP_Error $errors A WP_Error object containing any errors generated
* by using invalid credentials.
*/
do_action('lostpassword_post', $errors);
if ($errors->get_error_code()) {
$return = '<p class="error">' . $errors->get_error_message($errors->get_error_code()) . '</p>';
echo ($return);
die();
}
if (!$user_data) {
$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or email.'));
$return = '<p class="error">' . $errors->get_error_message($errors->get_error_code()) . '</p>';
echo ($return);
die();
}
// Redefining user_login ensures we return the right case in the email.
$user_login = $user_data->user_login;
$user_email = $user_data->user_email;
$key = get_password_reset_key($user_data);
if (is_wp_error($key)) {
return $key;
}
$message = 'Someone requested that the password be reset for the following ' . get_bloginfo('name') . ' account:<br /><br /> ';
$message .= sprintf(__('Username: %s'), $user_login) . "<br /><br />";
$message .= '<a href=' . esc_url(get_permalink(401) . "?action=rp&key=$key&login=" . rawurlencode($user_login)) . ' mc:disable-tracking>' . __('Click here to reset your password.') . '</a><br/><br/>';
$message .= __('If you did not request to change you password, you don\'t have to do anything. Your password will not be changed.') . "<br /><br />";
//$message .= '<br /><br /><br /><br />https://'.esc_url( get_permalink( 401 ) . "/?action=rp&key=$key&login=" . rawurlencode($user_login) ) . "<br /><br />";
if (is_multisite()) {
$blogname = $GLOBALS['current_site']->site_name;
} else
/*
* The blogname option is escaped with esc_html on the way into the database
* in sanitize_option we want to reverse this for the plain text arena of emails.
*/
{
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
}
$title = sprintf(__('Password Reset'), $blogname);
/**
* Filter the subject of the password reset email.
*
* @since 2.8.0
* @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
*
* @param string $title Default email title.
* @param string $user_login The username for the user.
* @param WP_User $user_data WP_User object.
*/
$title = apply_filters('retrieve_password_title', $title, $user_login, $user_data);
/**
* Filter the message body of the password reset mail.
*
* @since 2.8.0
* @since 4.1.0 Added `$user_login` and `$user_data` parameters.
*
* @param string $message Default mail message.
* @param string $key The activation key.
* @param string $user_login The username for the user.
* @param WP_User $user_data WP_User object.
*/
$message = apply_filters('retrieve_password_message', $message, $key, $user_login, $user_data);
if (wp_mail($user_email, wp_specialchars_decode($title), $message)) {
$errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
} else {
$errors->add('could_not_sent', __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.'), 'message');
}
// display error message
if ($errors) {
$return = '<p class="error">' . $errors->get_error_message($errors->get_error_code()) . '</p>';
echo ($return);
die();
}
// return proper result
die();
}
add_action('wp_ajax_nopriv_reset_pass', 'reset_pass_callback');
add_action('wp_ajax_reset_pass', 'reset_pass_callback');
/*
* @desc Process reset password
*/
function reset_pass_callback()
{
$errors = new WP_Error();
$nonce = $_POST['nonce'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$key = $_POST['user_key'];
$login = $_POST['user_login'];
$user = check_password_reset_key($key, $login);
// check to see if user added some string
if (empty($pass1) || empty($pass2)) {
$errors->add('password_required', __('Password is required field'));
}
// is pass1 and pass2 match?
if (isset($pass1) && $pass1 != $pass2) {
$errors->add('password_reset_mismatch', __('The passwords do not match.'));
}
/**
* Fires before the password reset procedure is validated.
*
* @since 3.5.0
*
* @param object $errors WP Error object.
* @param WP_User|WP_Error $user WP_User object if the login and reset key match. WP_Error object otherwise.
*/
do_action('validate_password_reset', $errors, $user);
if ((!$errors->get_error_code()) && isset($pass1) && !empty($pass1)) {
reset_password($user, $pass1);
$errors->add('password_reset', __('Your password has been reset.'));
}
// display error message
if ($errors->get_error_code()) {
echo '<p class="error">' . $errors->get_error_message($errors->get_error_code()) . '</p>';
}
// return proper result
die();
}
// localize wp-ajax, notice the path to our theme-ajax.js file
wp_enqueue_script('rsclean-request-script', get_stylesheet_directory_uri() . '/scripts/src/theme-ajax.js', array('jquery'));
wp_localize_script('rsclean-request-script', 'theme_ajax', array(
'url' => admin_url('admin-ajax.php'),
'site_url' => get_bloginfo('url'),
'theme_url' => get_bloginfo('template_directory'),
));
function get_custom_mail($args)
{
// Modify the options here
$template = get_mail_template();
$output = str_replace("[url]", get_template_directory_uri(), $template);
$output1 = str_replace("[title]", $args["subject"], $output);
$output2 = str_replace("[content]", $args["html"], $output1);
$custom_mail = array(
'to' => $args['to'],
'subject' => $args['subject'],
'html' => $output2,
'headers' => $args['headers'],
'attachments' => $args['attachments'],
);
// Return the value to the original function to send the email
return $custom_mail;
}
//add_filter('wp_mail', 'get_custom_mail');
function get_mail_template()
{
include( get_stylesheet_directory() . '/' . '/mail_template.php');
}
function custom_login_stylesheet()
{
wp_enqueue_style('custom-login', get_stylesheet_directory_uri() . '/style.css');
}
add_action('login_enqueue_scripts', 'custom_login_stylesheet');
function getMemberOfGroup($group_id)
{
// initiaze curl which is used to make the http request.
$available_members = get_users(
array(
'meta_query' => array(
array(
'key' => 'group_id',
'value' => $group_id,
'compare' => '=',
),
),
)
);
foreach ($available_members as $available_member) {
$user_info[] = get_user_meta($available_member->ID);
}
// There is a field for odata metadata that we ignore and just consume the value
return $user_info;
}
add_action('delete_attachment', 'DontDeleteMedia', 11, 1);
function DontDeleteMedia($postID)
{
//exit('You cannot delete media.');
}
//P.S. That was a long train ride! Lol
/**
* Disable the emoji's
*/
function disable_emojis()
{
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
add_filter('wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2);
}
add_action('init', 'disable_emojis');
/**
* Filter function used to remove the tinymce emoji plugin.
*
* @param array $plugins
* @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce($plugins)
{
if (is_array($plugins)) {
return array_diff($plugins, array('wpemoji'));
} else {
return array();
}
}
/**
* Remove emoji CDN hostname from DNS prefetching hints.
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed for.
* @return array Difference betwen the two arrays.
*/
function disable_emojis_remove_dns_prefetch($urls, $relation_type)
{
if ('dns-prefetch' == $relation_type) {
/** This filter is documented in wp-includes/formatting.php */
$emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/');
$urls = array_diff($urls, array($emoji_svg_url));
}
return $urls;
}
function broker_override_fields($broker_override_id)
{
$brokerList = getBrokerageList();
$userBrokerId = $broker_override_id;
?>
<select name="broker_override_id" class="broker_override_id">
<option value="">Select Broker</option>
<?php foreach ($brokerList as $broker): ?>
<?php
$isSelected = $userBrokerId === $broker['brokerage'] ? 'selected="selected"' : '';
?>
<option value="<?php echo $broker['brokerage']; ?>" <?php echo $isSelected; ?>><?php echo $broker['brokerage']; ?></option>
<?php endforeach;?>
</select>
<?php
}
function matchBrokerageFromList($post_title)
{
$brokerList = get_option('broker_list') ? unserialize(get_option('broker_list')) : [];
$searchword = $post_title;
$matches = array();
foreach ($brokerList as $k => $v) {
$brokerage = substr($v['brokerage'], 0, strrpos($v['brokerage'], '-'));
if (strpos($searchword, $brokerage) !== false) {
$matches[$k] = $v['brokerage'];
}
}
return $matches;
}
function getRecipientWithBrokerId($Brokerage)
{
$available_brokers = get_users(
array(
'meta_query' => array(
array(
'key' => 'brokerage',
'value' => $Brokerage,
'compare' => '==',
),
),
)
);
ob_start();
?>
<select name="lead_recipien_id" class="lead_recipien_id">
<option value="">Select Recipient</option>
<?php foreach ($available_brokers as $broker): ?>
<?php
$isSelected = "";
?>
<option value="<?php echo $broker->ID; ?>"><?php echo $broker->user_email; ?></option>
<?php endforeach;?>
</select>
<?php
}
add_action('wp_ajax_get_recipients', 'ajax_get_Recipien_With_BrokerId');
add_action('wp_ajax_nopriv_get_recipients', 'ajax_get_Recipien_With_BrokerId');
function ajax_get_Recipien_With_BrokerId()
{
$broker_override_id = $_POST['broker_override_id'];
$available_brokers = get_users(
array(
'meta_query' => array(
array(
'key' => 'brokerage',
'value' => $broker_override_id,
'compare' => '==',
),
),
)
);
?>
<select name="lead_recipien_id" class="lead_recipien_id">
<option value="">Select Recipient</option>
<?php foreach ($available_brokers as $broker): ?>
<?php
$isSelected = "";
?>
<option value="<?php echo $broker->ID; ?>"><?php echo $broker->user_email; ?></option>
<?php endforeach;?>
</select>
<?php $output = ob_get_clean();
wp_send_json_success($output);
die();
}
add_shortcode('add_hr', 'add_hr_shortcode');
function add_hr_shortcode()
{
ob_start();?>
<div class="hr"></div>
<?php
return ob_get_clean();
}
add_action('wp_logout', 'remove_custom_cookie_admin');
function remove_custom_cookie_admin()
{
setcookie('dialog_cookie', '', time() - 96400, '/');
}
function badgeos_send_achievements_email_custom( $user_id, $achievement_id, $this_trigger, $site_id, $args, $entry_id ) {
global $wpdb;
$badgeos_settings = ( $exists = badgeos_utilities::get_option( 'badgeos_settings' ) ) ? $exists : array();
$achievement_post_type = badgeos_utilities::get_post_type( $achievement_id );
$achievement_type = $badgeos_settings['achievement_main_post_type'];
$post_obj = get_page_by_path( $achievement_post_type, OBJECT, $achievement_type );
$parent_post_type = '';
if( $post_obj ) {
$parent_post_type = $post_obj->post_type;
}
if ( trim( $achievement_type ) == trim( $parent_post_type ) ) {
$badgeos_admin_tools = ( $exists = badgeos_utilities::get_option( 'badgeos_admin_tools' ) ) ? $exists : array();
$email_cc_list = badgeos_bcc_cc_emails( $badgeos_admin_tools, 'email_achievement_cc_list', 'cc' );
$email_bcc_list = badgeos_bcc_cc_emails( $badgeos_admin_tools, 'email_achievement_bcc_list', 'bcc' );
if( ! isset( $badgeos_admin_tools['email_disable_earned_achievement_email'] ) || $badgeos_admin_tools['email_disable_earned_achievement_email'] == 'no' ) {
$results = $wpdb->get_results( "select * from ".$wpdb->prefix."badgeos_achievements where entry_id='".$entry_id."'", 'ARRAY_A' );
if( count( $results ) > 0 ) {
$record = $results[ 0 ];
$achievement_type = $record[ 'post_type' ];
$type_title = $post_obj->post_title;
$step_type = trim( $badgeos_settings['achievement_step_post_type'] );
$issue_date = $record[ 'date_earned' ];
$rec_type = $record[ 'rec_type' ];
$rec_date_earned = $record['date_earned'];
$date_format = badgeos_utilities::get_option( 'date_format', true );
$time_format = badgeos_utilities::get_option( 'time_format', true );
if( get_post_meta( $achievement_id, '_open_badge_enable_baking', true ) ) {
$evidence_page_id = get_option( 'badgeos_evidence_url' );
$badgeos_evidence_url = get_permalink( $evidence_page_id );
$badgeos_evidence_url = add_query_arg( 'bg', $record[ 'ID' ], $badgeos_evidence_url );
$badgeos_evidence_url = add_query_arg( 'eid', $record[ 'entry_id' ], $badgeos_evidence_url );
$badgeos_evidence_url = add_query_arg( 'uid', $record[ 'user_id' ], $badgeos_evidence_url );
}
if( ! empty( $achievement_type ) && trim( $achievement_type ) != $step_type ) {
$email_subject = $badgeos_admin_tools['email_achievement_subject'];
if( empty( $email_subject ) ) {
$email_subject = __( 'Congratulation for earning an achievement', 'badgeos' );
}
$email_content = $badgeos_admin_tools['email_achievement_content'];
$from_title = get_bloginfo( 'name' );
$from_email = get_bloginfo( 'admin_email' );
if( !empty( $badgeos_admin_tools['email_general_from_name'] ) ) {
$from_title = $badgeos_admin_tools['email_general_from_name'];
}
if( !empty( $badgeos_admin_tools['email_general_from_email'] ) ) {
$from_title = $badgeos_admin_tools['email_general_from_email'];
}
$achievement_title = $record[ 'achievement_title' ];
$points = $record[ 'points' ];
$achievement_image = badgeos_get_achievement_post_thumbnail( $achievement_id, 'full' );
$user_to_title = '';
$user_email = '';
$to_user_id = $record[ 'user_id'];
$user_to = get_user_by( 'ID', $record[ 'user_id'] );
if( $user_to ) {
$user_to_title = $user_to->display_name;
$user_email = $user_to->user_email;
}
$headers[] = 'From: '.$from_title.' <'.$from_email.'>';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
if( is_array( $email_cc_list ) && count( $email_cc_list ) > 0 ) {
foreach( $email_cc_list as $cc_id ) {
if( !empty( $cc_id ) ) {
$headers[] = 'Cc: '.$cc_id;
}
}
}
if( is_array( $email_bcc_list ) && count( $email_bcc_list ) > 0 ) {
foreach( $email_bcc_list as $bcc_id ) {
if( !empty( $bcc_id ) ) {
$headers[] = 'Bcc: '.$bcc_id;
}
}
}
$email_subject = str_replace('[achievement_type]', $type_title, $email_subject );
$email_subject = str_replace('[achievement_title]', $achievement_title, $email_subject );
$email_subject = str_replace('[points]', $points, $email_subject );
$email_subject = str_replace('[user_email]', $user_email, $email_subject );
$email_subject = str_replace('[user_name]', $user_to_title, $email_subject );
ob_start();
$email_content = stripslashes( html_entity_decode( $email_content ) );
$email_content = str_replace("\'","'", $email_content);
$email_content = str_replace('\"','"', $email_content);
$email_content = str_replace('[achievement_type]', $type_title, $email_content );
$email_content = str_replace('[achievement_title]', $achievement_title, $email_content );
$email_content = str_replace('[date_earned]', date( $date_format.' '.$time_format, strtotime($record['date_earned']) ), $email_content );
$email_content = str_replace('[achievement_link]', get_permalink($achievement_id), $email_content );
$email_content = str_replace('[points]', $points, $email_content );
$email_content = str_replace('[user_email]', $user_email, $email_content );
$email_content = str_replace('[user_name]', $user_to_title."<p> </p>", $email_content );
$email_content = str_replace('[achievement_image]', "<p> </p>".$achievement_image."<p> </p>", $email_content );
$email_content = str_replace('[user_profile_link]', get_edit_profile_url( $to_user_id ), $email_content );
$email_content = str_replace('[evidence]', badgeos_include_evidence_in_email( $achievement_id, $issue_date, $rec_type, $badgeos_evidence_url, $rec_date_earned ), $email_content);
?>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
<tr>
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">
<?php echo $email_content; ?>
</td>
</tr>
</table>
<?php
$message = ob_get_contents();
ob_end_clean();
if( ! empty( $user_email ) ) {
wp_mail( $user_email, strip_tags( $email_subject ), $message, $headers );
}
}
}
}
}
}
add_action( 'badgeos_award_achievement', 'badgeos_send_achievements_email_custom', 10, 6 );
function remove_badgeos_can_notify_user( $user_login, $user ) {
update_user_meta($user->ID, '_badgeos_can_notify_user', '');
}
add_action('wp_login', 'remove_badgeos_can_notify_user', 10, 2 );
add_shortcode('textbooks', 'textbooks_shortcode');
function textbooks_shortcode()
{
ob_start();
global $wpdb;
$results = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."usermeta where meta_key LIKE '%learndash_group_users%' and user_id =".get_current_user_id());
foreach( $results as $result){
$sfwd_groups = get_post_meta($result->meta_value , '_groups', true );
if(!empty($sfwd_groups['groups_group_materials']) ){
echo '<h4 style="font-size:1rem;">'.get_the_title($result->meta_value).'</h4>';
echo '<div class="material">'.$sfwd_groups['groups_group_materials'].'</div>';
}
}
$enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false);
foreach($enrolled_courses as $enrolled_course){
$lesson_materials="";
$sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true );
$course_steps = get_post_meta($enrolled_course , 'ld_course_steps', true );
$course_steps = $course_steps['steps']['h']['sfwd-lessons'];
foreach($course_steps as $key => $course_step){
$sfwd_lessons = get_post_meta($key , '_sfwd-lessons', true );
$lesson_materials .= $sfwd_lessons['sfwd-lessons_lesson_materials'];
}
if(!empty($sfwd_course['sfwd-courses_course_materials']) || !empty($lesson_materials) ){
echo '<h4 style="font-size:1rem;">'.str_replace("Private:","",get_the_title($enrolled_course )).'</h4>';
echo '<div class="material">'.$sfwd_course['sfwd-courses_course_materials'].$lesson_materials.'</div>';
}
}
?>
<?php
return ob_get_clean();
}
add_shortcode('badges', 'badges_shortcode');
function badges_shortcode()
{
ob_start();
//learndash_groups_to_course(get_current_user_id());
global $wpdb;
$results = $wpdb->get_results("SELECT ID, date_earned, achievement_title FROM ".$wpdb->prefix."badgeos_achievements where post_type='badges' and user_id =".get_current_user_id());
echo '<div class="badges">';
foreach( $results as $result){
$thumbnail_id = get_post_meta($result->ID, '_thumbnail_id', true );
echo '<div class="badge_container" data-title="'.str_replace(":","_",str_replace(" ","-",get_the_title($result->ID))).'">'.wp_get_attachment_image($thumbnail_id, array('300', '200'), "", array( "class" => "img-responsive" ) ).'</div>';
}
echo '</div>';
echo '<p class="has-text-align-center">Click to download your certificate</p>';
echo '<div class="cert">';
$enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false);
foreach($enrolled_courses as $enrolled_course){
if($enrolled_course == 45591){
continue;
}
$cert = learndash_get_course_certificate_link($enrolled_course, get_current_user_id());
if(!empty($cert)){
$sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true );
$thumbnail_id = get_post_meta($sfwd_course['sfwd-courses_certificate'], '_thumbnail_id', true );
echo '<div class="badge_container cert"><a target="_blank" class="cert_link" href="'.$cert.'">'
.wp_get_attachment_image($thumbnail_id, array('200', '100'), "", array( "class" => "img-responsive" ) ).' </a><br><strong>'. date( 'F, d, Y', get_user_meta(get_current_user_id(), 'course_completed_'.$enrolled_course, true )).'</strong></div>';
}
}
echo '</div>';
?>
<?php
return ob_get_clean();
}
function learndash_groups_to_course($user_id)
{
global $user_ID, $blog_id, $wpdb;
$results = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."usermeta where meta_key LIKE '%learndash_group_users%' and user_id =".$user_id);
foreach( $results as $result){
if($result->meta_value== 45728){
continue;
}
ld_update_group_access( $user_id, $result->meta_value, false);
$sfwd_groups = get_post_meta($result->meta_value , '_groups', true );
$group_course_id = get_post_meta($result->meta_value, 'ld_auto_enroll_group_course_ids', true );
if($group_course_id[0] !==""){
if(!get_user_meta($user_id,'course_completed_'.$group_course_id[0],true )){
sci_learndash_mark_course_complete($group_course_id[0],$user_id);
if($access_from = get_user_meta($user_id,'course_'.$group_course_id[0].'_access_from',true )){
update_user_meta( $user_id, 'course_completed_'.$group_course_id[0], $access_from);
}
}
}
}
}
/**
* Mark learndash course as complete.
*
* @param int $id Course ID.
* @param int $user_id User ID.
*/
function sci_learndash_mark_course_complete($id, $user_id)
{
//retreive current course progress
$user_progress['course'][$id] = learndash_user_get_course_progress($user_id, $id, 'legacy');
if (isset($user_progress['course'][$id]['lessons'])) {
//update lessons progress to complete
$lesson_array = $user_progress['course'][$id]['lessons'];
$lessons = array_flip($lesson_array);
$lessons = array_fill_keys(array_keys($lesson_array), 1);
$user_progress['course'][$id]['lessons'] = $lessons;
}
//update topics progress to complete
if (isset($user_progress['course'][$id]['topics'])) {
foreach($user_progress['course'][$id]['topics'] as $ldtopic_key => $ldtopic){
if(count($ldtopic) > 0){
$new_ldtopic = array_flip($ldtopic);
$new_ldtopic = array_fill_keys(array_keys($ldtopic), 1);
$user_progress['course'][$id]['topics'][$ldtopic_key] = $new_ldtopic;
}
}
}
//update quiz progress to complete
if (isset($user_progress['quiz'][$id])) {
$quiz_array = $user_progress['course'][$id]['quiz'];
$quiz = array_flip($quiz_array);
$quiz = array_fill_keys(array_keys($quiz_array), 1);
$user_progress['course'][$id]['quiz'] = $quiz;
}else{
$quiz_list = [];
if ( isset($user_progress['course'][$id]['lessons']) && count($user_progress['course'][$id]['lessons']) > 0 ) {
$ld_lesson_keys = array_keys($user_progress['course'][$id]['lessons']);
foreach($ld_lesson_keys as $course_lesson_id){
$topic_quizzes = learndash_get_lesson_quiz_list( $course_lesson_id );
if (!empty($topic_quizzes)){
foreach ($topic_quizzes as $topic_quiz) {
$quiz_list[$topic_quiz['post']->ID] = 1;
}
}
}
}
if (!empty($quiz_list)){
$user_progress['quiz'][$id] = $quiz_list;
}
}
$processed_course_ids = [];
if ((isset($user_progress['course'])) && (!empty($user_progress['course']))) {
$usermeta = get_user_meta($user_id, '_sfwd-course_progress', true);
$course_progress = empty($usermeta) ? [] : $usermeta;
$course_changed = false; // Simple flag to let us know we changed the quiz data so we can save it back to user meta.
foreach ($user_progress['course'] as $course_id => $course_data_new) {
$processed_course_ids[intval($course_id)] = intval($course_id);
if (isset($course_progress[$course_id])) {
$course_data_old = $course_progress[$course_id];
} else {
$course_data_old = [];
}
$course_data_new = learndash_course_item_to_activity_sync($user_id, $course_id, $course_data_new,
$course_data_old);
$course_progress[$course_id] = $course_data_new;
$course_changed = true;
}
if (true === $course_changed) {
update_user_meta($user_id, '_sfwd-course_progress', $course_progress);
}
}
if ((isset($user_progress['quiz'])) && (!empty($user_progress['quiz']))) {
$usermeta = get_user_meta($user_id, '_sfwd-quizzes', true);
$quizz_progress = empty($usermeta) ? [] : $usermeta;
$quiz_changed = false; // Simple flag to let us know we changed the quiz data so we can save it back to user meta.
foreach ($user_progress['quiz'] as $course_id => $course_quiz_set) {
foreach ($course_quiz_set as $quiz_id => $quiz_new_status) {
$quiz_meta = get_post_meta($quiz_id, '_sfwd-quiz', true);
if (!empty($quiz_meta)) {
$quiz_old_status = !learndash_is_quiz_notcomplete($user_id, [$quiz_id => 1], false, $course_id);
// For Quiz if the admin marks a qiz complete we don't attempt to update an existing attempt for the user quiz.
// Instead we add a new entry. LD doesn't care as it will take the complete one for calculations where needed.
if ((bool)true === (bool)$quiz_new_status) {
if ((bool)true !== (bool)$quiz_old_status) {
if (isset($quiz_meta['sfwd-quiz_lesson'])) {
$lesson_id = absint($quiz_meta['sfwd-quiz_lesson']);
} else {
$lesson_id = 0;
}
if (isset($quiz_meta['sfwd-quiz_topic'])) {
$topic_id = absint($quiz_meta['sfwd-quiz_topic']);
} else {
$topic_id = 0;
}
// If the admin is marking the quiz complete AND the quiz is NOT already complete...
// Then we add the minimal quiz data to the user profile.
$quizdata = [
'quiz' => $quiz_id,
'score' => 0,
'count' => 0,
'question_show_count' => 0,
'pass' => true,
'rank' => '-',
'time' => time(),
'pro_quizid' => absint($quiz_meta['sfwd-quiz_quiz_pro']),
'course' => $course_id,
'lesson' => $lesson_id,
'topic' => $topic_id,
'points' => 0,
'total_points' => 0,
'percentage' => 0,
'timespent' => 0,
'has_graded' => false,
'statistic_ref_id' => 0,
'm_edit_by' => get_current_user_id(), // Manual Edit By ID.
'm_edit_time' => time(), // Manual Edit timestamp.
];
$quizz_progress[] = $quizdata;
if (true === $quizdata['pass']) {
$quizdata_pass = true;
} else {
$quizdata_pass = false;
}
// Then we add the quiz entry to the activity database.
learndash_update_user_activity(
[
'course_id' => $course_id,
'user_id' => $user_id,
'post_id' => $quiz_id,
'activity_type' => 'quiz',
'activity_action' => 'insert',
'activity_status' => $quizdata_pass,
'activity_started' => $quizdata['time'],
'activity_completed' => $quizdata['time'],
'activity_meta' => $quizdata,
]
);
$quiz_changed = true;
if ((isset($quizdata['course'])) && (!empty($quizdata['course']))) {
$quizdata['course'] = get_post($quizdata['course']);
}
if ((isset($quizdata['lesson'])) && (!empty($quizdata['lesson']))) {
$quizdata['lesson'] = get_post($quizdata['lesson']);
}
if ((isset($quizdata['topic'])) && (!empty($quizdata['topic']))) {
$quizdata['topic'] = get_post($quizdata['topic']);
}
/**
* Fires after the quiz is marked as complete.
*
* @param arrat $quizdata An array of quiz data.
* @param WP_User $user WP_User object.
*/
do_action('learndash_quiz_completed', $quizdata, get_user_by('ID', $user_id));
}
} elseif (true !== $quiz_new_status) {
// If we are unsetting a quiz ( changing from complete to incomplete). We need to do some complicated things...
if (true === $quiz_old_status) {
if (!empty($quizz_progress)) {
foreach ($quizz_progress as $quiz_idx => $quiz_item) {
if (($quiz_item['quiz'] == $quiz_id) && (true === $quiz_item['pass'])) {
$quizz_progress[$quiz_idx]['pass'] = false;
// We need to update the activity database records for this quiz_id
$activity_query_args = [
'post_ids' => $quiz_id,
'user_ids' => $user_id,
'activity_type' => 'quiz',
];
$quiz_activity = learndash_reports_get_activity($activity_query_args);
if ((isset($quiz_activity['results'])) && (!empty($quiz_activity['results']))) {
foreach ($quiz_activity['results'] as $result) {
if ((isset($result->activity_meta['pass'])) && (true === $result->activity_meta['pass'])) {
// If the activity meta 'pass' element is set to true we want to update it to false.
learndash_update_user_activity_meta($result->activity_id, 'pass',
false);
// Also we need to update the 'activity_status' for this record
learndash_update_user_activity(
[
'activity_id' => $result->activity_id,
'course_id' => $course_id,
'user_id' => $user_id,
'post_id' => $quiz_id,
'activity_type' => 'quiz',
'activity_action' => 'update',
'activity_status' => false,
]
);
}
}
}
$quiz_changed = true;
}
/**
* Remove the quiz lock.
*
* @since 2.3.1
*/
if ((isset($quiz_item['pro_quizid'])) && (!empty($quiz_item['pro_quizid']))) {
learndash_remove_user_quiz_locks($user_id, $quiz_item['quiz']);
}
}
}
}
}
$processed_course_ids[intval($course_id)] = intval($course_id);
}
}
}
if (true === $quiz_changed) {
update_user_meta($user_id, '_sfwd-quizzes', $quizz_progress);
}
}
if (!empty($processed_course_ids)) {
foreach (array_unique($processed_course_ids) as $course_id) {
learndash_process_mark_complete($user_id, $course_id);
learndash_update_group_course_user_progress($course_id, $user_id);
}
}
}
add_shortcode('dash_user_info', 'dash_user_info_shortcode');
function dash_user_info_shortcode()
{
global $current_user;
get_currentuserinfo();
echo'<div class="dash_user_info">';
echo get_avatar( $current_user->ID, 180 );
echo '<p>'.$current_user->first_name.' '.$current_user->last_name.'</p>';
echo "</div>";
ob_start();?>
<?php
return ob_get_clean();
}
function the_bread() {
if(!is_admin()){
$ingredients = array(
'separator' => '>',
'offset' => -3,
'length' => 3,
);
$flour = $_SERVER['REQUEST_URI'];
if ( str_contains( $flour, '?' ) )
$flour = substr( $flour, 0, strpos( $flour, '?' ) );
$flour = ( str_ends_with( $flour, '/' ) ? explode( '/', substr( $flour, 1, -1 ) ) : explode( '/', substr( $flour, 1 ) ) );
$crumbs = [];
foreach ( $flour as $crumb ) {
$slug = esc_html( $crumb );
$url = esc_url( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . substr( implode( '/', $flour ), 0, strpos( implode( '/', $flour ), $crumb ) ) . $crumb. '/' );
array_push( $crumbs, ( object )
[
'slug' => $slug,
'url' => $url,
]
);
};
$offset = ( empty( $ingredients['offset'] ) ? 0 : $ingredients['offset'] );
$length = ( empty( $ingredients['length'] ) ? null : $ingredients['length'] );
$crumbs = array_slice( $crumbs, $offset, $length );
echo '<ul class="bread">';
$i = 0;
if ( is_singular( 'sfwd-lessons' ) ) {
echo '<li class="crumb" itemprop="itemListElement">
<a itemprop="item" href="https://thecommonwell.ca/broker-landing-page/learning-2/">
<span itemprop="name">Broker Learning</span>
</a>
<meta itemprop="position" content="1">
</li>><li class="crumb" itemprop="itemListElement">
<a itemprop="item" href="https://thecommonwell.ca/broker-landing-page/learning-2/marketing-masters/">
<span itemprop="name">Marketing Masters</span>
</a>
<meta itemprop="position" content="2">
</li>>';
}
foreach ( $crumbs as $crumb ) {
$i++;
echo '<li class="crumb" itemprop="itemListElement">
<a itemprop="item" href="' . $crumb->url . '">
<span itemprop="name">' . ( url_to_postid( $crumb->url ) ? get_the_title( url_to_postid( $crumb->url ) ) : ucfirst( str_replace( '-', ' ', $crumb->slug ) ) ) . '</span>
</a>
<meta itemprop="position" content="' . $i . '">
</li>';
if ( $i !== sizeof( $crumbs ) && ! empty( $ingredients['separator'] ) )
echo $ingredients['separator'];
};
echo '</ul>';
}
};
add_shortcode( 'breadcrumbs', 'the_bread' );
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle): bool
{
return '' === $needle || false !== strpos($haystack, $needle);
}
}
if (!function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle): bool {
return \strncmp($haystack, $needle, \strlen($needle)) === 0;
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle): bool {
return $needle === '' || $needle === \substr($haystack, - \strlen($needle));
}
}
add_filter('manage_posts_columns', 'posts_columns_id', 5);
add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
add_filter('manage_pages_columns', 'posts_columns_id', 5);
add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2);
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}
function posts_custom_id_columns($column_name, $id){
if($column_name === 'wps_post_id'){
echo $id;
}
}
add_action( 'wp', 'prefix_setup_schedule' );
/**
* On an early action hook, check if the hook is scheduled - if not, schedule it.
*/
function prefix_setup_schedule() {
if ( ! wp_next_scheduled( 'prefix_daily_event' ) ) {
wp_schedule_event( time(), 'daily', 'prefix_daily_event');
}
}
add_action( 'prefix_daily_event', 'prefix_do_this_daily' );
/**
* On the scheduled action hook, run a function.
*/
function prefix_do_this_daily() {
$broker = get_users( array( 'role__in' => array('subscriber' ) ) );
// Array of WP_User objects.
foreach ( $broker as $user ) {
learndash_process_mark_complete($user->ID, 45654 );
}
}
add_filter( 'avatar_defaults', 'wpb_new_gravatar' );
function wpb_new_gravatar ($avatar_defaults) {
$myavatar = 'http://ccorp.test/wp-content/themes/commonwell-corp/images/CWL_Learning-Profile-Icon.gif';
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}
function get_excerpt($limit, $source = null){
$excerpt = $source == "content" ? get_the_content() : get_the_excerpt();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$strlen = strlen($excerpt) ;
if( $strlen <= $limit){
return $excerpt;
}
$excerpt = substr($excerpt, 0, $limit);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a class="share_read_more" data-id="'.get_the_ID().'" href="javascript:void(0);">READ MORE >></a>';
// $excerpt = $excerpt.'... <a href="'.get_permalink($post->ID).'">READ MORE >></a>';
return $excerpt;
}
add_action('wp_ajax_nopriv_ajax_request', 'ajax_handle_request');
add_action('wp_ajax_ajax_request', 'ajax_handle_request');
function ajax_handle_request(){
$postID = $_POST['post_id'];
global $post;
$post = get_post($postID);
$date = get_post_meta($postID,'date',true);
$date2 = date("F j, Y", strtotime($date));
$response = array(
'sucess' => true,
'post' => $post,
'id' => $postID,
'date' => $date2,
);
// generate the response
echo json_encode($response);
// IMPORTANT: don't forget to "exit"
exit;
}
// retrieves the attachment ID from the file URL
function pippin_get_image_id($filename) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid like'%$filename'",));
return $attachment[0];
}
function schedule_cron_jobs()
{
wp_clear_scheduled_hook('notification_for_project_follow_up');
//daily
// if(!wp_next_scheduled("notification_for_project_follow_up")){
// error_log('schedule_cron_jobs');
// wp_schedule_event(time(), 'daily', 'notification_for_project_follow_up');
// }
}
add_action("admin_init", "schedule_cron_jobs");
function ParseXML($xml) {
// Gets XML in a string and parses it into an array.
// Create the parser object
if (!($parser = xml_parser_create())) {
print "cannot create parser!";
exit();
}
// if we didn't get the argument then give them an error.
if ($xml == "") {
print "No XML Was found!";
exit;
}
xml_parse_into_struct($parser, trim($xml), $structure, $index);
xml_parser_free($parser);
// the parsed array will go here.
// Hack up the XML and put it into the array
foreach($structure as $s)
{
if ($s["tag"] == "FOUND") {
$found = $s['value'];
}
}
return $found;
}
/**
* Disable User Notification of Password Change Confirmation
*/
add_filter( 'send_password_change_email', '__return_false' );
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
// Disables the block editor from managing widgets.
add_filter( 'use_widgets_block_editor', '__return_false' );
add_filter( 'login_redirect', function( $url, $query, $user ) {
return '/broker-landing-page';
}, 10, 3 );