C:\xampp\htdocs\landing\wp-content\plugins\better-wp-security\core\lib.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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
<?php

/**
 * Miscellaneous plugin-wide functions.
 *
 * Various static functions to provide information to modules and other areas throughout the plugin.
 *
 * @since   4.0.0
 * @package iThemes_Security
 *
 */
final class ITSEC_Lib {
    
/**
     * Clear caches.
     *
     * Clears popular WordPress caching mechanisms.
     *
     * @since 4.0.0
     *
     * @param bool $page [optional] true to clear page cache
     *
     * @return void
     */
    
public static function clear_caches$page false ) {

        
//clear APC Cache
        
if ( function_exists'apc_store' ) ) {
            
apc_clear_cache(); //Let's clear APC (if it exists) when big stuff is saved.
        
}

        
//clear w3 total cache or wp super cache
        
if ( function_exists'w3tc_pgcache_flush' ) ) {

            if ( 
true == $page ) {
                
w3tc_pgcache_flush();
                
w3tc_minify_flush();
            }

            
w3tc_dbcache_flush();
            
w3tc_objectcache_flush();

        } elseif ( 
function_exists'wp_cache_clear_cache' ) && true == $page ) {

            
wp_cache_clear_cache();

        }


        
do_action'itsec-lib-clear-caches' );
    }

    
/**
     * Creates appropriate database tables.
     *
     * @since 4.0.0
     *
     * @return true|WP_Error
     */
    
public static function create_database_tables() {
        require_once( 
ITSEC_Core::get_core_dir() . '/lib/schema.php' );

        return 
ITSEC_Schema::create_database_tables();
    }

    
/**
     * Gets location of wp-config.php.
     *
     * Finds and returns path to wp-config.php
     *
     * @since 4.0.0
     *
     * @return string path to wp-config.php
     * */
    
public static function get_config() {
        require_once( 
ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php' );

        return 
ITSEC_Lib_Config_File::get_wp_config_file_path();
    }

    
/**
     * Return primary domain from given url.
     *
     * Returns primary domain name (without subdomains) of given URL.
     *
     * @since 4.0.0
     *
     * @param string $url URL to filter
     *
     * @return string domain name or '*' on error or domain mapped multisite
     * */
    
public static function get_domain$url ) {
        if ( 
is_multisite() && function_exists'domain_mapping_warning' ) ) {
            return 
'*';
        }


        
$host parse_url$urlPHP_URL_HOST );

        if ( 
false === $host ) {
            return 
'*';
        }
        if ( 
'www.' == substr$host0) ) {
            return 
substr$host);
        }

        
$host_parts explode'.'$host );

        if ( 
count$host_parts ) > ) {
            
$host_parts array_slice$host_parts, - 2);
        }

        return 
implode'.'$host_parts );
    }

    
/**
     * Returns the root of the WordPress install.
     *
     * Gets the URI path to the WordPress installation.
     *
     * @since 4.0.6
     *
     * @return string the root folder
     */
    
public static function get_home_root() {
        if ( isset( 
$GLOBALS['__itsec_lib_get_home_root'] ) ) {
            return 
$GLOBALS['__itsec_lib_get_home_root'];
        }

        
$url_parts parse_urlsite_url() );

        if ( isset( 
$url_parts['path'] ) ) {
            
$GLOBALS['__itsec_lib_get_home_root'] = trailingslashit$url_parts['path'] );
        } else {
            
$GLOBALS['__itsec_lib_get_home_root'] = '/';
        }

        return 
$GLOBALS['__itsec_lib_get_home_root'];
    }

    
/**
     * Gets location of .htaccess
     *
     * Finds and returns path to .htaccess or nginx.conf if appropriate
     *
     * @since 4.0.0
     *
     * @return string path to .htaccess
     */
    
public static function get_htaccess() {
        require_once( 
ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php' );

        return 
ITSEC_Lib_Config_File::get_server_config_file_path();
    }

    
/**
     * Returns the actual IP address of the user.
     *
     * Determines the user's IP address by returning the forwarded IP address if present or
     * the direct IP address if not.
     *
     * @since 4.0.0
     *
     * @param bool $use_cache Whether to check the cache, or force the retrieval of a new value.
     *
     * @return string The IP address of the user
     */
    
public static function get_ip$use_cache true ) {
        if ( isset( 
$GLOBALS['__itsec_remote_ip'] ) && $use_cache ) {
            return 
$GLOBALS['__itsec_remote_ip'];
        }

        
$ip apply_filters'itsec-get-ip'false );

        if ( 
false !== $ip ) {
            
$ip filter_var$ipFILTER_VALIDATE_IPFILTER_FLAG_NO_RES_RANGE FILTER_FLAG_NO_PRIV_RANGE );

            if ( 
$ip ) {
                
$GLOBALS['__itsec_remote_ip'] = $ip;

                return 
$ip;
            }
        }

        
self::load'ip-detector' );
        
$ip ITSEC_Lib_IP_Detector::build()->get();

        if ( ! 
$ip ) {
            
// If an IP is not found, force it to a localhost IP that would not be blacklisted as this typically
            // indicates a local request that does not provide the localhost IP.
            
$ip '127.0.0.1';
        }

        
$GLOBALS['__itsec_remote_ip'] = $ip;

        return 
$GLOBALS['__itsec_remote_ip'];
    }

    
/**
     * Returns the server type of the plugin user.
     *
     * Attempts to figure out what http server the visiting user is running.
     *
     * @since 4.0.0
     *
     * @return string|bool server type the user is using of false if undetectable.
     */
    
public static function get_server() {
        require_once( 
ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-utility.php' );

        return 
ITSEC_Lib_Utility::get_web_server();
    }

    public static function 
get_whitelisted_ips() {
        return 
apply_filters'itsec_white_ips', array() );
    }

    
/**
     * Determines whether a given IP address is whiteliste
     *
     * @param string  $ip              ip to check (can be in CIDR notation)
     * @param array   $whitelisted_ips ip list to compare to if not yet saved to options
     * @param boolean $current         whether to whitelist the current ip or not (due to saving, etc)
     *
     * @return boolean true if whitelisted or false
     */
    
public static function is_ip_whitelisted$ip$whitelisted_ips null$current false ) {

        
/** @var ITSEC_Lockout $itsec_lockout */
        
global $itsec_lockout;

        
$ip sanitize_text_field$ip );

        if ( 
ITSEC_Lib::get_ip() === $ip && $itsec_lockout->is_visitor_temp_whitelisted() ) {
            return 
true;
        }

        if ( ! 
class_exists'ITSEC_Lib_IP_Tools' ) ) {
            require_once( 
ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-ip-tools.php' );
        }

        if ( 
is_null$whitelisted_ips ) ) {
            
$whitelisted_ips self::get_whitelisted_ips();
        }

        if ( 
$current ) {
            
$whitelisted_ips[] = ITSEC_Lib::get_ip(); //add current user ip to whitelist
        
}

        if ( ! empty( 
$_SERVER['SERVER_ADDR'] ) ) {
            
$whitelisted_ips[] = $_SERVER['SERVER_ADDR'];
        }

        if ( ! empty( 
$_SERVER['LOCAL_ADDR'] ) ) {
            
$whitelisted_ips[] = $_SERVER['LOCAL_ADDR'];
        }

        foreach ( 
$whitelisted_ips as $whitelisted_ip ) {
            if ( 
ITSEC_Lib_IP_Tools::intersect$ipITSEC_Lib_IP_Tools::ip_wild_to_ip_cidr$whitelisted_ip ) ) ) {
                return 
true;
            }
        }

        return 
false;

    }

    
/**
     * Checks if the given IP is banned.
     *
     * @param string $ip IP address to check.
     *
     * @return bool
     */
    
public static function is_ip_banned$ip '' ) {
        
$ip $ip ?: ITSEC_Lib::get_ip();

        if ( ! 
ITSEC_Lib_IP_Tools::validate$ip ) ) {
            return 
false;
        }

        
$source ITSEC_Modules::get_container()->get( \iThemesSecurity\Ban_Hosts\Source::class );
        
$source = new \iThemesSecurity\Ban_Hosts\Deprecated_Filter_Source$source );

        return (bool) 
$source->find_ban_for_host$ip );
    }

    
/**
     * Gets the list of banned IPs.
     *
     * @deprecated 6.7.0
     *
     * @return string[]
     */
    
public static function get_blacklisted_ips() {
        
_deprecated_function__METHOD__'6.7.0', \iThemesSecurity\Ban_Hosts\Multi_Repository::class );

        if (
            
ITSEC_Modules::get_container()->has( \iThemesSecurity\Ban_Users\Database_Repository::class ) &&
            
ITSEC_Modules::get_setting'ban-users''enable_ban_lists' )
        ) {
            
$repo ITSEC_Modules::get_container()->get( \iThemesSecurity\Ban_Users\Database_Repository::class );
            
$ips  $repo->get_legacy_hosts();
        } else {
            
$ips = [];
        }

        return 
apply_filters'itsec_filter_blacklisted_ips'$ips );
    }

    
/**
     * Determines whether a given IP address is blacklisted.
     *
     * @deprecated 6.7.0
     *
     * @param string $ip              ip to check (can be in CIDR notation)
     * @param array  $blacklisted_ips ip list to compare to if not yet saved to options
     *
     * @return boolean true if blacklisted or false
     */
    
public static function is_ip_blacklisted$ip null$blacklisted_ips null ) {
        
_deprecated_function__METHOD__'6.7.0''ITSEC_Lib::is_ip_banned' );

        if ( 
null !== $blacklisted_ips ) {
            foreach ( 
$blacklisted_ips as $blacklisted_ip ) {
                if ( 
ITSEC_Lib_IP_Tools::intersect$ip$blacklisted_ip ) ) {
                    return 
true;
                }
            }

            return 
false;
        }

        return 
self::is_ip_banned$ip );
    }

    
/**
     * Set a 404 error.
     *
     * Forces the given page to a WordPress 404 error.
     *
     * @since 4.0.0
     *
     * @return void
     */
    
public static function set_404() {

        global 
$wp_query;

        
status_header404 );

        if ( 
function_exists'nocache_headers' ) ) {
            
nocache_headers();
        }

        
$wp_query->set_404();
        
$page_404 get_404_template();

        if ( 
strlen$page_404 ) ) {

            include( 
$page_404 );

        } else {

            include( 
get_query_template'index' ) );

        }

        die();

    }

    
/**
     * Increases minimum memory limit.
     *
     * This function, adopted from builder, attempts to increase the minimum
     * memory limit before heavy functions.
     *
     * @since 4.0.0
     *
     * @param int $new_memory_limit what the new memory limit should be
     *
     * @return void
     */
    
public static function set_minimum_memory_limit$new_memory_limit ) {

        
$memory_limit = @ini_get'memory_limit' );

        if ( - 
$memory_limit ) {

            
$unit         strtolowersubstr$memory_limit, - ) );
            
$memory_limit = (int) $memory_limit;

            
$new_unit         strtolowersubstr$new_memory_limit, - ) );
            
$new_memory_limit = (int) $new_memory_limit;

            if ( 
'm' == $unit ) {

                
$memory_limit *= 1048576;

            } elseif ( 
'g' == $unit ) {

                
$memory_limit *= 1073741824;

            } elseif ( 
'k' == $unit ) {

                
$memory_limit *= 1024;

            }

            if ( 
'm' == $new_unit ) {

                
$new_memory_limit *= 1048576;

            } elseif ( 
'g' == $new_unit ) {

                
$new_memory_limit *= 1073741824;

            } elseif ( 
'k' == $new_unit ) {

                
$new_memory_limit *= 1024;

            }

            if ( (int) 
$memory_limit < (int) $new_memory_limit ) {
                @
ini_set'memory_limit'$new_memory_limit );
            }

        }

    }

    
/**
     * Checks if user exists.
     *
     * Checks to see if WordPress user with given id exists.
     *
     * @since 4.0.0
     *
     * @param int $user_id user id of user to check
     *
     * @return bool true if user exists otherwise false
     *
     * */
    
public static function user_id_exists$user_id ) {

        global 
$wpdb;

        
//return false if username is null
        
if ( '' == $user_id ) {
            return 
false;
        }

        
//queary the user table to see if the user is there
        
$saved_id $wpdb->get_var$wpdb->prepare"SELECT ID FROM `" $wpdb->users "` WHERE ID= %d;"$user_id ) );

        if ( 
$saved_id == $user_id ) {

            return 
true;

        } else {

            return 
false;

        }

    }

    public static function 
show_status_message$message ) {
        echo 
"<div class=\"updated fade\"><p><strong>$message</strong></p></div>\n";
    }

    public static function 
show_error_message$message ) {
        if ( 
is_wp_error$message ) ) {
            
$message $message->get_error_message();
        }

        if ( ! 
is_string$message ) ) {
            return;
        }

        echo 
"<div class=\"error\"><p><strong>$message</strong></p></div>\n";
    }

    public static function 
show_inline_status_message$message ) {
        echo 
"<div class=\"updated fade inline\"><p><strong>$message</strong></p></div>\n";
    }

    public static function 
show_inline_error_message$message ) {
        if ( 
is_wp_error$message ) ) {
            
$message $message->get_error_message();
        }

        if ( ! 
is_string$message ) ) {
            return;
        }

        echo 
"<div class=\"error inline\"><p><strong>$message</strong></p></div>\n";
    }

    
/**
     * Print a WP core notice styled inline.
     *
     * @param string|WP_Error $message
     * @param string          $type
     *
     * @return string
     */
    
public static function inline_styled_notice$message$type 'error' ) {
        switch ( 
$type ) {
            case 
'error':
                
$bkg '#dc3232';
                
$bdr '#fbeaea';
                break;
            case 
'warning':
                
$bkg '#fff8e5';
                
$bdr '#ffb900';
                break;
            case 
'info':
                
$bkg '#e5f5fa';
                
$bdr '#00a0d2';
                break;
            case 
'success':
            default:
                
$bkg '#ecf7ed';
                
$bdr '#46b450';
                break;
        }

        if ( 
is_wp_error$message ) ) {
            
$messages = array();

            foreach ( 
$message->get_error_codes() as $code ) {
                foreach ( 
$message->get_error_messages$code ) as $str ) {
                    
$messages[] = $str;
                }
            }

            
$message wp_sprintf'%l'$messages );
        }

        
$html "<div style=\"background: {$bkg};border-left: 4px solid {$bdr};padding: 1px 12px; margin: 5px 0 15px;\">";
        
$html .= '<p style="margin: 0.5em 6px 0.5em 0;padding: 2px;vertical-align: bottom;">';
        
$html .= is_wp_error$message ) ? $message->get_error_message() : $message;
        
$html .= '</p>';
        
$html .= '</div>';

        return 
$html;
    }

    
/**
     * Get an error string for all errors in a WP_Error isntance.
     *
     * @param WP_Error $error
     *
     * @return string[]
     */
    
public static function get_error_stringsWP_Error $error ) {
        
$messages = array();

        foreach ( 
$error->get_error_codes() as $code ) {
            foreach ( 
$error->get_error_messages$code ) as $str ) {
                
$messages[] = $str;
            }
        }

        return 
$messages;
    }

    
/**
     * Get a WordPress user object.
     *
     * @param int|string|WP_User|bool $user Either the user ID ( must be an int ), the username, a WP_User object,
     *                                      or false to retrieve the currently logged-in user.
     *
     * @return WP_User|false
     */
    
public static function get_user$user false ) {
        if ( 
$user instanceof WP_User ) {
            return 
$user;
        }

        if ( 
false === $user ) {
            
$user wp_get_current_user();
        } elseif ( 
is_int$user ) ) {
            
$user get_user_by'id'$user );
        } elseif ( 
is_string$user ) ) {
            
$user get_user_by'login'$user );
        } elseif ( 
is_object$user ) && isset( $user->ID ) ) {
            
$user get_user_by'id'$user->ID );
        } else {
            if ( 
is_object$user ) ) {
                
$type 'object(' get_class$user ) . ')';
            } else {
                
$type gettype$user );
            }

            
error_log'ITSEC_Lib::get_user() called with an invalid $user argument. Received $user variable of type: ' $type );

            
wp_die'Internal Server Error' );
        }

        if ( 
$user instanceof WP_User ) {
            return 
$user;
        }

        return 
false;
    }

    
/**
     * Evaluate a password's strength.
     *
     * @param string $password
     * @param array  $penalty_strings Additional strings that if found within the password, will decrease the strength.
     *
     * @return ITSEC_Zxcvbn_Results
     */
    
public static function get_password_strength_results$password$penalty_strings = array() ) {
        if ( ! isset( 
$GLOBALS['itsec_zxcvbn'] ) ) {
            require_once( 
ITSEC_Core::get_core_dir() . '/lib/itsec-zxcvbn-php/zxcvbn.php' );
            
$GLOBALS['itsec_zxcvbn'] = new ITSEC_Zxcvbn();
        }

        return 
$GLOBALS['itsec_zxcvbn']->test_password$password$penalty_strings );
    }

    
/**
     * Retrieve the URL to a website to lookup the location of an IP address.
     *
     * @param string|bool $ip IP address to lookup, or false to return a URL to their home page.
     *
     * @return string
     */
    
public static function get_trace_ip_link$ip false ) {
        if ( empty( 
$ip ) ) {
            
$link 'https://www.iptrackeronline.com/ithemes.php';
        } else {
            
$link 'http://www.iptrackeronline.com/ithemes.php?ip_address=' urlencode$ip );
        }

        return 
apply_filters'itsec_ip_details_link'$link$ip );
    }

    
/**
     * Whenever a login fails, collect details of the attempt, and forward them to modules.
     *
     * @param string $username
     */
    
public static function handle_wp_login_failed$username ) {
        
$details self::get_login_details();

        
do_action'itsec-handle-failed-login'$username$details );
    }

    public static function 
get_login_details() {
        
$authentication_types = array();

        if ( isset( 
$_SERVER['HTTP_AUTHORIZATION'] ) ) {
            
$http_auth_type substr$_SERVER['HTTP_AUTHORIZATION'], 0);

            if ( 
'Basic ' === $http_auth_type ) {
                
$authentication_types[] = 'header_http_basic_auth';
            } elseif ( 
'OAuth ' === $http_auth_type ) {
                
$authentication_types[] = 'header_http_oauth';
            }
        }

        if ( isset( 
$_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ) ) {
            
$authentication_types[] = 'header_http_basic_auth';
        }

        if ( ! empty( 
$_GET['oauth_consumer_key'] ) ) {
            
$authentication_types[] = 'query_oauth';
        }

        if ( ! empty( 
$_POST['oauth_consumer_key'] ) ) {
            
$authentication_types[] = 'post_oauth';
        }

        if ( 
defined'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
            
$source               'xmlrpc';
            
$authentication_types = array( 'username_and_password' );
        } elseif ( 
defined'REST_REQUEST' ) && REST_REQUEST ) {
            
$source                 'rest_api';
            
$authentication_types[] = 'cookie';
        } else {
            
$source               'wp-login.php';
            
$authentication_types = array( 'username_and_password' );
        }

        
$details compact'source''authentication_types' );

        return 
apply_filters'itsec-filter-failed-login-details'$details );
    }

    
/**
     * Reliably provides the URL path.
     *
     * It optionally takes a prefix that will be stripped from the path, if present. This is useful for use to get site
     * URL paths without the site's subdirectory.
     *
     * Trailing slashes are not preserved.
     *
     * @param string $url    The URL to pull the path from.
     * @param string $prefix [optional] A string prefix to be removed from the path.
     *
     * @return string The URL path.
     */
    
public static function get_url_path$url$prefix '' ) {
        
$path = (string) parse_url$urlPHP_URL_PATH );
        
$path untrailingslashit$path );

        if ( ! empty( 
$prefix ) && === strpos$path$prefix ) ) {
            return 
substr$pathstrlen$prefix ) );
        }

        return 
'';
    }

    
/**
     * Returns the current request path without the protocol, domain, site subdirectories, or query args.
     *
     * This function returns "wp-login.php" when requesting http://example.com/site-path/wp-login.php?action=register.
     *
     * @return string The requested site path.
     */
    
public static function get_request_path() {
        if ( ! isset( 
$GLOBALS['__itsec_lib_get_request_path'] ) ) {
            
$request_uri                             preg_replace'|//+|''/'$_SERVER['REQUEST_URI'] );
            
$GLOBALS['__itsec_lib_get_request_path'] = self::get_url_path$request_uriself::get_home_root() );
        }

        return 
$GLOBALS['__itsec_lib_get_request_path'];
    }

    
/**
     * Acquire a lock.
     *
     * @since 6.3.0
     *
     * @param string $name       Lock name.
     * @param int    $expires_in Number of seconds to hold the lock for.
     *
     * @return bool
     */
    
public static function get_lock$name$expires_in 30 ) {

        
/** @var \wpdb $wpdb */
        
global $wpdb;
        
$main_options $wpdb->base_prefix 'options';

        
$lock       "itsec-lock-{$name}";
        
$now        ITSEC_Core::get_current_time_gmt();
        
$release_at $now $expires_in;

        if ( 
is_multisite() ) {
            
$result $wpdb->query$wpdb->prepare"INSERT IGNORE INTO `{$main_options}` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */"$lock$release_at ) );
        } else {
            
$result $wpdb->query$wpdb->prepare"INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */"$lock$release_at ) );
        }

        
// The lock exists. See if it has expired.
        
if ( ! $result ) {

            if ( 
is_multisite() && get_current_blog_id() !== ) {
                
$locked_until $wpdb->get_var$wpdb->prepare"SELECT `option_value` FROM {$main_options} WHERE `option_name` = %s"$main_options ) );
            } else {
                
$locked_until get_option$lock );
            }

            if ( ! 
$locked_until ) {
                
// Can't write or read the lock. Bail due to an unknown and hopefully temporary error.
                
return false;
            }

            if ( 
$locked_until $now ) {
                
// The lock still exists and has not expired.
                
return false;
            }
        }

        
// Ensure that the lock is set properly by triggering all the regular actions and filters.
        
if ( ! is_multisite() || get_current_blog_id() === ) {
            
update_option$lock$release_at );
        } else {
            
$wpdb->update$main_options, array( 'option_value' => $release_at ), array( 'option_name' => $lock ) );

            if ( 
function_exists'wp_cache_switch_to_blog' ) ) {
                
// Update persistent object caches
                
$current get_current_blog_id();
                
wp_cache_switch_to_blog);

                
$alloptions wp_cache_get'alloptions' );

                if ( 
is_array$alloptions ) && isset( $alloptions$lock ] ) ) {
                    
$alloptions$lock ] = $release_at;
                    
wp_cache_set'alloptions'$alloptions'options' );
                } else {
                    
wp_cache_set$lock$release_at'options' );
                }

                
wp_cache_switch_to_blog$current );
            }
        }

        return 
true;
    }

    
/**
     * Release a lock.
     *
     * @since 6.3.0
     *
     * @param string $name The lock name.
     */
    
public static function release_lock$name ) {

        
$lock "itsec-lock-{$name}";

        if ( 
is_multisite() && get_current_blog_id() !== ) {

            
/** @var \wpdb $wpdb */
            
global $wpdb;
            
$main_options $wpdb->base_prefix 'options';

            
$wpdb->delete$main_options, array( 'option_name' => $lock ) );

            if ( 
function_exists'wp_cache_switch_to_blog' ) ) {
                
// Update persistent object caches
                
$current get_current_blog_id();
                
wp_cache_switch_to_blog);

                
$alloptions wp_cache_get'alloptions' );

                if ( 
is_array$alloptions ) && isset( $alloptions$lock ] ) ) {
                    unset( 
$alloptions$lock ] );
                    
wp_cache_set'alloptions'$alloptions'options' );
                } else {
                    
wp_cache_delete$lock'options' );
                }

                
wp_cache_switch_to_blog$current );
            }
        } else {
            
delete_option$lock );
        }
    }

    public static function 
has_lock$name ) {

        
/** @var \wpdb $wpdb */
        
global $wpdb;
        
$main_options $wpdb->base_prefix 'options';

        
$lock "itsec-lock-{$name}";

        if ( 
is_multisite() ) {
            
$result $wpdb->get_var$wpdb->prepare"SELECT `option_value` FROM `{$main_options}` WHERE `option_name` = %s"$lock ) );
        } else {
            
$result $wpdb->get_var$wpdb->prepare"SELECT `option_value` FROM `$wpdb->options` WHERE `option_name` = %s"$lock ) );
        }

        if ( ! 
$result ) {
            return 
false;
        }

        if ( (int) 
$result ITSEC_Core::get_current_time_gmt() ) {
            return 
false;
        }

        return 
true;
    }

    
/**
     * Clear any expired locks.
     *
     * The vast majority of locks should be cleared by the same process that acquires them, however, this will clear locks that remain
     * due to a time out or fatal error.
     *
     * @since 3.8.0
     */
    
public static function delete_expired_locks() {

        
/** @var \wpdb $wpdb */
        
global $wpdb;
        
$main_options $wpdb->base_prefix 'options';

        
$rows $wpdb->get_results$wpdb->prepare(
            
"SELECT `option_name` FROM {$main_options} WHERE `option_name` LIKE %s AND `option_value` < %d",
            
$wpdb->esc_like'itsec-lock-' ) . '%'ITSEC_Core::get_current_time_gmt()
        ) );

        if ( 
$rows ) {
            if ( 
is_multisite() && get_current_blog_id() !== ) {
                if ( 
function_exists'wp_cache_switch_to_blog' ) ) {
                    
// Update persistent object caches
                    
$current get_current_blog_id();
                    
wp_cache_switch_to_blog);

                    
$alloptions wp_cache_get'alloptions' );
                    
$set_all    false;

                    foreach ( 
$rows as $row ) {
                        
$lock $row->option_name;

                        if ( 
is_array$alloptions ) && isset( $alloptions$lock ] ) ) {
                            unset( 
$alloptions$lock ] );
                            
$set_all true;
                        } else {
                            
wp_cache_delete$lock'options' );
                        }
                    }

                    if ( 
$set_all ) {
                        
wp_cache_set'alloptions'$alloptions );
                    }

                    
wp_cache_switch_to_blog$current );
                }

                
$wpdb->query$wpdb->prepare(
                    
"DELETE FROM {$main_options} WHERE `option_name` LIKE %s AND `option_value` < %d",
                    
$wpdb->esc_like'itsec-lock-' ) . '%'ITSEC_Core::get_current_time_gmt()
                ) );
            } else {
                foreach ( 
$rows as $row ) {
                    
delete_option$row->option_name );
                }
            }
        }
    }

    
/**
     * Replace a tag with a given value.
     *
     * Will look in the content for a tag matching the {{ $tag_name }} pattern.
     *
     * @param string $content
     * @param string $tag
     * @param string $replacement
     *
     * @return string
     */
    
public static function replace_tag$content$tag$replacement ) {
        return 
preg_replace'/{{ \$' preg_quote$tag'/' ) . ' }}/'$replacement$content );
    }

    
/**
     * Replace multiple tags.
     *
     * @param string $content
     * @param array  $tags Array of tag names to replacements.
     *
     * @return string
     */
    
public static function replace_tags$content$tags ) {
        foreach ( 
$tags as $tag => $replacement ) {
            
$content self::replace_tag$content$tag$replacement );
        }

        return 
$content;
    }

    
/**
     * Get a percentage value indicating the probability that the site supports SSL.
     *
     * The need for a probability value is that a site could appear to support SSL yet the certificate is self-signed.
     *
     * @return int
     */
    
public static function get_ssl_support_probability() {
        if ( 
is_ssl() ) {
            
$probability 50// The site appears to be on an SSL connection but it could be self-signed or otherwise
            // not valid to a visitor.
        
} else {
            
$probability 0;
        }

        return 
apply_filters'itsec-ssl-support-probability'$probability );
    }

    
/**
     * Format a date using date_i18n and convert the time from GMT to local.
     *
     * @author Modified from ticket #25331
     *
     * @param int    $timestamp
     * @param string $format Specify the format. If blank, will default to the date and time format settings.
     *
     * @return string
     */
    
public static function date_format_i18n_and_local_timezone$timestamp$format '' ) {

        if ( ! 
$format ) {
            
$format get_option'date_format' ) . ' ' get_option'time_format' );
        }

        return 
date_i18n$formatstrtotimeget_date_from_gmtdate'Y-m-d H:i:s'$timestamp ) ) ) );
    }

    
/**
     * Get the value of an option directly from the database, bypassing any caching.
     *
     * @param string $option
     *
     * @return array|mixed
     */
    
public static function get_uncached_option$option ) {
        
/** @var $wpdb \wpdb */
        
global $wpdb;

        
$storage = array();

        if ( 
is_multisite() ) {
            
$network_id get_current_site()->id;
            
$row        $wpdb->get_row$wpdb->prepare"SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d"$option$network_id ) );

            if ( 
is_object$row ) ) {
                
$storage maybe_unserialize$row->meta_value );
            }
        } else {
            
$row $wpdb->get_row$wpdb->prepare"SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1"$option ) );

            if ( 
is_object$row ) ) {
                
$storage maybe_unserialize$row->option_value );
            }
        }

        return 
$storage;
    }

    
/**
     * Get a dot nested value from an array.
     *
     * @param array  $array
     * @param string $key
     * @param mixed  $default
     *
     * @return mixed
     */
    
public static function array_get$array$key$default null ) {
        if ( ! 
is_array$array ) ) {
            return 
$default;
        }

        if ( isset( 
$array$key ] ) ) {
            return 
$array$key ];
        }

        if ( 
strpos$key'.' ) === false ) {
            return isset( 
$array$key ] ) ? $array$key ] : $default;
        }

        foreach ( 
explode'.'$key ) as $segment ) {
            if ( 
is_array$array ) && isset( $array$segment ] ) ) {
                
$array $array$segment ];
            } else {
                return 
$default;
            }
        }

        return 
$array;
    }

    
/**
     * Set an array item to a given value using "dot" notation.
     *
     * @param array  $array
     * @param string $key
     * @param mixed  $value
     *
     * @return array
     */
    
public static function array_set$array$key$value ) {
        
$keys   explode'.'$key );
        
$modify = &$array;

        while ( 
count$keys ) > ) {
            
$key array_shift$keys );
            
// If the key doesn't exist at this depth, we will just create an empty array
            // to hold the next value, allowing us to create the arrays to hold final
            // values at the correct depth. Then we'll keep digging into the array.
            
if ( ! isset( $modify$key ] ) || ! is_array$modify$key ] ) ) {
                
$modify$key ] = [];
            }

            
$modify = &$modify$key ];
        }

        
$modifyarray_shift$keys ) ] = $value;

        return 
$array;
    }

    public static function 
print_r$data$args = array() ) {
        require_once( 
ITSEC_Core::get_core_dir() . '/lib/debug.php' );

        
ITSEC_Debug::print_r$data$args );
    }

    public static function 
get_print_r$data$args = array() ) {
        require_once( 
ITSEC_Core::get_core_dir() . '/lib/debug.php' );

        return 
ITSEC_Debug::get_print_r$data$args );
    }

    
/**
     * Check if WP Cron appears to be running properly.
     *
     * @return bool
     */
    
public static function is_cron_working() {
        
$working ITSEC_Modules::get_setting'global''cron_status' );

        return 
$working === 1;
    }

    
/**
     * Should we be using Cron.
     *
     * @return bool
     */
    
public static function use_cron() {
        return 
ITSEC_Modules::get_setting'global''use_cron' );
    }

    
/**
     * Schedule a test to see if a user should be suggested to enable the Cron scheduler.
     */
    
public static function schedule_cron_test() {

        if ( 
defined'ITSEC_DISABLE_CRON_TEST' ) && ITSEC_DISABLE_CRON_TEST ) {
            return;
        }

        if ( 
$crons _get_cron_array() ) {
            foreach ( 
$crons as $timestamp => $cron ) {
                if ( isset( 
$cron['itsec_cron_test'] ) ) {
                    return;
                }
            }
        }

        
// Get a random time in the next 6-18 hours on a random minute.
        
$time ITSEC_Core::get_current_time_gmt() + mt_rand618 ) * HOUR_IN_SECONDS mt_rand160 ) * MINUTE_IN_SECONDS;
        
wp_schedule_single_event$time'itsec_cron_test', array( $time ) );
        
ITSEC_Modules::set_setting'global''cron_test_time'$time );
    }

    
/**
     * Remove the forward slash.
     *
     * @param string $string
     *
     * @return string
     */
    
public static function unfwdslash$string ) {
        return 
ltrim$string'/' );
    }

    
/**
     * Add a forward slash.
     *
     * @param string $string
     *
     * @return string
     */
    
public static function fwdslash$string ) {
        return 
'/' self::unfwdslash$string );
    }

    
/**
     * Enqueue the itsec_util script.
     *
     * Will only be included once per page.
     *
     * @param array $args
     */
    
public static function enqueue_util$args = array() ) {

        static 
$enqueued false;

        if ( 
$enqueued ) {
            return;
        }

        
$translations = array(
            
'ajax_invalid'      => new WP_Error'itsec-settings-page-invalid-ajax-response'__'An "invalid format" error prevented the request from completing as expected. The format of data returned could not be recognized. This could be due to a plugin/theme conflict or a server configuration issue.''better-wp-security' ) ),
            
'ajax_forbidden'    => new WP_Error'itsec-settings-page-forbidden-ajax-response: %1$s "%2$s"'__'A "request forbidden" error prevented the request from completing as expected. The server returned a 403 status code, indicating that the server configuration is prohibiting this request. This could be due to a plugin/theme conflict or a server configuration issue. Please try refreshing the page and trying again. If the request continues to fail, you may have to alter plugin settings or server configuration that could account for this AJAX request being blocked.''better-wp-security' ) ),
            
'ajax_not_found'    => new WP_Error'itsec-settings-page-not-found-ajax-response: %1$s "%2$s"'__'A "not found" error prevented the request from completing as expected. The server returned a 404 status code, indicating that the server was unable to find the requested admin-ajax.php file. This could be due to a plugin/theme conflict, a server configuration issue, or an incomplete WordPress installation. Please try refreshing the page and trying again. If the request continues to fail, you may have to alter plugin settings, alter server configurations, or reinstall WordPress.''better-wp-security' ) ),
            
'ajax_server_error' => new WP_Error'itsec-settings-page-server-error-ajax-response: %1$s "%2$s"'__'A "internal server" error prevented the request from completing as expected. The server returned a 500 status code, indicating that the server was unable to complete the request due to a fatal PHP error or a server problem. This could be due to a plugin/theme conflict, a server configuration issue, a temporary hosting issue, or invalid custom PHP modifications. Please check your server\'s error logs for details about the source of the error and contact your hosting company for assistance if required.''better-wp-security' ) ),
            
'ajax_unknown'      => new WP_Error'itsec-settings-page-ajax-error-unknown: %1$s "%2$s"'__'An unknown error prevented the request from completing as expected. This could be due to a plugin/theme conflict or a server configuration issue.''better-wp-security' ) ),
            
'ajax_timeout'      => new WP_Error'itsec-settings-page-ajax-error-timeout: %1$s "%2$s"'__'A timeout error prevented the request from completing as expected. The site took too long to respond. This could be due to a plugin/theme conflict or a server configuration issue.''better-wp-security' ) ),
            
'ajax_parsererror'  => new WP_Error'itsec-settings-page-ajax-error-parsererror: %1$s "%2$s"'__'A parser error prevented the request from completing as expected. The site sent a response that jQuery could not process. This could be due to a plugin/theme conflict or a server configuration issue.''better-wp-security' ) ),
        );

        foreach ( 
$translations as $i => $translation ) {
            
$messages ITSEC_Response::get_error_strings$translation );

            if ( 
$messages ) {
                
$translations$i ] = $messages[0];
            }
        }

        
wp_enqueue_script'itsec-util'plugins_url'admin-pages/js/util.js'__FILE__ ), array( 'jquery' ), ITSEC_Core::get_plugin_build(), true );
        
wp_localize_script'itsec-util''itsec_util', array(
            
'ajax_action'  => isset( $args['action'] ) ? $args['action'] : 'itsec_settings_page',
            
'ajax_nonce'   => wp_create_nonce( isset( $args['nonce'] ) ? $args['nonce'] : 'itsec-settings-nonce' ),
            
'translations' => $translations,
        ) );

        
$enqueued true;
    }

    
/**
     * Replace the prefix of a target string with another prefix.
     *
     * If the given target does not start with the current prefix, the string
     * will be returned unmodified.
     *
     * @param string $target      String to perform replacement on.
     * @param string $current     The current prefix.
     * @param string $replacement The new prefix.
     *
     * @return string
     */
    
public static function replace_prefix$target$current$replacement ) {
        if ( 
!== strpos$target$current ) ) {
            return 
$target;
        }

        
$stripped substr$targetstrlen$current ) );

        return 
$replacement $stripped;
    }

    
/**
     * Convert an iterator to an array.
     *
     * @param iterable $iterator
     *
     * @return array
     */
    
public static function iterator_to_array$iterator ) {

        if ( 
is_array$iterator ) ) {
            return 
$iterator;
        }

        
// Available since PHP 5.1, but SPL which isn't guaranteed.
        
if ( function_exists'iterator_to_array' ) ) {
            return 
iterator_to_array$iterator );
        }

        
$array = array();

        foreach ( 
$iterator as $key => $value ) {
            
$array$key ] = $value;
        }

        return 
$array;
    }

    
/**
     * Inserts a new key/value before the key in the array.
     *
     * @param string $key       The key to insert before.
     * @param array  $array     An array to insert in to.
     * @param string $new_key   The key to insert.
     * @param mixed  $new_value The value to insert.
     *
     * @return array
     */
    
public static function array_insert_before$key$array$new_key$new_value ) {
        if ( 
array_key_exists$key$array ) ) {
            
$new = array();
            foreach ( 
$array as $k => $value ) {
                if ( 
$k === $key ) {
                    
$new$new_key ] = $new_value;
                }
                
$new$k ] = $value;
            }

            return 
$new;
        }

        
$array$new_key ] = $new_value;

        return 
$array;
    }

    
/**
     * Insert an element after a given key.
     *
     * @param string|int $key
     * @param array      $array
     * @param string|int $new_key
     * @param mixed      $new_value
     *
     * @return array
     */
    
public static function array_insert_after$key$array$new_key$new_value ) {
        if ( 
array_key_exists$key$array ) ) {
            
$new = array();
            foreach ( 
$array as $k => $value ) {
                
$new$k ] = $value;
                if ( 
$k === $key ) {
                    
$new$new_key ] = $new_value;
                }
            }

            return 
$new;
        }

        
$array$new_key ] = $new_value;

        return 
$array;
    }

    
/**
     * Gets the first key in an array.
     *
     * @param array $arr
     *
     * @return int|string|null
     */
    
public static function array_key_first( array $arr ) {
        if ( 
function_exists'array_key_first' ) ) {
            return 
array_key_first$arr );
        }

        foreach ( 
$arr as $key => $value ) {
            return 
$key;
        }

        return 
null;
    }

    
/**
     * Gets the last ket in an array.
     *
     * @param array $arr
     *
     * @return int|string|null
     */
    
public static function array_key_last( array $arr ) {
        if ( 
function_exists'array_key_last' ) ) {
            return 
array_key_last$arr );
        }

        
end$arr );

        return 
key$arr );
    }

    
/**
     * Plucks a certain field out of each item in the list.
     *
     * Similar to {@see wp_list_pluck()} but it supports using methods.
     *
     * @param array  $list      The list of items.
     * @param string $field     The field or method name to use.
     * @param string $index_key Field from the item to use as keys for the new array.
     *
     * @return array
     */
    
public static function pluck( array $list$field$index_key '' ) {
        
$output = [];

        foreach ( 
$list as $i => $item ) {
            
$key $index_key ? static::get$item$index_key ) : $i;

            
$value = static::get$item$field );

            if ( 
null === $key ) {
                
$output[] = $value;
            } else {
                
$output$key ] = $value;
            }
        }

        return 
$output;
    }

    
/**
     * Get's a value from an array or object.
     *
     * @param array|object $item    The item to retrieve the value from.
     * @param string       $field   The field or method name to use.
     * @param null         $default The default value to return if no value is found.
     *
     * @return mixed|null
     */
    
public static function get$item$field$default null ) {
        if ( 
is_array$item ) ) {
            return isset( 
$item$field ] ) ? $item$field ] : $default;
        }

        if ( 
is_object$item ) ) {
            if ( 
is_callable( [ $item$field ] ) ) {
                return 
$item->{$field}();
            }

            return isset( 
$item->{$field} ) ? $item->{$field} : $default;
        }

        return 
$default;
    }

    
/**
     * Array unique implementation that allows for non-scalar values.
     *
     * Will compare elements using `serialize()`.
     *
     * Keys are preserved. If a numeric array is given, the array will be re-indexed.
     *
     * @param array $array
     *
     * @return array
     */
    
public static function non_scalar_array_unique$array ) {

        
$is_numeric wp_is_numeric_array$array );

        
$hashes = array();

        foreach ( 
$array as $key => $value ) {
            
$hash serialize$value );

            if ( isset( 
$hashes$hash ] ) ) {
                unset( 
$array$key ] );
            } else {
                
$hashes$hash ] = 1;
            }
        }

        if ( 
$is_numeric ) {
            return 
array_values$array );
        }

        return 
$array;
    }

    
/**
     * Parse a complex header that has attributes like quality values.
     *
     * @param string $header
     *
     * @return string[]
     * @example Parsing the Accept-Language header.
     *
     * "en-US,en;q=0.9,de;q=0.8" transforms to:
     *
     * [
     *     'en-US' => [],
     *     'en'    => [ 'q' => 0.9 ],
     *     'de'    => [ 'q' => 0.8' ],
     * ]
     *
     */
    
public static function parse_header_with_attributes$header ) {

        
$parsed = array();
        
$list   explode','$header );

        foreach ( 
$list as $value ) {

            
$attrs = array();
            
$parts explode';'trim$value ) );
            
$main  trim$parts[0], ' <>' );

            foreach ( 
$parts as $part ) {
                if ( 
false === strpos$part'=' ) ) {
                    continue;
                }

                list( 
$key$value ) = array_map'trim'explode'='$part) );

                
$attrs$key ] = trim$value'" ' );
            }

            
$parsed$main ] = $attrs;
        }

        return 
$parsed;
    }

    
/**
     * Is a particular function allowed to be called.
     *
     * Checks disabled functions and the function blacklist.
     *
     * @param string $func
     *
     * @return bool
     */
    
public static function is_func_allowed$func ) {

        static 
$cache = array();
        static 
$disabled;
        static 
$suhosin;

        if ( isset( 
$cache$func ] ) ) {
            return 
$cache$func ];
        }

        if ( 
$disabled === null ) {
            
$disabled preg_split'/\s*,\s*/', (string) ini_get'disable_functions' ) );
        }

        if ( 
$suhosin === null ) {
            
$suhosin preg_split'/\s*,\s*/', (string) ini_get'suhosin.executor.func.blacklist' ) );
        }

        if ( ! 
is_callable$func ) ) {
            return 
$cache$func ] = false;
        }

        if ( 
in_array$func$disabledtrue ) ) {
            return 
$cache$func ] = false;
        }

        if ( 
in_array$func$suhosintrue ) ) {
            return 
$cache$func ] = false;
        }

        return 
$cache$func ] = true;
    }

    
/**
     * Get whatever backup plugin is being used on this site.
     *
     * @return string
     */
    
public static function get_backup_plugin() {

        
$possible = array(
            
'backupbuddy/backupbuddy.php',
            
'updraftplus/updraftplus.php',
            
'backwpup/backwpup.php',
            
'xcloner-backup-and-restore/xcloner.php',
            
'duplicator/duplicator.php',
            
'backup/backup.php',
            
'wp-db-backup/wp-db-backup.php',
            
'backupwordpress/backupwordpress.php',
            
'blogvault-real-time-backup/blogvault.php',
            
'wp-all-backup/wp-all-backup.php',
            
'vaultpress/vaultpress.php',
        );

        
/**
         * Filter the list of possible backup plugins.
         *
         * @param string[] List of Backup Plugin __FILE__.
         */
        
$possible apply_filters'itsec_possible_backup_plugins'$possible );

        if ( ! 
function_exists'is_plugin_active' ) ) {
            require_once( 
ABSPATH 'wp-admin/includes/plugin.php' );
        }

        if ( ! 
function_exists'is_plugin_active' ) ) {
            return 
'';
        }

        foreach ( 
$possible as $file ) {
            if ( 
is_plugin_active$file ) ) {
                return 
$file;
            }
        }

        return 
'';
    }

    
/**
     * Generate a random token.
     *
     * @return string Hex token.
     */
    
public static function generate_token() {

        
$length 64;

        try {
            
$random bin2hexrandom_bytes$length ) );
        } catch ( 
Exception $e ) {
            
$unpacked unpack'H*'wp_generate_password$length 2truetrue ) );
            
$random   reset$unpacked );
        }

        return 
$random;
    }

    
/**
     * Generate a hash of the token for storage.
     *
     * @param string $token
     *
     * @return false|string
     */
    
public static function hash_token$token ) {
        return 
hash_hmacself::get_hash_algo(), $tokenwp_salt() );
    }

    
/**
     * Check if the provided token matches the stored hashed token.
     *
     * @param string $provided_token
     * @param string $hashed_token
     *
     * @return bool
     */
    
public static function verify_token$provided_token$hashed_token ) {

        if ( ! 
$hashed_token || ! $provided_token ) {
            return 
false;
        }

        return 
hash_equals$hashed_tokenself::hash_token$provided_token ) );
    }

    
/**
     * Get the hash algorithm to use.
     *
     * PHP can be compiled without the hash extension and the supported hash algos can be variable. WordPress shims
     * support for md5 and sha1 hashes with hash_hmac.
     *
     * @return string
     */
    
public static function get_hash_algo() {

        if ( ! 
function_exists'hash_algos' ) ) {
            return 
'sha1';
        }

        
$algos hash_algos();

        if ( 
in_array'sha256'$algostrue ) ) {
            return 
'sha256';
        }

        return 
'sha1';
    }

    public static function 
get_url_from_file$file$auto_ssl true$prevent_recursion false ) {
        
$file str_replace'\\''/'$file );

        
$url '';

        
$upload_dir            ITSEC_Core::get_wp_upload_dir();
        
$upload_dir['basedir'] = str_replace'\\''/'$upload_dir['basedir'] );

        if ( 
is_array$upload_dir ) && ( false === $upload_dir['error'] ) ) {
            if ( 
=== strpos$file$upload_dir['basedir'] ) ) {
                
$url str_replace$upload_dir['basedir'], $upload_dir['baseurl'], $file );
            } elseif ( 
false !== strpos$file'wp-content/uploads' ) ) {
                
$path_pattern 'wp-content/uploads';
                
$url_base     $upload_dir['baseurl'];

                if ( 
is_multisite() && ! ( is_main_network() && is_main_site() && defined'MULTISITE' ) ) ) {
                    if ( 
defined'MULTISITE' ) ) {
                        
$mu_path '/sites/' get_current_blog_id();
                    } else {
                        
$mu_path '/' get_current_blog_id();
                    }

                    if ( 
false === strpos$file"$path_pattern$mu_path) ) {
                        
$url_base substr$url_base0, - strlen$mu_path ) );
                    } else {
                        
$path_pattern .= $mu_path;
                    }
                }

                
$url $url_base substr$filestrpos$file$path_pattern ) + strlen$path_pattern ) );
            }
        }

        if ( empty( 
$url ) ) {
            if ( ! isset( 
$GLOBALS['__itsec_cache_wp_content_dir'] ) ) {
                
$GLOBALS['__itsec_cache_wp_content_dir'] = rtrimstr_replace'\\''/'WP_CONTENT_DIR ), '/' );
            }
            if ( ! isset( 
$GLOBALS['__itsec_cache_abspath'] ) ) {
                
$GLOBALS['__itsec_cache_abspath'] = rtrimstr_replace'\\''/'ABSPATH ), '/' );
            }

            if ( 
=== strpos$file$GLOBALS['__itsec_cache_wp_content_dir'] ) ) {
                
$url WP_CONTENT_URL str_replace'\\''/'preg_replace'/^' preg_quote$GLOBALS['__itsec_cache_wp_content_dir'], '/' ) . '/'''$file ) );
            } elseif ( 
=== strpos$file$GLOBALS['__itsec_cache_abspath'] ) ) {
                
$url get_option'siteurl' ) . str_replace'\\''/'preg_replace'/^' preg_quote$GLOBALS['__itsec_cache_abspath'], '/' ) . '/'''$file ) );
            }
        }

        if ( empty( 
$url ) && ! $prevent_recursion ) {
            
$url self::get_url_from_filerealpath$file ), $auto_ssltrue );
        }

        if ( empty( 
$url ) ) {
            return 
'';
        }

        if ( 
$auto_ssl ) {
            
$url self::fix_url$url );
        }

        return 
$url;
    }

    public static function 
get_file_from_url$url ) {
        
$url preg_replace'/^https/''http'$url );
        
$url preg_replace'/\?.*$/'''$url );

        
$file '';

        
$upload_dir ITSEC_Core::get_wp_upload_dir();

        if ( 
is_array$upload_dir ) && ( false === $upload_dir['error'] ) ) {
            if ( 
=== strpos$url$upload_dir['baseurl'] ) ) {
                
$file str_replace$upload_dir['baseurl'], $upload_dir['basedir'], $url );
            } elseif ( 
false !== strpos$url'wp-content/uploads' ) ) {
                
$path_pattern 'wp-content/uploads';
                
$file_base    $upload_dir['basedir'];

                if ( 
is_multisite() && ! ( is_main_network() && is_main_site() && defined'MULTISITE' ) ) ) {
                    if ( 
defined'MULTISITE' ) ) {
                        
$mu_path '/sites/' get_current_blog_id();
                    } else {
                        
$mu_path '/' get_current_blog_id();
                    }

                    if ( 
false === strpos$url"$path_pattern$mu_path) ) {
                        
$file_base substr$file_base0, - strlen$mu_path ) );
                    } else {
                        
$path_pattern .= $mu_path;
                    }
                }

                
$file $file_base substr$urlstrpos$url$path_pattern ) + strlen$path_pattern ) );
            }
        }

        if ( empty( 
$file ) ) {
            if ( ! isset( 
$GLOBALS['__itsec_cache_wp_content_url'] ) ) {
                
$GLOBALS['__itsec_cache_wp_content_url'] = preg_replace'/^https/''http'WP_CONTENT_URL );
            }
            if ( ! isset( 
$GLOBALS['__itsec_cache_siteurl'] ) ) {
                
$GLOBALS['__itsec_cache_siteurl'] = preg_replace'/^https/''http'get_option'siteurl' ) );
            }

            if ( 
=== strpos$url$GLOBALS['__itsec_cache_wp_content_url'] ) ) {
                
$file rtrimWP_CONTENT_DIR'\\\/' ) . preg_replace'/^' preg_quote$GLOBALS['__itsec_cache_wp_content_url'], '/' ) . '/'''$url );
            } elseif ( 
=== strpos$url$GLOBALS['__itsec_cache_siteurl'] ) ) {
                
$file rtrimABSPATH'\\\/' ) . preg_replace'/^' preg_quote$GLOBALS['__itsec_cache_siteurl'], '/' ) . '/'''$url );
            }
        }

        return 
$file;
    }

    public static function 
fix_url$url ) {
        if ( 
is_ssl() ) {
            
$url preg_replace'|^http://|''https://'$url );
        } else {
            
$url preg_replace'|^https://|''http://'$url );
        }

        return 
$url;
    }

    
/**
     * Set a cookie.
     *
     * @param string $name
     * @param string $value
     * @param array  $args
     */
    
public static function set_cookie$name$value$args = array() ) {

        
$args wp_parse_args( array(
            
'length'    => 0,
            
'http_only' => true,
        ), 
$args );

        
$expires $args['length'] ? ITSEC_Core::get_current_time_gmt() + $args['length'] : 0;

        
setcookie$name$value$expiresCOOKIEPATHCOOKIE_DOMAINis_ssl(), $args['http_only'] );
    }

    
/**
     * Clear a cookie.
     *
     * @param string $name
     */
    
public static function clear_cookie$name ) {
        
setcookie$name' 'ITSEC_Core::get_current_time_gmt() - YEAR_IN_SECONDSCOOKIEPATHCOOKIE_DOMAINfalsefalse );
    }

    
/**
     * Is the current request a loopback request.
     *
     * @return bool
     */
    
public static function is_loopback_request() {
        return 
in_arrayself::get_ip(), ITSEC_Modules::get_setting'global''server_ips' ), true );
    }

    
/**
     * Version of {@see wp_slash()} that won't cast numbers to strings.
     *
     * @param array|string $value
     *
     * @return array|string
     */
    
public static function slash$value ) {
        if ( 
is_array$value ) ) {
            foreach ( 
$value as $k => $v ) {
                if ( 
is_array$v ) ) {
                    
$value$k ] = self::slash$v );
                } elseif ( 
is_string$v ) ) {
                    
$value$k ] = addslashes$v );
                }
            }
        } elseif ( 
is_string$value ) ) {
            
$value addslashes$value );
        }

        return 
$value;
    }

    
/**
     * Format as a ISO 8601 date.
     *
     * @param int|string|\DateTimeInterface $date Epoch or strtotime compatible date.
     *
     * @return string|false
     */
    
public static function to_rest_date$date ) {
        if ( ! 
$date ) {
            
$date ITSEC_Core::get_current_time_gmt();
        } elseif ( 
$date instanceof \DateTimeInterface ) {
            
$date $date->getTimestamp();
        } elseif ( ! 
is_int$date ) ) {
            
$date strtotime$date );
        }

        return 
gmdate'Y-m-d\TH:i:sP'$date );
    }

    
/**
     * Flatten an array.
     *
     * @param array $array
     *
     * @return array
     */
    
public static function flatten$array ) {
        if ( ! 
is_array$array ) ) {
            return array( 
$array );
        }

        
$merge = array();

        foreach ( 
$array as $value ) {
            
$merge[] = self::flatten$value );
        }

        return 
$merge call_user_func_array'array_merge'$merge ) : array();
    }

    
/**
     * Preload REST API requests.
     *
     * @param array $requests
     *
     * @return array
     */
    
public static function preload_rest_requests$requests ) {
        
$preload = array();

        foreach ( 
$requests as $key => $config ) {
            if ( 
is_string$config ) ) {
                
$key    $config;
                
$config = array( 'route' => $config );
            }

            
$request = new WP_REST_Request(
                isset( 
$config['method'] ) ? $config['method'] : 'GET',
                
$config['route']
            );

            if ( ! empty( 
$config['query'] ) ) {
                
$request->set_query_params$config['query'] );
            }

            
$response rest_do_request$request );

            if ( 
$response->get_status() >= 200 && $response->get_status() < 300 ) {
                
rest_send_allow_header$responserest_get_server(), $request );

                
$preload$key ] = array(
                    
'body'    => rest_get_server()->response_to_data$response, ! empty( $config['embed'] ) ),
                    
'headers' => $response->get_headers()
                );
            }
        }

        return 
$preload;
    }

    
/**
     * Check if the given string starts with the given needle.
     *
     * @param string $haystack
     * @param string $needle
     *
     * @return bool
     */
    
public static function str_starts_with$haystack$needle ) {
        return 
=== strpos$haystack$needle );
    }

    public static function 
str_ends_with$haystack$needle ) {
        return 
'' === $needle || substr_compare$haystack$needle, - strlen$needle ) ) === 0;
    }

    
/**
     * Load a library class definition.
     *
     * @param string $name
     */
    
public static function load$name ) {
        require_once( 
dirname__FILE__ ) . "/lib/class-itsec-lib-{$name}.php" );
    }

    
/**
     * Combine multiple WP_Error instances.
     *
     * @param WP_Error|null ...$errors
     *
     * @return WP_Error
     */
    
public static function combine_wp_error( ...$errors ) {
        
$combined = new WP_Error();

        
self::add_to_wp_error$combined, ...$errors );

        return 
$combined;
    }

    
/**
     * Add the subsequent WP Error data to the first WP Error instance.
     *
     * @param WP_Error      $add_to
     * @param WP_Error|null ...$errors
     */
    
public static function add_to_wp_errorWP_Error $add_to, ...$errors ) {
        foreach ( 
$errors as $error ) {
            if ( 
$error ) {
                foreach ( 
$error->get_error_codes() as $code ) {
                    foreach ( 
$error->get_error_messages$code ) as $message ) {
                        
$add_to->add$code$message );
                    }

                    
$data $error->get_error_data$code );

                    if ( 
null !== $data ) {
                        
$add_to->add_data$data$code );
                    }
                }
            }
        }
    }

    
/**
     * Render a file with only the given vars in context.
     *
     * @param string $file
     * @param array  $context
     * @param bool   $echo
     *
     * @return string|void
     */
    
public static function render$file$context = array(), $echo true ) {
        
$__echo $echo;
        
$__file $file;

        
extract$contextEXTR_OVERWRITE );
        unset( 
$file$context$echo );

        if ( ! 
$__echo ) {
            
ob_start();
        }

        require( 
$__file );

        if ( ! 
$__echo ) {
            return 
ob_get_clean() ?: '';
        }
    }

    
/**
     * Utility to mark this page as not cacheable.
     */
    
public static function no_cache() {
        
nocache_headers();

        if ( ! 
defined'DONOTCACHEPAGE' ) ) {
            
define'DONOTCACHEPAGE'true );
        }
    }

    
/**
     * Get the WordPress branch version.
     *
     * @return string
     * @example 5.2.4 => 5.2
     *
     */
    
public static function get_wp_branch() {
        
$version get_bloginfo'version' );

        list( 
$major$minor ) = explode'.'$version );

        return 
$major '.' $minor;
    }

    
/**
     * Are two lists equal ignoring order.
     *
     * @param array         $a
     * @param array         $b
     * @param callable|null $cmp
     *
     * @return bool
     */
    
public static function equal_sets( array $a, array $b, callable $cmp null ) {
        if ( 
$cmp ) {
            
usort$a$cmp );
            
usort$b$cmp );
        } else {
            
sort$a );
            
sort$b );
        }

        return 
$a === $b;
    }

    
/**
     * Convert the return val from {@see ITSEC_Modules::set_settings()} to a WP_Error object.
     *
     * @param array $updated
     *
     * @return WP_Error|null
     */
    
public static function updated_settings_to_wp_error$updated ) {
        if ( 
is_wp_error$updated ) ) {
            return 
$updated;
        }

        if ( 
$updated['saved'] ) {
            return 
null;
        }

        if ( 
$updated['errors'] ) {
            
$error self::combine_wp_error( ...$updated['errors'] );
        } else {
            
$error = new \WP_Error'itsec.settings.set-failed'__'Failed to update settings.''better-wp-security' ), [ 'status' => \WP_Http::BAD_REQUEST ] );
        }

        return 
$error;
    }

    
/**
     * Sanitize the list of roles.
     *
     * @param string[] $roles
     *
     * @return array
     */
    
public static function sanitize_roles$roles ) {
        return 
array_filter$roles, static function ( $role ) {
            return (bool) 
get_role$role );
        } );
    }

    
/**
     * Get a snapshot of $_SERVER properties.
     *
     * @return array
     */
    
public static function get_server_snapshot() {
        
$whitelist = [
            
'REQUEST_TIME',
            
'REQUEST_TIME_FLOAT',
            
'REQUEST_METHOD',
            
'HTTPS',
            
'REQUEST_SCHEME',
            
'SERVER_PROTOCOL',
            
'SCRIPT_FILENAME',
        ];

        return 
array_filter$_SERVER, static function ( $key ) use ( $whitelist ) {
            if ( 
$key === 'HTTP_COOKIE' ) {
                return 
false;
            }

            if ( 
self::str_starts_with$key'HTTP_' ) ) {
                return 
true;
            }

            if ( 
self::str_starts_with$key'CONTENT_' ) ) {
                return 
true;
            }

            return 
in_array$key$whitelisttrue );
        }, 
ARRAY_FILTER_USE_KEY );
    }

    
/**
     * Version of {@see is_super_admin()} that operates on a `WP_User` instance.
     *
     * This bypasses an issue where {@see is_super_admin()} cannot be used during the `determine_current_user` filter since
     * `is_super_admin` has a side effect of querying for the current user, causing an infinite loop.
     *
     * @param WP_User $user
     *
     * @return bool
     */
    
public static function is_super_adminWP_User $user ) {
        if ( ! 
$user->exists() ) {
            return 
false;
        }

        if ( 
is_multisite() ) {
            
$super_admins get_super_admins();
            if ( 
is_array$super_admins ) && in_array$user->user_login$super_admins ) ) {
                return 
true;
            }
        } else {
            if ( 
$user->has_cap'delete_users' ) ) {
                return 
true;
            }
        }

        return 
false;
    }

    
/**
     * Performs a {@see dbDelta()} but reports any errors encountered.
     *
     * @param string $delta
     *
     * @return WP_Error
     */
    
public static function db_delta_with_error_handling$delta ) {
        global 
$wpdb$EZSQL_ERROR;

        require_once( 
ABSPATH 'wp-admin/includes/upgrade.php' );

        
$err_count     is_array$EZSQL_ERROR ) ? count$EZSQL_ERROR ) : 0;
        
$showed_errors $wpdb->show_errorsfalse );

        
dbDelta$delta );

        if ( 
$showed_errors ) {
            
$wpdb->show_errors();
        }

        
$wp_error = new WP_Error();

        if ( 
is_array$EZSQL_ERROR ) ) {
            for ( 
$i $err_count$i_max count$EZSQL_ERROR ); $i $i_max$i ++ ) {
                
$error $EZSQL_ERROR$i ];

                if ( empty( 
$error['error_str'] ) || empty( $error['query'] ) || === strpos$error['query'], 'DESCRIBE ' ) ) {
                    continue;
                }

                
$wp_error->add'db_delta_error'$error['error_str'] );
            }
        }

        return 
$wp_error;
    }

    
/**
     * Evaluate whether this site passes the given requirements.
     *
     * @param array $requirements
     *
     * @return WP_Error
     */
    
public static function evaluate_requirements( array $requirements ) {
        
$schema = [
            
'type'                 => 'object',
            
'additionalProperties' => false,
            
'properties'           => [
                
'version' => [
                    
'type'                 => 'object',
                    
'additionalProperties' => false,
                    
'properties'           => [
                        
'pro'  => [
                            
'type'     => 'string',
                            
'required' => true,
                        ],
                        
'free' => [
                            
'type'     => 'string',
                            
'required' => true,
                        ],
                    ],
                ],
            ],
        ];

        
$valid_requirements rest_validate_value_from_schema$requirements$schema );

        if ( 
is_wp_error$valid_requirements ) ) {
            return 
$valid_requirements;
        }

        
$error = new WP_Error();

        foreach ( 
$requirements as $kind => $requirement ) {
            switch ( 
$kind ) {
                case 
'version':
                    
$key     ITSEC_Core::is_pro() ? 'pro' 'free';
                    
$version $requirement$key ];

                    if ( 
version_compareITSEC_Core::get_plugin_version(), $version'<' ) ) {
                        
$error->add(
                            
'version',
                            
sprintf__'Must be running at least version %s of iThemes Security.''better-wp-security' ), $version )
                        );
                    }

                    break;
            }
        }

        return 
$error;
    }

    
/**
     * Converts a JSON Schema to a WP-CLI synopsis.
     *
     * @param array $schema
     *
     * @return array
     */
    
public static function convert_schema_to_cli_synopsis( array $schema ) {
        
$synopsis = [];

        
$required = isset( $schema['required'] ) ? $schema['required'] : [];

        if ( isset( 
$schema['properties'] ) ) {
            foreach ( 
$schema['properties'] as $property => $config ) {
                
$param = [
                    
'name' => $property,
                ];

                if ( 
'boolean' === $config['type'] ) {
                    
$param['type'] = 'flag';
                } else {
                    
$param['type'] = 'assoc';
                }

                if ( 
array_key_exists'default'$config ) ) {
                    
$param['default'] = $config['default'];
                }

                if ( isset( 
$config['enum'] ) ) {
                    
$param['options'] = $config['enum'];
                }

                if ( ( ! isset( 
$config['required'] ) || true !== $config['required'] ) && ! in_array$property$requiredtrue ) ) {
                    
$param['optional'] = true;
                }

                if ( isset( 
$config['description'] ) ) {
                    
$param['description'] = $config['description'];
                }

                
$synopsis[] = $param;
            }
        }

        if ( ! empty( 
$schema['additionalProperties'] ) ) {
            
$synopsis[] = [
                
'type' => 'generic',
            ];
        }

        return 
$synopsis;
    }

    
/**
     * Decode a string with URL-safe Base64.
     *
     * @param string $input A Base64 encoded string
     *
     * @return string A decoded string
     */
    
public static function url_safe_b64_decode$input ) {
        
$remainder strlen$input ) % 4;
        if ( 
$remainder ) {
            
$padlen $remainder;
            
$input  .= str_repeat'='$padlen );
        }

        return 
base64_decodestrtr$input'-_''+/' ) );
    }

    
/**
     * Encode a string with URL-safe Base64.
     *
     * @param string $input The string you want encoded
     *
     * @return string The base64 encode of what you passed in
     */
    
public static function url_safe_b64_encode$input ) {
        return 
str_replace'='''strtrbase64_encode$input ), '+/''-_' ) );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586