Easy Property Listings 3.5.14 Code Reference
  • Package
  • Class
  • Tree
  • Todo
  • Hook Reference

Packages

  • EPL
    • Admin
      • Actions
      • Classes
        • ContactsTable
        • ReportsGraph
        • Welcome
      • Contacts
      • ContactsActions
      • ContactsFunctions
      • Elements
      • Functions
      • Help
      • HelpSingle
      • Menus
      • MenusAddons
      • MenusExtensions
      • MenusLicenses
      • Plugins
      • Reports
      • ReportsGraphing
      • User
    • Assets
      • ScriptsStyles
      • SVG
    • Classes
      • AuthorLoader
      • AuthorMeta
      • Contact
      • Cron
      • CustomPostType
      • Forms
      • License
      • ListingAdvanced
      • ListingElements
      • MetaboxesCustomFields
      • Pagination
      • PropertyMeta
      • RenderFields
      • RestAPI
      • Search
      • Session
      • Updater
    • Compatibility
      • Extensions
      • Functions
      • Shortcodes
    • Functions
      • Actions
      • ConditionalTags
      • ErrorTracking
      • Formatting
      • Front
      • Global
      • Install
      • Pagination
      • Settings
      • Templates
    • Hooks
      • EnergyCertificate
      • ExternalLinks
      • FloorPlan
      • Map
      • ReadMore
      • WebLink
    • Meta
      • InitCustomFields
      • Meta
    • PostTypes
      • Business
      • Commercial
      • CommercialLand
      • Contact
      • Functions
      • Land
      • Property
      • Rental
      • Rural
    • Shortcode
      • CommercialListingSearch
      • ContactForm
      • Listing
      • ListingAdvanced
      • ListingAuction
      • ListingCategory
      • ListingFeature
      • ListingLocation
      • ListingMetaDoc
      • ListingOpen
      • ListingResults
      • ListingSearch
      • Map
    • Taxonomy
      • BusinessCategories
      • ContactTag
      • Features
      • Location
    • Templates
      • Themes
        • iThemes
        • iThemesBuilder
    • Widget
      • Admin
        • Dashboard
      • Classes
        • Author
        • ContactCapture
        • Gallery
        • Listing
        • Search
      • Functions
  • None
  • WordPress
    • Session

Classes

  • EPL_Advanced_Shortcode_Listing
  • EPL_Author
  • EPL_Author_Loader
  • EPL_Author_Meta
  • EPL_Contact
  • EPL_Contact_Reports_Table
  • EPL_CPT
  • EPL_Cron
  • EPL_FORM_BUILDER
  • EPL_Graph
  • EPL_License
  • EPL_Listing_Elements
  • EPL_METABOX
  • EPL_Pagination_Call
  • EPL_Property_Meta
  • EPL_Render_Fields
  • EPL_Rest_API
  • EPL_SEARCH
  • EPL_Search_Fields
  • EPL_Session
  • EPL_SL_Plugin_Updater
  • EPL_Welcome
  • EPL_Widget_Author
  • EPL_Widget_Contact_Capture
  • EPL_Widget_Property_Gallery
  • EPL_Widget_Property_Search
  • EPL_Widget_Recent_Property

Functions

  • EPL
   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 
<?php
/**
 * Front End Functions
 *
 * @package     EPL
 * @subpackage  Functions/Global
 * @copyright   Copyright (c) 2020, Merv Barrett
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Get an option
 *
 * Looks to see if the specified setting exists, returns default if not
 *
 * @param string $key Meta key.
 * @param bool   $default Returns default if not set.
 *
 * @return mixed
 *
 * @since 2.2
 * @since 3.5.2 Added check to identify 0 values so that it's not ignored by empty check.
 */
function epl_get_option( $key = '', $default = false ) {

    global $epl_settings;

    // Check for zeros.
    if ( isset( $epl_settings[ $key ] ) && is_numeric( $epl_settings[ $key ] ) && 0 === (int) $epl_settings[ $key ] ) {
            $value = 0;
    } else {
        // Preserve empty check for rest of the values to preserve the behaviour: if value empty, then return default.
        $value = ! empty( $epl_settings[ $key ] ) ? $epl_settings[ $key ] : $default;
    }

    $value = apply_filters( 'epl_get_option', $value, $key, $default );
    return apply_filters( 'epl_get_option_' . $key, $value, $key, $default );

}

/**
 * Determine if Divi framework is loaded
 *
 * @since 3.1
 */
function epl_is_divi_framework_theme() {
    if ( function_exists( 'et_divi_fonts_url' ) ) {
        return true;
    }
    return false;
}

/**
 * Determine if iThemes Builder framework is loaded
 *
 * @since 1.0
 */
function epl_is_builder_framework_theme() {
    if ( function_exists( 'it_classes_load' ) ) {
        return true;
    }
    return false;
}

/**
 * Determine if Genesis framework is loaded
 *
 * @since 1.0
 */
function epl_is_genesis_framework_theme() {
    if ( function_exists( 'genesis_constants' ) ) {
        return true;
    }
    return false;
}

/**
 * Determine if TwentyTwenty is loaded
 *
 * @since 3.4.14
 */
function epl_is_twenty_twenty_theme() {
    if ( function_exists( 'twentytwenty_theme_support' ) ) {
        return true;
    }
    return false;
}

/**
 * Determine if Avada is loaded
 *
 * @since 3.4.26
 */
function epl_is_avada_theme() {
    if ( function_exists( 'Avada' ) ) {
        return true;
    }
    return false;
}

/**
 * Used in the widgets by appending the registered image sizes
 *
 * @since 1.0
 * @since 3.4.24 Added full size in array.
 */
function epl_get_thumbnail_sizes() {
    global $_wp_additional_image_sizes;
    $sizes = array(
        'full' => array(),
    );
    foreach ( get_intermediate_image_sizes() as $s ) {
        $sizes[ $s ] = array( 0, 0 );
        if ( in_array( $s, array( 'thumbnail', 'medium', 'large' ), true ) ) {
            $sizes[ $s ][0] = get_option( $s . '_size_w' );
            $sizes[ $s ][1] = get_option( $s . '_size_h' );
        } else {
            if ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[ $s ] ) ) {
                $sizes[ $s ] = array( $_wp_additional_image_sizes[ $s ]['width'], $_wp_additional_image_sizes[ $s ]['height'] );
            }
        }
    }
    return $sizes;
}

/**
 * Remote get function
 *
 * @param string $url Url.
 *
 * @return string
 * @since 3.3.5 Removed curl.
 * @since 1.0
 */
function epl_remote_url_get( $url ) {

    $response = wp_remote_get( $url );
    return wp_remote_retrieve_body( $response );
}

/**
 * Register post type to EPL and WordPress
 *
 * @param string $post_type Post type name.
 * @param string $post_type_label Post type label.
 * @param array  $args Arguments.
 *
 * @since 1.0.0
 * @since 3.4.20 flush permalinks after new settings are saved.
 * @since 3.4.26 Set $post_type_label to blank by default.
 */
function epl_register_post_type( $post_type = '', $post_type_label = '', $args = array() ) {
    if ( empty( $post_type ) ) {
        return;
    }

    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['activate_post_types'] ) ) {
        $epl_activate_post_types = $epl_settings['activate_post_types'];
        if ( ! empty( $epl_activate_post_types ) ) {
            if ( in_array( $post_type, $epl_activate_post_types, true ) ) {
                global $epl_active_post_types;
                if ( ! isset( $epl_active_post_types ) ) {
                    $epl_active_post_types = array();
                }
                $epl_active_post_types[ $post_type ] = $post_type_label;
                register_post_type( $post_type, $args );
            }
        }
    }

    if ( isset( $_REQUEST['action'] ) && 'epl_settings' === $_REQUEST['action'] ) { //phpcs:ignore
        update_option( 'epl_rewrite_rules', false );
    }
}

/**
 * Return all the post types that are selected as active by admin
 *
 * @since 1.0
 */
function epl_get_active_post_types() {
    global $epl_active_post_types;
    if ( is_null( $epl_active_post_types ) ) {
        $epl_active_post_types = array();
    }
    return $epl_active_post_types;
}

/**
 * Return all the post types doesn't matter if selected as active or not by admin
 *
 * @since 1.0
 */
function epl_get_post_types() {
    $epl_post_types = array(
        'property'        => __( 'Property (Residential)', 'easy-property-listings' ),
        'land'            => __( 'Land', 'easy-property-listings' ),
        'rental'          => __( 'Rental', 'easy-property-listings' ),
        'rural'           => __( 'Rural', 'easy-property-listings' ),
        'commercial'      => __( 'Commercial', 'easy-property-listings' ),
        'commercial_land' => __( 'Commercial Land', 'easy-property-listings' ),
        'business'        => __( 'Business', 'easy-property-listings' ),
    );
    // allow 3rd party extensions to add custom posts as a part of epl.
    return apply_filters( 'epl_post_types', $epl_post_types );
}

/**
 * Get Currencies
 *
 * @since 1.0
 * @return array $currencies A list of the available currencies
 * @since 3.4.48 Support for Namibian dollar.
 */
function epl_get_currencies() {
    $currencies = array(
        'AUD'  => __( 'Australian Dollars (&#36;)', 'easy-property-listings' ),
        'USD'  => __( 'US Dollars (&#36;)', 'easy-property-listings' ),
        'EUR'  => __( 'Euros (&euro;)', 'easy-property-listings' ),
        'GBP'  => __( 'Pounds Sterling (&pound;)', 'easy-property-listings' ),
        'BRL'  => __( 'Brazilian Real (R&#36;)', 'easy-property-listings' ),
        'CAD'  => __( 'Canadian Dollars (&#36;)', 'easy-property-listings' ),
        'CZK'  => __( 'Czech Koruna', 'easy-property-listings' ),
        'DKK'  => __( 'Danish Krone', 'easy-property-listings' ),
        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'easy-property-listings' ),
        'HUF'  => __( 'Hungarian Forint', 'easy-property-listings' ),
        'INR'  => __( 'Indian Rupee (&#8377;)', 'easy-property-listings' ),
        'RIAL' => __( 'Iranian Rial (&#65020;)', 'easy-property-listings' ),
        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'easy-property-listings' ),
        'JPY'  => __( 'Japanese Yen (&yen;)', 'easy-property-listings' ),
        'MYR'  => __( 'Malaysian Ringgits', 'easy-property-listings' ),
        'MXN'  => __( 'Mexican Peso (&#36;)', 'easy-property-listings' ),
        'NAD'  => __( 'Namibian Dollar (&#36;)', 'easy-property-listings' ),
        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'easy-property-listings' ),
        'NOK'  => __( 'Norwegian Krone', 'easy-property-listings' ),
        'PHP'  => __( 'Philippine Pesos', 'easy-property-listings' ),
        'PLN'  => __( 'Polish Zloty', 'easy-property-listings' ),
        'PKR'  => __( 'Pakistani Rupee', 'easy-property-listings' ),
        'QAR'  => __( 'Qatar Riyal (QAR)', 'easy-property-listings' ),
        'SGD'  => __( 'Singapore Dollar (&#36;)', 'easy-property-listings' ),
        'ZAR'  => __( 'South African Rand (R)', 'easy-property-listings' ),
        'SEK'  => __( 'Swedish Krona', 'easy-property-listings' ),
        'CHF'  => __( 'Swiss Franc', 'easy-property-listings' ),
        'TWD'  => __( 'Taiwan New Dollars', 'easy-property-listings' ),
        'THB'  => __( 'Thai Baht (&#3647;)', 'easy-property-listings' ),
        'TRY'  => __( 'Turkish Lira (&#8378;)', 'easy-property-listings' ),
        'RUB'  => __( 'Russian Rubles', 'easy-property-listings' ),
        'AED'  => __( 'United Arab Emirates, Dirham (AED)', 'easy-property-listings' ),
        'UAH'  => __( 'Ukrainian Hryvnia (&#8372;)', 'easy-property-listings' ),
        'VND'  => __( 'Vietnamese đồng (&#8363;)', 'easy-property-listings' ),
    );
    return apply_filters( 'epl_get_currencies', $currencies );
}

/**
 * Get the store's set currency
 *
 * @since 1.0
 * @return string The currency code
 */
function epl_get_currency() {
    $epl_currency = '';

    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['currency'] ) ) {
        $epl_currency = $epl_settings['currency'];
    }
    return apply_filters( 'epl_currency', $epl_currency );
}

/**
 * Get the currency position
 *
 * @since 1.0
 * @return string The currency symbol position
 */
function epl_get_currency_position() {
    $epl_currency_position = '';

    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['currency_position'] ) ) {
        $epl_currency_position = $epl_settings['currency_position'];
    }
    return apply_filters( 'epl_currency_position', $epl_currency_position );
}

/**
 * Get the currency thousands separator
 *
 * @since 1.0
 * @return string The currency thousands separator
 */
function epl_get_thousands_separator() {
    $epl_thousands_separator = '';

    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['currency_thousands_separator'] ) ) {
        $epl_thousands_separator = $epl_settings['currency_thousands_separator'];
    }
    return apply_filters( 'epl_thousands_separator', $epl_thousands_separator );
}

/**
 * Get the currency decimal separator
 *
 * @since 1.0
 * @return string The currency decimal separator
 */
function epl_get_decimal_separator() {
    $epl_decimal_separator = '';

    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['currency_decimal_separator'] ) ) {
        $epl_decimal_separator = $epl_settings['currency_decimal_separator'];
    }
    return apply_filters( 'epl_decimal_separator', $epl_decimal_separator );
}

/**
 * Get the currency formatted amount
 *
 * @param integer $price The price.
 *
 * @return string Currency Formatted price
 * @since 1.0
 */
function epl_currency_formatted_amount( $price ) {
    $price_format           = apply_filters( 'epl_price_number_format', 'number' );
    $price_format_com_lease = apply_filters( 'epl_price_number_format_commercial_lease', 'number' );

    if ( 'decimal' === $price_format || 'decimal' === $price_format_com_lease ) {
        return epl_currency_filter( epl_format_amount( $price, true ) );
    } else {
        return epl_currency_filter( epl_format_amount( $price, false ) );
    }
}

/**
 * Get labels
 *
 * @param integer $key Settings meta key.
 * @return string
 *
 * @since 2.2
 * @since 3.5.0 New: Display hidden field option.
 */
function epl_labels( $key ) {
    global $epl_settings;
    $field_groups = epl_get_admin_option_fields();
    $epl_labels   = array();
    foreach ( $field_groups as $field_group ) {
        if ( 'labels' === $field_group['id'] || 'address' === $field_group['id'] ) {
            $epl_labels = array_merge( $epl_labels, array_filter( $field_group['fields'] ) );
        }
    }
    foreach ( $epl_labels as $label_key   => $label ) {

        if ( isset( $label['default'] ) && $key === $label['name'] ) {

            $label = isset( $epl_settings[ $key ] ) ? $epl_settings[ $key ] : $label['default'];

            return apply_filters( 'epl_display_' . $key, $label );
        }
    }
}

/**
 * Display or retrieve the current listing address based on user display selection with optional markup.
 *
 * @since 3.3
 *
 * @param string $before   Optional. Markup to prepend to the title. Default empty.
 * @param string $after    Optional. Markup to append to the title. Default empty.
 * @param bool   $country  Optional. Whether to echo or return country. Default false for country.
 * @param bool   $echo     Optional. Whether to echo or return the title. Default true for echo.
 * @return string|void Current post title if $echo is false.
 */
function epl_the_address( $before = '', $after = '', $country = false, $echo = true ) {
    $address = epl_get_the_address();

    if ( strlen( $address ) === 0 ) {
        return;
    }

        $address = $before . $address . $after;

    if ( $echo ) {
        echo wp_kses_post( $address );
    } else {
        return $address;
    }
}

/**
 * Retrieve address based on user display selection.
 *
 * @param array $address_args Address components.
 * @param array $sep          Override default separators for each address components here.
 * @param bool  $country      Return country with true, default false.
 * @param array $prefix       Customise the prefix for each address component.
 *
 * @return string
 * @since 3.3
 * @since 3.4.27 Added support for prefix.
 */
function epl_get_the_address( $address_args = array(), $sep = array(), $country = false, $prefix = array() ) {

    $address = '';

    $address_defaults = array(
        'sub_number'    => '/',
        'lot_number'    => ' ',
        'street_number' => ' ',
        'street'        => ', ',
        'suburb'        => ' ',
        'city'          => ' ',
        'state'         => ' ',
        'postal_code'   => ' ',
        'country'       => ' ',
    );

    $prefix_defaults = array(
        'sub_number'    => '',
        'lot_number'    => '',
        'street_number' => '',
        'street'        => '',
        'suburb'        => '',
        'city'          => '',
        'state'         => '',
        'postal_code'   => '',
        'country'       => '',
    );

    // Override default separators for address components.
    $seps = array_merge( $address_defaults, $sep );

    $prefix = array_merge( $prefix_defaults, $prefix );

    // Output the full address based on user selection.
    if ( empty( $address_args ) ) {
        $address_args = array_keys( $address_defaults );
    }

    foreach ( $address_args as $arg ) {

        if ( isset( $address_defaults[ $arg ] ) ) {

            if ( 'yes' !== get_property_meta( 'property_address_display' ) && in_array( $arg, array( 'sub_number', 'lot_number', 'street_number', 'street' ), true ) ) {
                continue;
            }

            // Country hidden by default.
            if ( true !== $country && in_array( $arg, array( 'country' ), true ) ) {
                continue;
            }

            $value = get_property_meta( 'property_address_' . $arg );

            if ( ! empty( $value ) ) {
                $address .= $prefix[ $arg ] . get_property_meta( 'property_address_' . $arg ) . $seps[ $arg ];
            }
        }
    }

    /**
     * Filters the post title.
     *
     * @since 3.3
     *
     * @param string $title The listing address.
     * @param int    $id    The post ID.
     */
    return apply_filters( 'epl_the_address', $address );
}

/**
 * Display or retrieve the listing status label with optional markup.
 *
 * @since 3.3
 *
 * @param string $before Output string before.
 * @param string $after Output string after.
 * @param bool   $echo Echo the result.
 * @return string/list for values
 */
function epl_the_status( $before = '', $after = '', $echo = true ) {
    $status = epl_get_the_status();

    $status_opts = epl_get_property_status_opts();

    if ( strlen( $status ) === 0 ) {
        return;
    }

    $status = $before . $status_opts[ $status ] . $after;

    if ( $echo ) {
        echo wp_kses_post( $status );
    } else {
        return $status;
    }
}

/**
 * Retrieve listing status.
 *
 * @since 3.3
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function epl_get_the_status( $post = 0 ) {

    $post = get_post( $post );

    $status = get_property_meta( 'property_status' );
    $status = isset( $status ) ? $status : '';
    $id     = isset( $post->ID ) ? $post->ID : 0;

    /**
     * Filters the status.
     *
     * @since 3.3
     *
     * @param string $title The listing status.
     * @param int    $id    The post ID.
     */
    return apply_filters( 'epl_get_the_status', $status, $id );
}

/**
 * Get EPL property meta data based on post id
 *
 * @since 1.0
 * @param string $post_ID The post ID.
 * @param string $meta_key Meta key name.
 * @return string Value.
 */
function epl_get_property_meta( $post_ID = '', $meta_key = '' ) {

    if ( empty( $post_ID ) ) {
        $post_ID = get_the_ID();
    }

    if ( ! empty( $meta_key ) ) {
        $meta_value = trim( get_post_meta( $post_ID, $meta_key, true ) );
    } else {
        $meta_value = get_post_meta( $post_ID, $meta_key );
    }
    return apply_filters( 'epl_get_property_meta_filter', $meta_value );
}

/**
 * Print EPL property meta data
 *
 * @param string $post_ID The post ID.
 * @param string $meta_key Meta key name.
 *
 * @since 1.0.0
 * @since 3.4.26 Set $meta_key variable as blank.
 */
function epl_the_property_meta( $post_ID = '', $meta_key = '' ) {
    $meta_value = epl_get_property_meta( $post_ID, $meta_key );
    echo wp_kses_post( apply_filters( 'epl_the_property_meta_filter', $meta_value ) );
}

/**
 * Taxonomy Location Label
 *
 * @since 1.0
 * @return string Location label.
 */
function epl_tax_location_label() {
    $label_location = '';
    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['label_location'] ) ) {
        $label_location = trim( $epl_settings['label_location'] );
    }
    if ( empty( $label_location ) ) {
        $label_location = __( 'City', 'easy-property-listings' );
    }
    return $label_location;
}

/**
 * Location Label
 *
 * @since 1.0
 * @return string Location label.
 */
function epl_meta_location_label() {
    $label_location = '';
    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['label_suburb'] ) ) {
        $label_location = trim( $epl_settings['label_suburb'] );
    }
    if ( empty( $label_location ) ) {
        $label_location = __( 'City', 'easy-property-listings' );
    }
    return $label_location;
}

/**
 * Display or retrieve the under offer label with optional markup.
 *
 * @since 3.3
 *
 * @param string $before Optional. Markup to prepend to the formatted Under Offer label. Default empty.
 * @param string $after  Optional. Markup to append to the formatted Under Offer label. Default empty.
 * @param bool   $echo   Optional. Whether to echo or return the formatted Under Offer label. Default true for echo.
 * @return string|void Current post title if $echo is false.
 */
function epl_the_under_offer( $before = '', $after = '', $echo = true ) {
    $under_offer = epl_get_the_under_offer();

    $under_offer_label = epl_meta_under_offer_label();

    if ( strlen( $under_offer ) === 0 ) {
        return;
    }

    if ( 'yes' !== strtolower( $under_offer ) && 'sold' !== epl_get_the_status() ) {
        return;
    }

    $under_offer = $before . $under_offer_label . $after;

    if ( $echo ) {
        echo wp_kses_post( $under_offer );
    } else {
        return $under_offer;
    }
}

/**
 * Retrieve listing under offer value.
 *
 * @since 3.3
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string
 */
function epl_get_the_under_offer( $post = 0 ) {

    $post = get_post( $post );

    $under_offer = get_property_meta( 'property_under_offer' );
    $under_offer = 'yes' === get_property_meta( 'property_under_offer' ) && 'sold' !== epl_get_the_status() ? $under_offer : '';
    $id          = isset( $post->ID ) ? $post->ID : 0;

    /**
     * Filters the status.
     *
     * @since 3.3
     *
     * @param string $under_offer The Under Offer status.
     * @param int    $id    The post ID.
     */
    return apply_filters( 'epl_get_the_under_offer', $under_offer, $id );
}

/**
 * Under Offer Label
 *
 * @since 2.1
 * @return string
 */
function epl_meta_under_offer_label() {
    $under_offer = '';
    global $epl_settings;
    if ( ! empty( $epl_settings ) && isset( $epl_settings['label_under_offer'] ) ) {
        $under_offer = trim( $epl_settings['label_under_offer'] );
    }
    if ( empty( $under_offer ) ) {
        $under_offer = __( 'Under Offer', 'easy-property-listings' );
    }
    return $under_offer;
}

/**
 * House Categories Options
 *
 * @since 1.1
 * @return array Categories in array.
 */
function epl_listing_load_meta_property_category() {
    $defaults = array(
        'House'               => __( 'House', 'easy-property-listings' ),
        'Unit'                => __( 'Unit', 'easy-property-listings' ),
        'Townhouse'           => __( 'Townhouse', 'easy-property-listings' ),
        'Villa'               => __( 'Villa', 'easy-property-listings' ),
        'Apartment'           => __( 'Apartment', 'easy-property-listings' ),
        'Flat'                => __( 'Flat', 'easy-property-listings' ),
        'Studio'              => __( 'Studio', 'easy-property-listings' ),
        'Warehouse'           => __( 'Warehouse', 'easy-property-listings' ),
        'DuplexSemi-detached' => __( 'Duplex Semi-detached', 'easy-property-listings' ),
        'Alpine'              => __( 'Alpine', 'easy-property-listings' ),
        'AcreageSemi-rural'   => __( 'Acreage Semi-rural', 'easy-property-listings' ),
        'Retirement'          => __( 'Retirement', 'easy-property-listings' ),
        'BlockOfUnits'        => __( 'Block Of Units', 'easy-property-listings' ),
        'Terrace'             => __( 'Terrace', 'easy-property-listings' ),
        'ServicedApartment'   => __( 'Serviced Apartment', 'easy-property-listings' ),
        'Other'               => __( 'Other', 'easy-property-listings' ),
    );
    return apply_filters( 'epl_listing_meta_property_category', $defaults );
}

/**
 * Custom Meta: Return Value of House Category
 *
 * @since 1.1
 * @param string $key Meta key.
 * @return string the categories in array
 */
function epl_listing_meta_property_category_value( $key ) {
    $array  = epl_listing_load_meta_property_category();
    $key    = (array) $key;
    $values = array();
    foreach ( $key as $single ) {
        $values[] = array_key_exists( $single, $array ) && ! empty( $array[ $single ] ) ? $array[ $single ] : $single;
    }

    $value = implode( ', ', $values );

    return apply_filters( 'epl_property_category_value', $value );
}

/**
 * Custom Meta: Land Categories
 *
 * @since 1.1
 * @return array the categories in array
 */
function epl_listing_load_meta_land_category() {
    $defaults = array(
        'Commercial'  => __( 'Commercial', 'easy-property-listings' ),
        'Residential' => __( 'Residential', 'easy-property-listings' ),
    );
    return apply_filters( 'epl_listing_meta_land_category', $defaults );
}

/**
 * Custom Meta: Return Value of Land Category
 *
 * @param string $key Meta key.
 * @return array the categories in array
 *
 * @since 1.1.0
 */
function epl_listing_meta_land_category_value( $key ) {
    $array = epl_listing_load_meta_land_category();
    $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : '';

    return $value;
}

/**
 * Custom Meta: Commercial Categories
 *
 * @since 1.1
 * @return array the categories in array
 */
function epl_listing_load_meta_commercial_category() {
    $defaults = array(
        'Commercial Farming'    => __( 'Commercial Farming', 'easy-property-listings' ),
        'Land/Development'      => __( 'Land/Development', 'easy-property-listings' ),
        'Hotel/Leisure'         => __( 'Hotel/Leisure', 'easy-property-listings' ),
        'Industrial/Warehouse'  => __( 'Industrial/Warehouse', 'easy-property-listings' ),
        'Medical/Consulting'    => __( 'Medical/Consulting', 'easy-property-listings' ),
        'Offices'               => __( 'Offices', 'easy-property-listings' ),
        'Retail'                => __( 'Retail', 'easy-property-listings' ),
        'Showrooms/Bulky Goods' => __( 'Showrooms/Bulky Goods', 'easy-property-listings' ),
        'Other'                 => __( 'Other', 'easy-property-listings' ),
    );
    return apply_filters( 'epl_listing_meta_commercial_category', $defaults );
}

/**
 * Custom Meta: Return Value of Commercial Category
 *
 * @since 1.1
 * @param string $key Meta key.
 * @return array the categories in array
 */
function epl_listing_load_meta_commercial_category_value( $key ) {
    $array = epl_listing_load_meta_commercial_category();

    if ( is_array( $key ) ) {
        $values = array();
        foreach ( $key as $k ) {
            $values[] = array_key_exists( $k, $array ) && ! empty( $array[ $k ] ) ? $array[ $k ] : ucfirst( $k );
        }
        $value = implode( ', ', $values );
    } else {
        $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : ucfirst( $key );
    }

    return apply_filters( 'epl_meta_commercial_category_value', $value, $key, $array );
}

/**
 * Custom Meta: Commercial Rental Period
 *
 * @since 2.1
 * @return array the categories in array
 */
function epl_listing_load_meta_commercial_rent_period() {
    $defaults = array(
        'annual'            => __( 'P.A.', 'easy-property-listings' ),
        'nnn'               => __( 'NNN', 'easy-property-listings' ),
        'full-service'      => __( 'Full Service', 'easy-property-listings' ),
        'gross-lease-rates' => __( 'Gross Lease Rates', 'easy-property-listings' ),
    );
    return apply_filters( 'epl_listing_meta_commercial_rent_period', $defaults );
}

/**
 * Custom Meta: Return Value of Commercial Rental Period
 *
 * @since 2.1
 * @param string $key Meta key.
 * @return array the categories in array
 */
function epl_listing_load_meta_commercial_rent_period_value( $key ) {
    $array = epl_listing_load_meta_commercial_rent_period();
    $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : '';

    return $value;
}

/**
 * Custom Meta: Rural Categories
 *
 * @since 1.1
 * @return all the categories in array
 */
function epl_listing_load_meta_rural_category() {
    $defaults = array(
        'Cropping'     => __( 'Cropping', 'easy-property-listings' ),
        'Dairy'        => __( 'Dairy', 'easy-property-listings' ),
        'Farmlet'      => __( 'Farmlet', 'easy-property-listings' ),
        'Horticulture' => __( 'Horticulture', 'easy-property-listings' ),
        'Livestock'    => __( 'Livestock', 'easy-property-listings' ),
        'Viticulture'  => __( 'Viticulture', 'easy-property-listings' ),
        'MixedFarming' => __( 'Mixed Farming', 'easy-property-listings' ),
        'Lifestyle'    => __( 'Lifestyle', 'easy-property-listings' ),
        'Other'        => __( 'Other', 'easy-property-listings' ),
    );
    return apply_filters( 'epl_listing_meta_rural_category', $defaults );
}

/**
 * Custom Meta: Return Value of Rural Category
 *
 * @since 1.1
 * @param string $key Meta key.
 * @return all the categories in array
 */
function epl_listing_load_meta_rural_category_value( $key ) {
    $array = epl_listing_load_meta_rural_category();
    $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : '';

    return $value;
}

/**
 * REAXML Date Processing Function for WP All Import and FeedSync
 *
 * Some imports set the current date instead of the date from the REAXML file.
 * Usage in WP All Import Post Date field is:
 * [epl_feedsync_format_date({./@modTime})]
 *
 * @since 1.2
 * @param string $date Date.
 * @return string formatted date
 * @revised 3.3
 */
function epl_feedsync_format_date( $date ) {
    $date_example = '2014-07-22-16:45:56';

    $tempdate = explode( '-', $date );
    $date     = $tempdate[0];
    if ( isset( $tempdate[1] ) ) {
        $date .= '-' . $tempdate[1];
    }
    if ( isset( $tempdate[2] ) ) {
        $date .= '-' . $tempdate[2];
    }
    if ( isset( $tempdate[3] ) ) {
        $date .= ' ' . $tempdate[3];
    }

    return date( 'Y-m-d H:i:s', strtotime( $date ) );
}

/**
 * REAXML Auction Date Processing Function for WP All Import and FeedSync
 *
 * Some imports set the current date instead of the date from the REAXML file.
 * Usage in WP All Import Post Date field is:
 * [epl_feedsync_format_date_auction({AUCDATE[1]},{AUC_TIME[1]})]
 *
 * @since 3.1.7
 * @param string $date Date.
 * @param string $time Time.
 * @return string formatted date
 */
function epl_feedsync_format_date_auction( $date, $time ) {

    $date = str_replace( '/', '-', $date ); // Convert to european date format for strtotime function.
    return date( 'Y-M-d H:i:s', strtotime( $date . ' ' . $time ) );
}

/**
 * REAXML Address Sub Number field for title import
 * processing Function for WP All Import and FeedSync
 *
 * This function adds a / after the $value else returns false.
 * Usage in WP All Import Post Date field is:
 * [epl_feedsync_filter_sub_number({address[1]/subNumber[1]})]
 *
 * @since 1.3
 * @param string $sub_value Address sub value.
 * @return string formatted sub number/
 */
function epl_feedsync_format_sub_number( $sub_value ) {
    if ( $sub_value ) {
        $sub_value = $sub_value . '/';
        return $sub_value;
    }
}

/**
 * REAXML convert currency to integer
 *
 * Processing Function for WP All Import and FeedSync
 *
 * @param string $value Value.
 * @return float|void Currently as number.
 * @since 3.0
 */
function epl_feedsync_format_strip_currency( $value ) {
    if ( $value ) {
        $value = preg_replace( apply_filters( 'epl_feedsync_format_strip_currency_symbol', '/[\$,]/' ), '', $value );
        $value = floatval( $value );
        return $value;
    }
}

/**
 * REAXML convert date/time to adjust for timezone
 *
 * Processing Function for WP All Import and FeedSync
 * [epl_feedsync_switch_date_time({firstDate[1]},"Australia/Perth","Australia/Sydney")]
 *
 * @param bool   $date_time     Switch date time.
 * @param string $old_time_zone Old Timezone.
 * @param string $new_timezone  New timezone.
 * @param string $format        Date format.
 *
 * @return string
 * @throws exception Exception.
 * @since 3.0
 * @since 3.5.3 Update to return local timestamp.
 */
function epl_feedsync_switch_date_time( $date_time = false, $old_time_zone = 'Australia/Perth', $new_timezone = 'Australia/Sydney', $format = 'Y-m-d H:i:s' ) {

    if ( ! $date_time ) {
        $date_time = date( 'Y-m-d H:i:s', epl_get_local_timestamp() );
    }
    if ( ! $old_time_zone ) {
        $old_time_zone = 'Australia/Perth';
    }
    if ( ! $new_timezone ) {
        $new_timezone = 'Australia/Sydney';
    }

    $schedule_date = new DateTime( $date_time, new DateTimeZone( $new_timezone ) );
    $schedule_date->setTimeZone( new DateTimeZone( $old_time_zone ) );
    return $schedule_date->format( $format );

}

/**
 * Renders field array to html
 *
 * @since 2.1
 * @param array  $field Field array.
 * @param string $val Value.
 * @revised 3.3
 */
function epl_render_html_fields( $field = array(), $val = '' ) {
    EPL()->render_fields->render( $field, $val );
}

/**
 * Admin options settings
 *
 * @since 2.1
 * @since 3.5.3 Updated to return local timestamp.
 */
function epl_get_admin_option_fields() {
    global $epl_settings;
    $opts_epl_gallery_n = array();
    for ( $i = 1; $i <= 10; $i++ ) {
        $opts_epl_gallery_n[ $i ] = $i;
    }

    $opts_epl_property_card_excerpt_length = array();
    for ( $i = 10; $i <= 55; $i++ ) {
        $opts_epl_property_card_excerpt_length[ $i ] = $i;
    }

    $opts_epl_features = array();
    for ( $i = 1; $i <= 5; $i++ ) {
        $opts_epl_features[ $i ] = $i;
    }

    $opts_pages = array( '' => __( 'Select Page', 'easy-property-listings' ) );
    $pages      = get_pages();

    if ( ! empty( $pages ) ) {
        foreach ( $pages as $page ) {
            $opts_pages[ $page->ID ] = $page->post_title;
        }
    }

    $get_google_maps_api_key_uri = '<a target="_blank" href="https://developers.google.com/maps/documentation/javascript/get-api-key">' . __( 'Google Maps API Key', 'easy-property-listings' ) . '</a>';

    $epl_currency_positions = array(
        'before' => __( 'Before - $10', 'easy-property-listings' ),
        'after'  => __( 'After - 10$', 'easy-property-listings' ),
    );
    $epl_currency_types     = epl_get_currencies();
    $epl_post_types         = epl_get_post_types();
    if ( ! function_exists( 'get_editable_roles' ) ) {
        require_once ABSPATH . '/wp-admin/includes/user.php';
    }
    $roles  = array(
        'level_10' => __( 'Administrator', 'easy-property-listings' ),
        'level_7'  => __( 'Editor', 'easy-property-listings' ),
        'level_2'  => __( 'Author', 'easy-property-listings' ),
        'level_1'  => __( 'Contributor', 'easy-property-listings' ),
        'level_0'  => __( 'Subscriber', 'easy-property-listings' ),
    );
    $fields = array(
        array(
            'label'  => __( 'Listing Types and Location Taxonomy', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'general',
            'help'   => __( 'Select the listing types you want to enable and press Save Changes. Refresh the page to see your new activated listing types.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(
                array(
                    'name'  => 'activate_post_types',
                    'label' => __( 'Listing Types to Enable', 'easy-property-listings' ),
                    'type'  => 'checkbox',
                    'opts'  => $epl_post_types,
                    'help'  => __( 'Note: If they are not visible on the front end visit Dashboard > Settings > Permalinks and press Save Changes.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_location',
                    'label'   => __( 'Location Taxonomy', 'easy-property-listings' ),
                    'type'    => 'text',
                    'help'    => __( 'After changing this setting visit Dashboard > Settings > Permalinks to save the settings.', 'easy-property-listings' ),
                    'default' => __( 'Location', 'easy-property-listings' ),
                ),
            ),
        ),

        array(
            'label'  => __( 'Address', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'address',
            'help'   => __( 'Use these settings to adjust the address labels to suite your location and address format for your listings.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(

                array(
                    'name'    => 'label_suburb',
                    'label'   => __( 'Suburb/Town/City Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Suburb', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_enable_city_field',
                    'label'   => __( 'Additional Address Field', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        'yes' => __( 'Enable', 'easy-property-listings' ),
                        'no'  => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 'no',
                    'help'    => __( 'Use when you need an additional Municipality/Town/City/Region.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_city',
                    'label'   => __( 'Additional Address Field Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'City', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_state',
                    'label'   => __( 'State/Province/Region Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'State', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_postcode',
                    'label'   => __( 'Postcode/ZIP Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Postcode', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_enable_country_field',
                    'label'   => __( 'Display Country', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        'yes' => __( 'Enable', 'easy-property-listings' ),
                        'no'  => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 'no',
                    'help'    => __( 'Display country with listing address.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_default_country',
                    'label'   => __( 'Default Country', 'easy-property-listings' ),
                    'type'    => 'select',
                    'opts'    => epl_get_countries_list(),
                    'default' => 'Australia',
                    'help'    => __( 'This is used for map when listing has no address details', 'easy-property-listings' ),
                ),

            ),
        ),

        array(
            'label'  => __( 'Labels', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'labels',
            'help'   => __( 'Customise the labels that are used to show the status and information on the archive and individual listing pages.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(

                array(
                    'name'    => 'label_new',
                    'label'   => __( 'New/Just Listed Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'New', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'sticker_new_range',
                    'label'   => __( 'Keep Listings flagged "New" for', 'easy-property-listings' ),
                    'type'    => 'number',
                    'default' => '7',
                    'help'    => __( 'Listings will have a "NEW" Sticker for the defined number of days.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_home_open',
                    'label'   => __( 'Home Open Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Home Open', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_poa',
                    'label'   => __( 'No Price Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'POA', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_under_offer',
                    'label'   => __( 'Under Offer Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Under Offer', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_sold',
                    'label'   => __( 'Sold Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Sold', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_leased',
                    'label'   => __( 'Leased Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Leased', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'label_bond',
                    'label'   => __( 'Rental Bond/Deposit Label', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Bond', 'easy-property-listings' ),
                ),

                array(
                    'name'  => 'display_bond',
                    'label' => __( 'Rental Bond/Deposit Display', 'easy-property-listings' ),
                    'type'  => 'radio',
                    'opts'  => array(
                        1 => __( 'Enable', 'easy-property-listings' ),
                        0 => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'help'  => __( 'Display the Bond/Deposit on rental listings.', 'easy-property-listings' ),
                ),
            ),
        ),

        array(
            'label'  => __( 'Listing Single View', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'general',
            'help'   => __( 'Configure the default options when viewing a single listing.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(
                array(
                    'name'    => 'display_single_gallery',
                    'label'   => __( 'Automatically display image gallery?', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        1 => __( 'Enable', 'easy-property-listings' ),
                        0 => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 1,
                    'help'    => __( 'Images uploaded and attached to a listing will automatically display on the single listing page.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'display_gallery_n',
                    'label'   => __( 'Gallery columns?', 'easy-property-listings' ),
                    'type'    => 'select',
                    'opts'    => $opts_epl_gallery_n,
                    'default' => 4,
                ),

                array(
                    'name'    => 'display_feature_columns',
                    'label'   => __( 'Feature list columns?', 'easy-property-listings' ),
                    'type'    => 'select',
                    'opts'    => $opts_epl_features,
                    'default' => 2,
                ),

                array(
                    'name'  => 'epl_video_width',
                    'label' => __( 'Video width on single listings', 'easy-property-listings' ),
                    'type'  => 'number',
                    'help'  => __( 'Width should be in pixels', 'easy-property-listings' ),
                ),
            ),
        ),

        array(
            'label'  => __( 'Listing Archive View', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'general',
            'help'   => __( 'Configure the default options for when viewing the archive listing pages.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(
                array(
                    'name'    => 'display_excerpt_length',
                    'label'   => __( 'Excerpt words', 'easy-property-listings' ),
                    'type'    => 'select',
                    'opts'    => $opts_epl_property_card_excerpt_length,
                    'default' => 10,
                    'help'    => __( 'This is ignored when using manual excerpts.', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'display_archive_view_type',
                    'label'   => __( 'Listing view type', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        'list' => __( 'List', 'easy-property-listings' ),
                        'grid' => __( 'Grid', 'easy-property-listings' ),
                    ),
                    'default' => 'list',
                ),

                array(
                    'name'    => 'use_fancy_navigation',
                    'label'   => __( 'Fancy pagination', 'easy-property-listings' ),
                    'type'    => 'select',
                    'opts'    => array(
                        0 => __( 'No, use WordPress default pagination', 'easy-property-listings' ),
                        1 => __( 'Yes, use fancy navigation', 'easy-property-listings' ),
                    ),
                    'default' => 0,
                ),
            ),
        ),

        array(
            'label'  => __( 'Search Widget: Tab Labels', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'labels',
            'help'   => __( 'Customise the tab labels of the EPL - Search Widget or [listing_search] shortcode.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(
                array(
                    'name'    => 'widget_label_all',
                    'label'   => __( 'All', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'All', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'widget_label_property',
                    'label'   => __( 'Property', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Property', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'widget_label_land',
                    'label'   => __( 'Land', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Land', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'widget_label_rental',
                    'label'   => __( 'Rental', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Rental', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'widget_label_rural',
                    'label'   => __( 'Rural', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Rural', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'widget_label_commercial',
                    'label'   => __( 'Commercial', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Commercial', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'widget_label_commercial_land',
                    'label'   => __( 'Commercial Land', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Commercial Land', 'easy-property-listings' ),
                ),
                array(
                    'name'    => 'widget_label_business',
                    'label'   => __( 'Business', 'easy-property-listings' ),
                    'type'    => 'text',
                    'default' => __( 'Business', 'easy-property-listings' ),
                ),
            ),
        ),

        array(
            'label'  => __( 'Listings', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'admin_general',
            'help'   => __( 'Use the following settings to change how the Dashboard > Property or any listing of the types you have enabled display.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(

                array(
                    'name'    => 'epl_max_graph_sales_price',
                    'label'   => __( 'Graph Max', 'easy-property-listings' ),
                    'type'    => 'number',
                    'default' => '2000000',
                    'help'    => __( 'Used for bar chart display on listings for sale.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_max_graph_rent_price',
                    'label'   => __( 'Graph Rental Max', 'easy-property-listings' ),
                    'type'    => 'number',
                    'default' => '2000',
                    'help'    => __( 'Rental range.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_admin_thumb_size',
                    'label'   => __( 'Image size', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        'admin-list-thumb'      => __( '100 X 100', 'easy-property-listings' ),
                        'epl-image-medium-crop' => __( '300 X 200', 'easy-property-listings' ),
                    ),
                    'default' => 'admin-list-thumb',
                    'help'    => __( 'Size of the image shown in listing columns in admin area', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'admin_unique_id',
                    'label'   => __( 'Unique Listing ID column', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        1 => __( 'Enable', 'easy-property-listings' ),
                        0 => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 0,
                ),

                array(
                    'name'    => 'debug',
                    'label'   => __( 'Geocode Lat/Long results column', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        1 => __( 'Enable', 'easy-property-listings' ),
                        0 => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 0,
                ),

                array(
                    'name'    => 'display_hidden_fields',
                    'label'   => __( 'Display Hidden Fields', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        1 => __( 'Enable', 'easy-property-listings' ),
                        0 => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'help'    => __( 'Display hidden fields on the edit listing screen.', 'easy-property-listings' ),
                    'default' => 0,
                ),
            ),
        ),

        array(
            'label'  => __( 'Theme Setup', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'theme_setup',
            'help'   => __( 'The following settings will use your theme templates to generate your listing pages. If your listings appear too wide or your sidebar is in the wrong place enable theme compatibility. When this is enabled you can use the included shortcodes like [listing post_type="property" tools_top="on"] to display your listings with sorting and grid options.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(

                array(
                    'name'    => 'epl_feeling_lucky',
                    'label'   => __( 'Theme Compatibility', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        'on'  => __( 'Enable', 'easy-property-listings' ),
                        'off' => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                    'help'    => __( 'When using iThemes, Genesis frameworks or your listings look good, leave this disabled.', 'easy-property-listings' ),
                ),
            ),
        ),

        array(
            'label'  => __( 'Theme Setup: Featured Images', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'theme_setup_featured_images',
            'help'   => __( 'Some WordPress themes automatically display featured images on posts and pages which may cause you to see double on your listings. Use the following settings to adjust the featured image behaviour.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(

                array(
                    'name'    => 'help_lucky_theme_featured_image',
                    'type'    => 'help',
                    'content' => __( 'Theme Featured Image Settings', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_lucky_disable_theme_single_thumb',
                    'label'   => __( 'Single Listing', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                ),

                array(
                    'name'    => 'epl_lucky_disable_archive_thumb',
                    'label'   => __( 'Archive Listing', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                ),

                array(
                    'name'    => 'help_lucky_epl_featured_image',
                    'type'    => 'help',
                    'content' => '<hr/>' . __( 'Easy Property Listings Featured Image Settings', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_lucky_disable_single_thumb',
                    'label'   => __( 'Single Listing', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                ),

                array(
                    'name'    => 'epl_lucky_disable_epl_archive_thumb',
                    'label'   => __( 'Archive Listing', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                ),
            ),
        ),

        array(
            'label'  => __( 'Currency', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'currency',
            // Translators: Currency article link.
            'help'   => sprintf( __( 'Select your default currency. If you can not find the currency you are looking for, you can add additional currencies with a filter, <a href="%s" target="_blank">visit the codex to see how</a>.', 'easy-property-listings' ), esc_url( 'https://codex.easypropertylistings.com.au/article/153-eplgetcurrencies' ) ) . '<hr/>',
            'fields' => array(
                array(
                    'name'  => 'currency',
                    'label' => __( 'Currency Type', 'easy-property-listings' ),
                    'type'  => 'select',
                    'opts'  => $epl_currency_types,
                ),

                array(
                    'name'  => 'currency_position',
                    'label' => __( 'Symbol Position', 'easy-property-listings' ),
                    'type'  => 'select',
                    'opts'  => $epl_currency_positions,
                ),

                array(
                    'name'  => 'currency_thousands_separator',
                    'label' => __( 'Thousands Separator', 'easy-property-listings' ),
                    'type'  => 'text',
                ),

                array(
                    'name'  => 'currency_decimal_separator',
                    'label' => __( 'Decimal Separator', 'easy-property-listings' ),
                    'type'  => 'text',
                ),
            ),
        ),

        array(
            'label'  => __( 'Inspection Date & Time Format', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'inspection_date_time',
            'help'   => __( 'These settings allow you to control how your inspection times display by default.', 'easy-property-listings' ) . '<hr/>',
            'fields' => array(
                array(
                    'name'  => 'inspection_date_format',
                    'label' => __( 'Date Format', 'easy-property-listings' ),
                    'type'  => 'radio',
                    'opts'  => array(

                        'd-M-Y'                         => date( 'd-M-Y', epl_get_local_timestamp() ),
                        'l, dS F'                       => date( 'l, dS F', epl_get_local_timestamp() ),
                        'D d M'                         => date( 'D d M', epl_get_local_timestamp() ),
                        'custom_inspection_date_format' => __( 'Custom', 'easy-property-listings' ),

                    ),
                ),
                array(
                    'name'  => 'custom_inspection_date_format',
                    'label' => __( 'Custom Date Format', 'easy-property-listings' ),
                    'type'  => 'text',
                ),
                array(
                    'name'  => 'inspection_time_format',
                    'label' => __( 'Time Format', 'easy-property-listings' ),
                    'type'  => 'radio',
                    'opts'  => array(

                        'h:i A'                         => date( 'h:i A', epl_get_local_timestamp() ),
                        'h:i a'                         => date( 'h:i a', epl_get_local_timestamp() ),
                        'H:i'                           => date( 'h:i', epl_get_local_timestamp() ) . __( ' ( 24 Hours Format ) ', 'easy-property-listings' ),
                        'custom_inspection_time_format' => __( 'Custom', 'easy-property-listings' ),

                    ),
                ),
                array(
                    'name'  => 'custom_inspection_time_format',
                    'label' => __( 'Custom Time Format', 'easy-property-listings' ),
                    'type'  => 'text',
                ),
            ),
        ),

        array(
            'label'   => __( 'Contact Settings', 'easy-property-listings' ),
            'class'   => 'core',
            'id'      => 'contact',
            'help'    => __( 'You can allow access to the Contacts system for logged in users.', 'easy-property-listings' ) . '<hr/>',
            'fields'  => array(
                array(
                    'name'  => 'min_contact_access',
                    'label' => __( 'Contact Access Level', 'easy-property-listings' ),
                    'type'  => 'radio',
                    'opts'  => $roles,
                ),

            ),
            'default' => 'administrator',
        ),

        array(
            'label'   => __( 'Reports Settings', 'easy-property-listings' ),
            'class'   => 'core',
            'id'      => 'reports',
            'help'    => __( 'You can allow access to the Reports system for logged in users.', 'easy-property-listings' ) . '<hr/>',

            'fields'  => array(
                array(
                    'name'  => 'min_reports_access',
                    'label' => __( 'Reports Access Level', 'easy-property-listings' ),
                    'type'  => 'radio',
                    'opts'  => $roles,
                ),

            ),
            'default' => 'administrator',
        ),

        array(
            'label'  => __( 'Advanced Settings', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'advanced',
            // translators: EPL site link.
            'help'   => sprintf( __( 'Additional settings to control how Easy Property Listings works. For even more advanced filters and hooks, <a href="%s" target="_blank">visit the codex</a>.', 'easy-property-listings' ), esc_url( 'https://codex.easypropertylistings.com.au/' ) ) . '<hr/>',
            'fields' => array(
                array(
                    'name'    => 'epl_use_core_css',
                    'label'   => __( 'Disable Styles', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Yes', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                    'help'    => __( 'Check this to disable all elements.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_css_legacy',
                    'label'   => __( 'Legacy Styles', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Enable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                    'help'    => __( 'Check this to enable legacy css styles.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_css_enhanced',
                    'label'   => __( 'Enhanced Styles', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Enable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                    'help'    => __( 'Check this to enable enhanced structural css styles. This implements inline-block mode for a better grid format on your listings.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_icons_svg_listings',
                    'label'   => __( 'SVG Icons for Listings', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Enable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                    'help'    => __( 'Check this to enable SVG icons on listings.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_icons_svg_author',
                    'label'   => __( 'SVG Icons for Author Social Links', 'easy-property-listings' ),
                    'type'    => 'checkbox_option',
                    'opts'    => array(
                        'on' => __( 'Enable', 'easy-property-listings' ),
                    ),
                    'default' => 'off',
                    'help'    => __( 'Check this to enable SVG icons on author social links.', 'easy-property-listings' ),
                ),

                array(
                    'name'    => 'epl_disable_google_api',
                    'label'   => __( 'Google Maps API', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        ''   => __( 'Enable', 'easy-property-listings' ),
                        'on' => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'default' => '',
                    'help'    => __( 'Set to disabled if Google Maps API has already been loaded in your theme or other plugin.', 'easy-property-listings' ),

                ),

                array(
                    'name'  => 'epl_google_api_key',
                    'label' => __( 'Google Maps API Key', 'easy-property-listings' ),
                    'type'  => 'text',
                    // translators: google map register key link.
                    'help'  => sprintf( __( 'Register for a %s here.', 'easy-property-listings' ), $get_google_maps_api_key_uri ),
                ),

                array(
                    'name'    => 'epl_plugin_mode',
                    'label'   => __( 'Mode', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        'development' => __( 'Development', 'easy-property-listings' ),
                        'production'  => __( 'Production', 'easy-property-listings' ),
                    ),
                    'help'    => __( 'Production mode enqueue minified js & css for faster page loads.', 'easy-property-listings' ),
                    'default' => 'production',
                ),

                array(
                    'name'    => 'uninstall_on_delete',
                    'label'   => __( 'Remove Data on Uninstall?', 'easy-property-listings' ),
                    'type'    => 'radio',
                    'opts'    => array(
                        1 => __( 'Enable', 'easy-property-listings' ),
                        0 => __( 'Disable', 'easy-property-listings' ),
                    ),
                    'help'    => __( 'Select Enable if you would like EPL to completely remove all of its data when the plugin is deleted.', 'easy-property-listings' ),
                    'default' => 0,
                ),
            ),
        ),

    );

    if ( defined( 'EPL_BETA_VERSIONS' ) && true === EPL_BETA_VERSIONS ) {
        $fields[] = array(
            'label'  => __( 'Beta Versions', 'easy-property-listings' ),
            'class'  => 'core',
            'id'     => 'beta-versions',
            'fields' => array(
                array(
                    'name'  => 'enabled_betas',
                    'label' => __( 'Enable Beta Versions', 'easy-property-listings' ),
                    'type'  => 'checkbox',
                    'opts'  => epl_get_beta_enabled_extensions(),
                    'help'  => __( 'Checking any of the checkboxes will opt you in to receive pre-release update notifications. You can opt-out at any time. Pre-release updates do not install automatically, you will still have the opportunity to ignore update notifications.', 'easy-property-listings' ),
                ),

            ),
        );
    }

    $fields = apply_filters( 'epl_display_options_filter', $fields );
    return $fields;
}

/**
 * Sold status filter
 *
 * @since 2.1.11
 */
function epl_sold_label_status_filter_callback() {
    global $epl_settings;
    $epl_settings['label_sold'] = ! isset( $epl_settings['label_sold'] ) ? '' : $epl_settings['label_sold'];
    $sold_label                 = 'Sold' !== $epl_settings['label_sold'] || ! empty( $epl_settings['label_sold'] ) ? $epl_settings['label_sold'] : __( 'Sold', 'easy-property-listings' );
    return $sold_label;
}
add_filter( 'epl_sold_label_status_filter', 'epl_sold_label_status_filter_callback' );

/**
 * Under Offer status filter
 *
 * @since 2.1.11
 */
function epl_under_offer_label_status_filter_callback() {
    global $epl_settings;
    $epl_settings['label_under_offer'] = ! isset( $epl_settings['label_under_offer'] ) ? '' : $epl_settings['label_under_offer'];
    $under_offer_label                 = 'Under Offer' !== $epl_settings['label_under_offer'] || ! empty( $epl_settings['label_under_offer'] ) ? $epl_settings['label_under_offer'] : __( 'Under Offer', 'easy-property-listings' );
    return $under_offer_label;
}
add_filter( 'epl_under_offer_label_status_filter', 'epl_under_offer_label_status_filter_callback' );

/**
 * Leased status filter
 *
 * @since 2.1.11
 */
function epl_leased_label_status_filter_callback() {
    global $epl_settings;
    $epl_settings['label_leased'] = ! isset( $epl_settings['label_leased'] ) ? '' : $epl_settings['label_leased'];
    $leased_label                 = 'Leased' !== $epl_settings['label_leased'] || ! empty( $epl_settings['label_leased'] ) ? $epl_settings['label_leased'] : __( 'Leased', 'easy-property-listings' );
    return $leased_label;
}
add_filter( 'epl_leased_label_status_filter', 'epl_leased_label_status_filter_callback' );

/**
 * Description: Getting all the values associated with a specific custom post meta key, across all posts
 * Author: Chinmoy Paul
 * Author URL: http://pwdtechnology.com
 *
 * @param string $key             Post Meta Key.
 * @param string $type            Post Type. Default is post. You can pass custom post type here.
 * @param string $status          Post Status like Publish, draft, future etc. default is publish.
 * @param string $property_status Listing status.
 *
 * @return void
 *
 * @since 2.1.11
 * @since 3.4.40 Tweak: Search selection results will be sorted in a-z order.
 * @since 3.4.40 Fix: Search address options fixed for the all search tab.
 * @since 3.5.3  Fix: Prepared statement for SQL.
 * @since 3.5.5  Fix: DB error due to double escaping.
 * @since 3.5.6  Fix: Status variable overwritten when status option was passed to the shortcode.
 */
function epl_get_unique_post_meta_values( $key = '', $type = '', $status = 'publish', $property_status = '' ) {

    global $wpdb;

    if ( empty( $key ) ) {
        return;
    }

    if ( empty( $type ) || 'all' === $type ) {
        $type = epl_get_core_post_types();
    }

    $type     = (array) $type;
    $type     = array_map( 'sanitize_text_field', $type );
    $type_str = " ( '" . implode( "','", $type ) . "' ) ";

    $query = "
    SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
    LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
    LEFT JOIN {$wpdb->postmeta} pm2 ON pm.post_id = pm2.post_id
    WHERE pm.meta_key = '%s'
    AND p.post_status = '%s'
    AND p.post_type IN $type_str
    ";

    if ( ! empty( $property_status ) ) {

        $property_status = array_map( 'trim', explode( ',', $property_status ) );

        if ( count( $property_status ) ) {
            $prepared_status_values = array();
            foreach ( $property_status as $status_value ) {
                $prepared_status_values[] = $wpdb->prepare( '%s', $status_value );
            }

            $in_clause = implode( ',', $prepared_status_values );

            $query .= " AND pm2.meta_key = 'property_status' AND pm2.meta_value IN ($in_clause) ";
        }
    }

    $res = $wpdb->get_col( $wpdb->prepare( $query, $key, $status ) ); // phpcs:ignore
    $res = array_filter( $res );

    foreach ( $res as $key => &$elem ) {
        $elem = maybe_unserialize( $elem );
        if ( ! empty( $elem ) && is_array( $elem ) ) {
            foreach ( $elem as $el ) {
                $res[] = $el;
            }
            unset( $res[ $key ] );
        }
    }

    $res     = array_filter( $res );
    $results = array();

    foreach ( $res as $s_res ) {
        $results[ $s_res ] = ucwords( $s_res );
    }

    asort( $results );

    return apply_filters( 'epl_get_unique_post_meta_values', $results, $key, $type );
}

/**
 * Get Sales Count By Date
 *
 * @param int  $day Day number.
 * @param int  $month_num Month number.
 * @param int  $year Year.
 * @param int  $hour Hour.
 * @param int  $status Listing status.
 * @param bool $day_by_day Sales by day.
 * @return int $count Sales
 * @since 3.0
 */
function epl_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null, $status = null, $day_by_day = true ) {
    // phpcs:disable WordPress.Security.NonceVerification
    $post_type = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : 'property';
    $args      = array(
        'post_type'              => $post_type,
        'nopaging'               => true,
        'year'                   => $year,
        'fields'                 => 'ids',
        'post_status'            => array( 'publish' ),
        'update_post_meta_cache' => false,
        'update_post_term_cache' => false,
    );

    if ( in_array( $status, array( 'sold', 'leased' ), true ) ) {

            $month_num = is_null( $month_num ) ? 00 : $month_num;
            $day       = is_null( $day ) ? 00 : $day;
            $year      = is_null( $year ) ? 0000 : $year;
            $range     = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : 'other';

            $args['meta_query'] = array( //phpcs:ignore
                array(
                    'key'     => 'property_status',
                    'value'   => (array) $status,
                    'compare' => 'IN',
                ),
            );

            if ( in_array( $range, array( 'other', 'last_year', 'this_year', 'last_quarter', 'this_quarter' ), true ) ) {

                $sold_key = 'leased' === $status ? 'property_date_available' : 'property_sold_date';

                $sold_date_end   = date( 'Y-m-d', strtotime( $year . '-' . $month_num . '-' . $day ) );
                $sold_date_start = true === $day_by_day ? $sold_date_end : date( 'Y-m-01', strtotime( $year . '-' . $month_num . '-' . $day ) );

                $args['meta_query'][] = array(
                    'key'     => $sold_key,
                    'value'   => array( $sold_date_start, $sold_date_end ),
                    'type'    => 'DATE',
                    'compare' => 'BETWEEN',
                );

            } else {

                $sold_key  = 'leased' === $status ? 'property_date_available' : 'property_sold_date';
                $sold_date = date( 'Y-m-d', strtotime( $year . '-' . $month_num . '-' . $day ) );

                $args['meta_query'][] = array(
                    'key'   => $sold_key,
                    'value' => $sold_date,
                    'type'  => 'DATE',
                );
            }
    } else {

        if ( ! empty( $month_num ) ) {
            $args['monthnum'] = $month_num;
        }

        if ( ! empty( $day ) ) {
            $args['day'] = $day;
        }

        if ( ! empty( $hour ) ) {
            $args['hour'] = $hour;
        }
    }

    $args = apply_filters( 'epl_get_sales_by_date_args', $args );

    $key   = 'epl_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); //phpcs:ignore
    $count = get_transient( $key );
    if ( false === $count ) {
        $sales = new WP_Query( $args );
        $count = (int) $sales->post_count;
        // Cache the results for one hour.
        set_transient( $key, $count, HOUR_IN_SECONDS );
    }

    return $count;
}

/**
 * Month Num To Name
 *
 * Takes a month number and returns the name three letter name of it.
 *
 * @since 3.0
 *
 * @param integer $n Month number.
 * @return string Short month name
 */
function epl_month_num_to_name( $n ) {
    $timestamp = mktime( 0, 0, 0, $n, 1, 2005 );

    return date_i18n( 'M', $timestamp );
}

/**
 * Retrieve contacts from the database
 *
 * @access  public
 *
 * @param array $args Arguments.
 *
 * @return bool|int[]|mixed|WP_Post[]
 * @since   3.0
 */
function epl_get_contacts( $args = array() ) {

    global $wpdb;

    $defaults = array(
        'post_type'      => 'epl_contact',
        'posts_per_page' => 20,
        'offset'         => 0,
        'orderby'        => 'ID',
        'order'          => 'DESC',
    );

    $args = wp_parse_args( $args, $defaults );

    if ( $args['posts_per_page'] < 1 ) {
        $args['number'] = -1;
    }

    $where = ' WHERE 1=1 ';

    // specific contacts.
    if ( ! empty( $args['ID'] ) ) {
        $args['post__in'] = $args['ID'];

    }

    // specific contacts by email.
    if ( ! empty( $args['email'] ) ) {

        $email_query = array(
            'key'   => 'contact_email',
            'value' => $args['email'],
        );

        if ( is_array( $args['email'] ) ) {
            $email_query['comparison'] = 'IN';

        }
        $args['meta_query'][] = $email_query;
    }

    // specific contacts by name.
    if ( ! empty( $args['name'] ) ) {
        $args['post_title'] = $args['name'];
    }

    $cache_key = md5( 'epl_contacts_' . serialize( $args ) ); //phpcs:ignore

    $contacts = wp_cache_get( $cache_key, 'contacts' );

    $args['orderby'] = esc_sql( $args['orderby'] );
    $args['order']   = esc_sql( $args['order'] );

    if ( false === $contacts ) {
        $contacts = get_posts( $args );
        wp_cache_set( $cache_key, $contacts, 'contacts', 3600 );
    }
    return $contacts;
}

/**
 * Search Listing Ajax
 *
 * @access  public
 * @since   3.0
 */
function epl_search_listing() {
    $search_array = array(
        's'           => isset( $_POST['s'] ) ? sanitize_text_field( wp_unslash( $_POST['s'] ) ) : '',
        'showposts'   => 6,
        'post_type'   => epl_get_core_post_types(),
        'post_status' => 'publish',
    );
    $query        = http_build_query( $search_array );
    $listings     = get_posts( $query );
    if ( ! empty( $listings ) ) {
        echo '<ul class="epl-popup-box epl-property-suggestion epl-striped">';
        foreach ( $listings as  $listing ) {
            $status = get_post_meta( $listing->ID, 'property_status', true );
            echo '<li data-id="' . esc_attr( $listing->ID ) . '"><span class="epl-listing-type">' . esc_attr( $listing->post_type ) . '</span>' . esc_attr( $listing->post_title ) . '<span class="epl-listing-status type_' . esc_attr( $status ) . '">' . esc_attr( $status ) . '</span></li>';
        }
        echo '</ul>';
    }
    wp_die();
}
add_action( 'wp_ajax_nopriv_epl_search_listing', 'epl_search_listing' );
add_action( 'wp_ajax_epl_search_listing', 'epl_search_listing' );

/**
 * Get Contact Categories
 *
 * @access  public
 * @since   3.0
 */
function epl_get_contact_categories() {
    return apply_filters(
        'epl_contact_categories',
        array(
            'appraisal'     => __( 'Appraisal', 'easy-property-listings' ),
            'buyer'         => __( 'Buyer', 'easy-property-listings' ),
            'contact'       => __( 'Contact', 'easy-property-listings' ),
            'lead'          => __( 'Lead', 'easy-property-listings' ),
            'landlord'      => __( 'Landlord', 'easy-property-listings' ),
            'new'           => __( 'New', 'easy-property-listings' ),
            'past_customer' => __( 'Past Customer', 'easy-property-listings' ),
            'seller'        => __( 'Seller', 'easy-property-listings' ),
            'tenant'        => __( 'Tenant', 'easy-property-listings' ),
            'widget'        => __( 'Widget Lead', 'easy-property-listings' ),
            'contract'      => __( 'Under Contract', 'easy-property-listings' ),
        )
    );
}

/**
 * Get Contact Labels
 *
 * @param string $category Category label.
 *
 * @access  public
 * @return string
 * @since   3.0
 */
function get_category_label( $category ) {
    foreach ( epl_get_contact_categories() as $key    => $cat ) {
        if ( $key === $category ) {
            return $cat;
        }
    }
    return $category;
}

/**
 * Helper function starts with
 *
 * @param string $haystack String.
 * @param string $needle String.
 *
 * @return bool
 * @since 3.3
 */
function epl_starts_with( $haystack, $needle ) {
    // search backwards starting from haystack length characters from the end.
    return empty( $needle ) || strrpos( $haystack, $needle, -strlen( $haystack ) ) !== false;
}

/**
 * Helper function ends with
 *
 * @param string $haystack String.
 * @param string $needle String.
 *
 * @return bool
 * @since 3.3
 */
function epl_ends_with( $haystack, $needle ) {
    // search forward starting from end minus needle length characters.
    $temp = strlen( $haystack ) - strlen( $needle );
    return empty( $needle ) || ( $temp >= 0 && strpos( $haystack, $needle, $temp ) !== false );
}

/**
 * Parse EPL shortcodes for meta queries
 *
 * @param  array $atts Attributes.
 * @return array
 *
 * @since 3.5 Fix: PHP 8.2. Automatic conversion of false to array is deprecated fix.
 * @since 3.5.4 Fix: Min & Max not working.
 */
function epl_parse_atts( $atts ) {

    $query = array();

    if ( empty( $atts ) ) {
        return $atts;
    }

    $compare_operators = array(
        '_min'         => '>=',
        '_max'         => '<=',
        '_not_equal'   => '!=',
        '_like'        => 'LIKE',
        '_not_like'    => 'NOT LIKE',
        '_exists'      => 'EXISTS',
        '_not_exists'  => 'NOT EXISTS',
        '_in'          => 'IN',
        '_not_in'      => 'NOT IN',
        '_between'     => 'BETWEEN',
        '_not_between' => 'NOT BETWEEN',
    );

    foreach ( $atts as $key   => &$value ) {

        $this_query = array(
            'compare' => '=',
            'value'   => $value,
        );

        // check for meta.
        if ( epl_starts_with( $key, '_' ) ) {

            $key = preg_replace( '/^_/', '', $key );

            foreach ( $compare_operators as $look_for => $compare_operator ) {

                if ( epl_ends_with( $key, $look_for ) ) {

                    $key                   = preg_replace( '/' . $look_for . '$/', '', $key );
                    $this_query['compare'] = $compare_operator;

                    if ( in_array( $look_for, array( '_in', '_not_in', '_between', '_not_between' ), true ) ) {

                        $this_query['value'] =
                        array_map( 'trim', explode( ',', $this_query['value'] ) );

                        if ( in_array( $look_for, array( '_between', '_not_between' ), true ) ) {

                            if ( is_numeric( $this_query['value'][0] ) ) {
                                $this_query['type'] = 'numeric';
                            }
                        }
                    }

                    if ( in_array( $look_for, array( '_min', '_max' ), true ) ) {
                        if ( is_numeric( $this_query['value'] ) ) {
                            $this_query['type'] = 'numeric';
                        }
                    }

                    if ( in_array( $look_for, array( '_exists', '_not_exists' ), true ) ) {
                        unset( $this_query['value'] );
                    }
                }
            }
            $this_query['key']                       = $key;
            $query['meta_query'][ $key . '_clause' ] = $this_query;
        }
    }
    return isset( $query['meta_query'] ) ? $query['meta_query'] : array();
}

/**
 * Return an array of all extensions with beta support
 *
 * Extensions should be added as 'extension-slug' => 'Extension Name'
 *
 * @return array $extensions The array of extensions
 */
function epl_get_beta_enabled_extensions() {
    return apply_filters( 'epl_beta_enabled_extensions', array() );
}

/**
 * Returns List of countries
 *
 * @since 3.2
 */
function epl_get_countries_list() {

    $countries = array( 'Australia', 'Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegowina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, the Democratic Republic of the', 'Cook Islands', 'Costa Rica', "Cote d'Ivoire", 'Croatia (Hrvatska)', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'France Metropolitan', 'French Guiana', 'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard and Mc Donald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran (Islamic Republic of)', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', "Korea, Democratic People's Republic of", 'Korea, Republic of', 'Kuwait', 'Kyrgyzstan', "Lao, People's Democratic Republic", 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia, The Former Yugoslav Republic of', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia, Federated States of', 'Moldova, Republic of', 'Monaco', 'Mongolia', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia (Slovak Republic)', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia and the South Sandwich Islands', 'Spain', 'Sri Lanka', 'St. Helena', 'St. Pierre and Miquelon', 'Sudan', 'Suriname', 'Svalbard and Jan Mayen Islands', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan, Province of China', 'Tajikistan', 'Tanzania, United Republic of', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'United States Minor Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Virgin Islands (British)', 'Virgin Islands (U.S.)', 'Wallis and Futuna Islands', 'Western Sahara', 'Yemen', 'Yugoslavia', 'Zambia', 'Zimbabwe' );

    return apply_filters( 'epl_get_countries_list', array_combine( $countries, $countries ) );
}

/**
 * Returns array containing Property Status
 *
 * @since 3.2
 * @since 3.4.45 Added deleted status. Re-orderd status options.
 */
function epl_get_property_status_opts() {

    return apply_filters(
        'epl_opts_property_status_filter',
        array(
            'current'   => __( 'Current', 'easy-property-listings' ),
            'sold'      => array(
                'label'   => apply_filters( 'epl_sold_label_status_filter', __( 'Sold', 'easy-property-listings' ) ),
                'exclude' => array( 'rental' ),
            ),
            'leased'    => array(
                'label'   => apply_filters( 'epl_leased_label_status_filter', __( 'Leased', 'easy-property-listings' ) ),
                'include' => array( 'rental', 'commercial', 'commercial_land', 'business' ),
            ),
            'withdrawn' => __( 'Withdrawn', 'easy-property-listings' ),
            'offmarket' => __( 'Off Market', 'easy-property-listings' ),
            'deleted'   => __( 'Deleted', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns the status label for given status value.
 *
 * @since 3.5.0
 *
 * @param bool $status Status status value.
 * @return string $label Status label.
 */
function epl_get_the_status_label( $status = '' ) {

    $status_opts = epl_get_property_status_opts();

    if ( 0 === strlen( $status ) ) {
        return null;
    }

    $status_data = $status_opts[ $status ];

    $label = is_array( $status_data ) && isset( $status_data['label'] ) ? $status_data['label'] : $status_data;

    return $label;
}

/**
 * Returns the array of status available in the site as key, label pair.
 *
 * @since 3.5.0
 *
 * @param string $key Post Meta Key.
 * @param string $type Post Type. Default is post. You can pass custom post type here.
 *
 * @return string|array $label Status label.
 */
function epl_get_available_status_list( $key, $type ) {

    $status_list = epl_get_unique_post_meta_values( $key, $type );
    $available   = array();

    if ( empty( $status_list ) ) {
        return array();
    }

    foreach ( $status_list as $key => $key_label ) {
        $available[ $key ] = epl_get_the_status_label( $key );
    }

    return apply_filters( 'epl_get_available_status_list', $available, $key, $type );
}

/**
 * Returns array containing Property authority
 *
 * @since 3.2
 */
function epl_get_property_authority_opts() {

    return apply_filters(
        'epl_property_authority_filter',
        array(
            'exclusive'     => __( 'Exclusive', 'easy-property-listings' ),
            'auction'       => __( 'Auction', 'easy-property-listings' ),
            'multilist'     => __( 'Multilist', 'easy-property-listings' ),
            'conjunctional' => __( 'Conjunctional', 'easy-property-listings' ),
            'open'          => __( 'Open', 'easy-property-listings' ),
            'sale'          => __( 'Sale', 'easy-property-listings' ),
            'setsale'       => __( 'Set Sale', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns array containing Property exclusivity
 *
 * @since 3.2
 */
function epl_get_property_exclusivity_opts() {

    return apply_filters(
        'epl_opts_property_exclusivity_filter',
        array(
            'exclusive' => __( 'Exclusive', 'easy-property-listings' ),
            'open'      => __( 'Open', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns array containing Commercial Authority
 *
 * @since 3.2
 * @since 3.4.26 Re-ordered options.
 */
function epl_get_property_com_authority_opts() {

    return apply_filters(
        'epl_opts_property_com_authority_filter',
        array(
            'Forsale' => __( 'For Sale', 'easy-property-listings' ),
            'auction' => __( 'Auction', 'easy-property-listings' ),
            'eoi'     => __( 'EOI', 'easy-property-listings' ),
            'offers'  => __( 'Offers', 'easy-property-listings' ),
            'Sale'    => __( 'Sale', 'easy-property-listings' ),
            'tender'  => __( 'Tender', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns array containing area unit options
 *
 * @since 3.2
 */
function epl_get_property_area_unit_opts() {

    return apply_filters(
        'epl_opts_area_unit_filter',
        array(
            'square'      => __( 'Square', 'easy-property-listings' ),
            'squareMeter' => __( 'Square Meter', 'easy-property-listings' ),
            'acre'        => __( 'Acre', 'easy-property-listings' ),
            'hectare'     => __( 'Hectare', 'easy-property-listings' ),
            'sqft'        => __( 'Square Feet', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns array containing Rental period
 *
 * @since 3.2
 */
function epl_get_property_rent_period_opts() {

    return apply_filters(
        'epl_opts_rent_period_filter',
        array(
            'day'     => __( 'Day', 'easy-property-listings' ),
            'daily'   => __( 'Daily', 'easy-property-listings' ),
            'week'    => __( 'Week', 'easy-property-listings' ),
            'weekly'  => __( 'Weekly', 'easy-property-listings' ),
            'month'   => __( 'Month', 'easy-property-listings' ),
            'monthly' => __( 'Monthly', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns array containing Commercial Leasing Types
 *
 * @since 3.2
 */
function epl_get_property_com_listing_type_opts() {

    return apply_filters(
        'epl_opts_property_com_listing_type_filter',
        array(
            'sale'  => __( 'Sale', 'easy-property-listings' ),
            'lease' => __( 'Lease', 'easy-property-listings' ),
            'both'  => __( 'Both', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns array containing Commercial Tenancy
 *
 * @since 3.2
 */
function epl_get_property_com_tenancy_opts() {

    return apply_filters(
        'epl_opts_property_com_tenancy_filter',
        array(
            'unknown'  => __( 'Unknown', 'easy-property-listings' ),
            'vacant'   => __( 'Vacant', 'easy-property-listings' ),
            'tenanted' => __( 'Tenanted', 'easy-property-listings' ),
        )
    );
}

/**
 * Returns array containing Commercial Land Extent
 *
 * @since 3.2
 */
function epl_get_property_com_property_extent_opts() {

    return apply_filters(
        'epl_opts_property_com_property_extent_filter',
        array(
            'whole' => __( 'Whole', 'easy-property-listings' ),
            'part'  => __( 'Part', 'easy-property-listings' ),
        )
    );
}

/**
 * Get author id from name
 *
 * @param string $author Author name.
 *
 * @return int
 * @since 3.1.1
 */
function epl_get_author_id_from_name( $author ) {
    if ( is_numeric( $author ) ) {
        return absint( $author );
    } else {
        $user = get_user_by( 'login', $author );
        return $user->ID;
    }
}

/**
 * WP All Import Pro filter that processes property_price_global after updating or saving a post
 *
 * @param string $id Post ID.
 * @since 3.3
 */
function epl_pmxi_import_post_saved( $id ) {

    $post = get_post( $id );

    if ( is_null( $post ) ) {
        return;
    }

    if ( is_epl_post( $post->post_type ) ) {

        if ( 'rental' === $post->post_type ) {
            $price = get_post_meta( $id, 'property_rent', true );
            update_post_meta( $id, 'property_price_global', $price );
        } elseif ( 'commercial' === $post->post_type ) {
            $price = get_post_meta( $id, 'property_price', true );
            if ( empty( $price ) ) {
                $price = get_post_meta( $id, 'property_com_rent', true );
            }
            update_post_meta( $id, 'property_price_global', $price );
        } else {
            $price = get_post_meta( $id, 'property_price', true );
            update_post_meta( $id, 'property_price_global', $price );
        }
    }
}
add_action( 'pmxi_saved_post', 'epl_pmxi_import_post_saved', 10, 1 );

/**
 * Load functions from child theme folder if present
 *
 * @since 3.3
 */
function epl_single_and_archive_functions() {

    if ( is_epl_post_single() && file_exists( get_stylesheet_directory() . '/easypropertylistings/functions-single.php' ) ) {
        include_once get_stylesheet_directory() . '/easypropertylistings/functions-single.php';
    }

    if ( is_epl_post_archive() && file_exists( get_stylesheet_directory() . '/easypropertylistings/functions-archive.php' ) ) {
        include_once get_stylesheet_directory() . '/easypropertylistings/functions-archive.php';
    }
}
add_action( 'wp', 'epl_single_and_archive_functions', 99 );

/**
 * Recursive array map for multi dimensional array
 *
 * @param string $callback Callback.
 * @param array  $array Array.
 *
 * @return array
 * @since 3.3.5
 */
function epl_array_map_recursive( $callback, $array ) {
    $func = function ( $item ) use ( &$func, &$callback ) { //phpcs:ignore
        return is_array( $item ) ? array_map( $func, $item ) : call_user_func( $callback, $item );
    };
    return array_map( $func, $array );
}

/**
 * Sanitize function to allow certain safe html tags.
 *
 * @param array $content sanitized html content.
 *
 * @return string
 * @since 3.4.48
 */
function epl_sanitize_html_tags( $content ) {

    $allowed_tags = wp_kses_allowed_html( 'post' );

    return wp_kses( $content, $allowed_tags );
}

/**
 * Function to generate a unique tab counter for search forms.
 *
 * @return int
 * @since 3.5
 */
function epl_generate_unique_tab_counter() {

    global $epl_search_shortcode_counter;

    if ( empty( $epl_search_shortcode_counter ) ) {
        $epl_search_shortcode_counter = 0;
    }

    $epl_search_shortcode_counter++;
    return $epl_search_shortcode_counter;
}

/**
 * Function to generate a unique instance counter for search forms.
 *
 * @return int
 * @since 3.5
 */
function epl_generate_search_instance_counter() {

    global $epl_search_instance_counter;

    if ( empty( $epl_search_instance_counter ) ) {
        $epl_search_instance_counter = 0;
    }

    $epl_search_instance_counter++;
    return $epl_search_instance_counter;
}

/**
 * Get the meta value as label helper function.
 *
 * @param string $meta_key The meta key to get the label for.
 *
 * @return mixed
 * @since 3.5
 */
function epl_get_property_meta_label( $meta_key ) {

    $value  = get_property_meta( $meta_key );
    $return = $value;

    if ( function_exists( 'epl_get_' . $meta_key . '_opts' ) ) {

        $labels = call_user_func( 'epl_get_' . $meta_key . '_opts' );

        if ( is_string( $value ) && isset( $labels[ $value ] ) ) {
            $return = $labels[ $value ];
        }
    }

    return $return;
}

/**
 * Returns the localised timestamp
 *
 * @since 3.5.3
 */
function epl_get_local_timestamp() {
    $local_time = current_datetime();
    return $local_time->getTimestamp() + $local_time->getOffset();
}
Easy Property Listings 3.5.14 Code Reference API documentation generated by ApiGen