BP_Members_Admin
Load Members admin area.
Description
Source
File: bp-members/classes/class-bp-members-admin.php
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 | class BP_Members_Admin { /** Directory *************************************************************/ /** * Path to the BP Members Admin directory. * * @var string $admin_dir */ public $admin_dir = '' ; /** URLs ******************************************************************/ /** * URL to the BP Members Admin directory. * * @var string $admin_url */ public $admin_url = '' ; /** * URL to the BP Members Admin CSS directory. * * @var string $css_url */ public $css_url = '' ; /** * URL to the BP Members Admin JS directory. * * @var string */ public $js_url = '' ; /** Other *****************************************************************/ /** * Screen id for edit user's profile page. * * @var string */ public $user_page = '' ; /** * Setup BP Members Admin. * * @since BuddyPress 2.0.0 * * @return BP_Members_Admin */ public static function register_members_admin() { if ( ! is_admin() ) { return ; } $bp = buddypress(); if ( empty ( $bp ->members->admin ) ) { $bp ->members->admin = new self; } return $bp ->members->admin; } /** * Constructor method. * * @since BuddyPress 2.0.0 */ public function __construct() { $this ->setup_globals(); $this ->setup_actions(); } /** * Set admin-related globals. * * @since BuddyPress 2.0.0 */ private function setup_globals() { $bp = buddypress(); // Paths and URLs $this ->admin_dir = trailingslashit( $bp ->plugin_dir . 'bp-members/admin' ); // Admin path. $this ->admin_url = trailingslashit( $bp ->plugin_url . 'bp-members/admin' ); // Admin URL. $this ->css_url = trailingslashit( $this ->admin_url . 'css' ); // Admin CSS URL. $this ->js_url = trailingslashit( $this ->admin_url . 'js' ); // Admin CSS URL. // Capability depends on config. $this ->capability = bp_core_do_network_admin() ? 'manage_network_users' : 'edit_users' ; // The Edit Profile Screen id. $this ->user_page = '' ; // The Show Profile Screen id. $this ->user_profile = is_network_admin() ? 'users' : 'profile' ; // The current user id. $this ->current_user_id = get_current_user_id(); // The user id being edited. $this ->user_id = 0; // Is a member editing their own profile. $this ->is_self_profile = false; // The screen ids to load specific css for. $this ->screen_id = array (); // The stats metabox default position. $this ->stats_metabox = new StdClass(); // BuddyPress edit user's profile args. $this ->edit_profile_args = array ( 'page' => 'bp-profile-edit' ); $this ->edit_profile_url = '' ; $this ->edit_url = '' ; // Data specific to signups. $this ->users_page = '' ; $this ->signups_page = '' ; $this ->users_url = bp_get_admin_url( 'users.php' ); $this ->users_screen = bp_core_do_network_admin() ? 'users-network' : 'users' ; // Specific config: BuddyPress is not network activated. $this ->subsite_activated = (bool) is_multisite() && ! bp_is_network_activated(); // When BuddyPress is not network activated, only Super Admin can moderate signups. if ( ! empty ( $this ->subsite_activated ) ) { $this ->capability = 'manage_network_users' ; } } /** * Set admin-related actions and filters. * * @since BuddyPress 2.0.0 */ private function setup_actions() { /** Extended Profile ************************************************* */ // Enqueue all admin JS and CSS. add_action( 'bp_admin_enqueue_scripts' , array ( $this , 'enqueue_scripts' ) ); // Add some page specific output to the <head>. add_action( 'bp_admin_head' , array ( $this , 'admin_head' ), 999 ); // Add menu item to all users menu. add_action( 'admin_menu' , array ( $this , 'admin_menus' ), 5 ); add_action( 'network_admin_menu' , array ( $this , 'admin_menus' ), 5 ); add_action( 'user_admin_menu' , array ( $this , 'user_profile_menu' ), 5 ); // Create the Profile Navigation (Profile/Extended Profile). add_action( 'edit_user_profile' , array ( $this , 'profile_nav' ), 99, 1 ); add_action( 'show_user_profile' , array ( $this , 'profile_nav' ), 99, 1 ); // Editing users of a specific site. add_action( "admin_head-site-users.php" , array ( $this , 'profile_admin_head' ) ); // Add a row action to users listing. if ( bp_core_do_network_admin() ) { add_filter( 'ms_user_row_actions' , array ( $this , 'row_actions' ), 10, 2 ); add_action( 'admin_init' , array ( $this , 'add_edit_profile_url_filter' ) ); add_action( 'wp_after_admin_bar_render' , array ( $this , 'remove_edit_profile_url_filter' ) ); } // Add user row actions for single site. add_filter( 'user_row_actions' , array ( $this , 'row_actions' ), 10, 2 ); // Process changes to profile type. add_action( 'bp_members_admin_load' , array ( $this , 'process_member_type_update' ) ); /** Signups ********************************************************** */ if ( is_admin() ) { // Filter non multisite user query to remove sign-up users. if ( ! is_multisite() ) { add_action( 'pre_user_query' , array ( $this , 'remove_signups_from_user_query' ), 10, 1 ); } // Reorganise the views navigation in users.php and signups page. if ( current_user_can( $this ->capability ) ) { $user_screen = $this ->users_screen; /** * Users screen on multiblog is users, but signups * need to be managed in the network for this case */ if ( bp_is_network_activated() && bp_is_multiblog_mode() && false === strpos ( $user_screen , '-network' ) ) { $user_screen .= '-network' ; } add_filter( "views_{$user_screen}" , array ( $this , 'signup_filter_view' ), 10, 1 ); add_filter( 'set-screen-option' , array ( $this , 'signup_screen_options' ), 10, 3 ); } // Registration is turned on. add_action( 'update_site_option_registration' , array ( $this , 'multisite_registration_on' ), 10, 2 ); add_action( 'update_option_users_can_register' , array ( $this , 'single_site_registration_on' ), 10, 2 ); add_action( 'update_option_bp-enable-site-registration' , array ( $this , 'bp_registration_update_option' ), 10, 2 ); add_action( 'admin_init' , array ( $this , 'bp_update_registration_update_option' ), 10 ); } /** Users List - Members Types *************************************** */ if ( is_admin() && bp_get_member_types() ) { // Add "Change type" <select> to WP admin users list table and process bulk members type changes. add_action( 'restrict_manage_users' , array ( $this , 'users_table_output_type_change_select' ) ); add_action( 'load-users.php' , array ( $this , 'users_table_process_bulk_type_change' ) ); // Add the profile type column to the WP admin users list table. add_filter( 'manage_users_columns' , array ( $this , 'users_table_add_type_column' ) ); add_filter( 'manage_users_custom_column' , array ( $this , 'users_table_populate_type_cell' ), 10, 3 ); // Filter WP admin users list table to include users of the specified type. add_filter( 'pre_get_users' , array ( $this , 'users_table_filter_by_type' ) ); } } /** * Update site registrations options based on the wordpress settings on plugin activate. * * @since BuddyBoss 1.0.0 * * @param string $old_value * @param string $value */ function bp_update_registration_update_option() { if ( ! is_multisite() ) { $check_current_wp = (bool) bp_get_option( 'users_can_register' , 0); $check_current_bp = (bool) bp_enable_site_registration(); if ( true === $check_current_wp && false === $check_current_bp ) { bp_update_option( 'bp-enable-site-registration' , 1 ); } elseif ( false === $check_current_wp && true === $check_current_bp ) { update_option( 'users_can_register' , 1 ); bp_update_option( 'bp-enable-site-registration' , 1 ); } } else { $check_current_wp = get_site_option( 'registration' , 'none' ); $check_current_bp = (bool) bp_enable_site_registration(); if ( ( 'all' === $check_current_wp || 'user' === $check_current_wp ) && false === $check_current_bp ) { bp_update_option( 'bp-enable-site-registration' , 1 ); } elseif ( ( 'all' !== $check_current_wp || 'user' !== $check_current_wp ) && true === $check_current_bp ) { update_site_option( 'registration' , 'all' ); bp_update_option( 'bp-enable-site-registration' , 1 ); } } } /** * Update site registrations options based on the BuddyBoss general registration settings. * * @since BuddyBoss 1.0.0 * * @param string $old_value * @param string $value */ public function bp_registration_update_option( $old_value , $value ) { if ( 1 === $value ) { if ( ! is_multisite() ) { update_option( 'users_can_register' , 1 ); } else { update_site_option( 'registration' , 'all' ); } } else { if ( '' !== $value ) { if ( ! is_multisite() ) { update_option( 'users_can_register' , 0 ); } else { update_site_option( 'registration' , 'none' ); } } } } /** * Create registration pages when multisite user registration is turned on. * * @since BuddyPress 2.7.0 * * @param string $option_name Current option name; value is always 'registration'. * @param string $value */ public function multisite_registration_on( $option_name , $value ) { if ( 'user' === $value || 'all' === $value ) { bp_core_add_page_mappings( array ( 'register' => 1, 'activate' => 1 ) ); // Update site registrations options based on the BuddyBoss general registration settings. bp_update_option( 'bp-enable-site-registration' , 1 ); } else { // Update site registrations options based on the BuddyBoss general registration settings. bp_update_option( 'bp-enable-site-registration' , 0 ); } } /** * Create registration pages when single site registration is turned on. * * @since BuddyPress 2.7.0 * * @param string $old_value * @param string $value */ public function single_site_registration_on( $old_value , $value ) { // Single site. if ( ! is_multisite() && ! empty ( $value ) ) { bp_core_add_page_mappings( array ( 'register' => 1, 'activate' => 1 ) ); // Update site registrations options based on the BuddyBoss general registration settings. bp_update_option( 'bp-enable-site-registration' , 1 ); } else { // Update site registrations options based on the BuddyBoss general registration settings. bp_update_option( 'bp-enable-site-registration' , 0 ); } } /** * Get the user ID. * * Look for $_GET['user_id']. If anything else, force the user ID to the * current user's ID so they aren't left without a user to edit. * * @since BuddyPress 2.1.0 * * @return int */ private function get_user_id() { if ( ! empty ( $this ->user_id ) ) { return $this ->user_id; } $this ->user_id = (int) get_current_user_id(); // We'll need a user ID when not on self profile. if ( ! empty ( $_GET [ 'user_id' ] ) ) { $this ->user_id = (int) $_GET [ 'user_id' ]; } return $this ->user_id; } /** * Can the current user edit the one displayed. * * Self profile editing / or bp_moderate check. * This might be replaced by more granular capabilities * in the future. * * @since BuddyPress 2.1.0 * * @param int $user_id ID of the user being checked for edit ability. * * @return bool */ private function member_can_edit( $user_id = 0 ) { $retval = false; // Bail if no user ID was passed. if ( empty ( $user_id ) ) { return $retval ; } // Member can edit if they are viewing their own profile. if ( $this ->current_user_id === $user_id ) { $retval = true; // Trust the 'bp_moderate' capability. } else { $retval = bp_current_user_can( 'bp_moderate' ); } return $retval ; } /** * Get admin notice when saving a user or member profile. * * @since BuddyPress 2.1.0 * * @return array */ private function get_user_notice() { // Setup empty notice for return value. $notice = array (); // Updates. if ( ! empty ( $_REQUEST [ 'updated' ] ) ) { switch ( $_REQUEST [ 'updated' ] ) { case 'avatar' : $notice = array ( 'class' => 'updated' , 'message' => __( 'Profile photo was deleted.' , 'buddyboss' ) ); break ; case 'ham' : $notice = array ( 'class' => 'updated' , 'message' => __( 'User removed as spammer.' , 'buddyboss' ) ); break ; case 'spam' : $notice = array ( 'class' => 'updated' , 'message' => __( 'User marked as spammer. Spam users are visible only to site admins.' , 'buddyboss' ) ); break ; case 1 : $notice = array ( 'class' => 'updated' , 'message' => __( 'Profile updated.' , 'buddyboss' ) ); break ; } } // Errors. if ( ! empty ( $_REQUEST [ 'error' ] ) ) { switch ( $_REQUEST [ 'error' ] ) { case 'avatar' : $notice = array ( 'class' => 'error' , 'message' => __( 'There was a problem deleting that profile photo. Please try again.' , 'buddyboss' ) ); break ; case 'ham' : $notice = array ( 'class' => 'error' , 'message' => __( 'User could not be removed as spammer.' , 'buddyboss' ) ); break ; case 'spam' : $notice = array ( 'class' => 'error' , 'message' => __( 'User could not be marked as spammer.' , 'buddyboss' ) ); break ; case 1 : $notice = array ( 'class' => 'error' , 'message' => __( 'An error occurred while trying to update the profile.' , 'buddyboss' ) ); break ; case 2: $notice = array ( 'class' => 'error' , 'message' => __( 'Your changes have not been saved. Please fill in all required fields, and save your changes again.' , 'buddyboss' ) ); break ; case 3: $notice = array ( 'class' => 'error' , 'message' => __( 'There was a problem updating some of your profile information. Please try again.' , 'buddyboss' ) ); break ; case 4: $notice = array ( 'class' => 'error' , 'message' => stripcslashes ( $_REQUEST [ 'message' ] ) ); break ; } } return $notice ; } /** * Create the /user/ admin Profile submenus for all members. * * @since BuddyPress 2.1.0 * */ public function user_profile_menu() { // Setup the hooks array. $hooks = array (); // Add the faux "Edit Profile" submenu page. $hooks [ 'user' ] = $this ->user_page = add_submenu_page( 'profile.php' , __( 'Edit Profile' , 'buddyboss' ), __( 'Edit Profile' , 'buddyboss' ), 'exist' , 'bp-profile-edit' , array ( $this , 'user_admin' ) ); // Setup the screen ID's. $this ->screen_id = array ( $this ->user_page . '-user' , $this ->user_profile . '-user' ); // Loop through new hooks and add method actions. foreach ( $hooks as $key => $hook ) { add_action( "load-{$hook}" , array ( $this , $key . '_admin_load' ) ); } // Add the profile_admin_head method to proper admin_head actions. add_action( "admin_head-{$this->user_page}" , array ( $this , 'profile_admin_head' ) ); add_action( "admin_head-profile.php" , array ( $this , 'profile_admin_head' ) ); } /** * Create the All Users / Profile > Edit Profile and All Users Signups submenus. * * @since BuddyPress 2.0.0 * */ public function admin_menus() { // Setup the hooks array. $hooks = array (); // Manage user's profile. $hooks [ 'user' ] = $this ->user_page = add_submenu_page( $this ->user_profile . '.php' , __( 'Edit Profile' , 'buddyboss' ), __( 'Edit Profile' , 'buddyboss' ), 'read' , 'bp-profile-edit' , array ( $this , 'user_admin' ) ); // Only show sign-ups where they belong. if ( ( ! bp_is_network_activated() && ! is_network_admin() ) || ( is_network_admin() && bp_is_network_activated() ) ) { // Manage signups. $hooks [ 'signups' ] = $this ->signups_page = add_users_page( __( 'Pending Signups' , 'buddyboss' ), __( 'Pending Signups' , 'buddyboss' ), $this ->capability, 'bp-signups' , array ( $this , 'signups_admin' ) ); } $edit_page = 'user-edit' ; $profile_page = 'profile' ; $this ->users_page = 'users' ; // Self profile check is needed for this pages. $page_head = array ( $edit_page . '.php' , $profile_page . '.php' , $this ->user_page, $this ->users_page . '.php' , ); // Append '-network' to each array item if in network admin. if ( is_network_admin() ) { $edit_page .= '-network' ; $profile_page .= '-network' ; $this ->user_page .= '-network' ; $this ->users_page .= '-network' ; $this ->signups_page .= '-network' ; } // Setup the screen ID's. $this ->screen_id = array ( $edit_page , $this ->user_page, $profile_page ); // Loop through new hooks and add method actions. foreach ( $hooks as $key => $hook ) { add_action( "load-{$hook}" , array ( $this , $key . '_admin_load' ) ); } // Add the profile_admin_head method to proper admin_head actions. foreach ( $page_head as $head ) { add_action( "admin_head-{$head}" , array ( $this , 'profile_admin_head' ) ); } } /** * Highlight the Users menu if on Edit Profile and check if on the user's admin profile. * * @since BuddyPress 2.1.0 */ public function profile_admin_head() { global $submenu_file , $parent_file ; // Is the user editing their own profile? if ( is_user_admin() || ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) ) { $this ->is_self_profile = true; // Is the user attempting to edit their own profile. } elseif ( isset( $_GET [ 'user_id' ] ) || ( isset( $_GET [ 'page' ] ) && ( 'bp-profile-edit' === $_GET [ 'page' ] ) ) ) { $this ->is_self_profile = (bool) ( $this ->get_user_id() === $this ->current_user_id ); } // Force the parent file to users.php to open the correct top level menu // but only if not editing a site via the network site editing page. if ( 'sites.php' !== $parent_file ) { $parent_file = 'users.php' ; $submenu_file = 'users.php' ; } // Editing your own profile, so recheck some vars. if ( true === $this ->is_self_profile ) { // Use profile.php as the edit page. $edit_page = 'profile.php' ; // Set profile.php as the parent & sub files to correct the menu nav. if ( is_blog_admin() || is_user_admin() ) { $parent_file = 'profile.php' ; $submenu_file = 'profile.php' ; } // Not editing yourself, so use user-edit.php. } else { $edit_page = 'user-edit.php' ; } if ( is_user_admin() ) { $this ->edit_profile_url = add_query_arg( $this ->edit_profile_args, user_admin_url( 'profile.php' ) ); $this ->edit_url = user_admin_url( 'profile.php' ); } elseif ( is_blog_admin() ) { $this ->edit_profile_url = add_query_arg( $this ->edit_profile_args, admin_url( 'users.php' ) ); $this ->edit_url = admin_url( $edit_page ); } elseif ( is_network_admin() ) { $this ->edit_profile_url = add_query_arg( $this ->edit_profile_args, network_admin_url( 'users.php' ) ); $this ->edit_url = network_admin_url( $edit_page ); } } /** * Remove the Edit Profile page. * * We add these pages in order to integrate with WP's Users panel, but * we want them to show up as a row action of the WP panel, not as separate * subnav items under the Users menu. * * @since BuddyPress 2.0.0 */ public function admin_head() { remove_submenu_page( 'users.php' , 'bp-profile-edit' ); remove_submenu_page( 'profile.php' , 'bp-profile-edit' ); } /** Community Profile *****************************************************/ /** * Add some specific styling to the Edit User and Edit User's Profile page. * * @since BuddyPress 2.0.0 */ public function enqueue_scripts() { if ( ! in_array( get_current_screen()->id, $this ->screen_id ) ) { return ; } $min = bp_core_get_minified_asset_suffix(); $css = $this ->css_url . "admin{$min}.css" ; /** * Filters the CSS URL to enqueue in the Members admin area. * * @since BuddyPress 2.0.0 * * @param string $css URL to the CSS admin file to load. */ $css = apply_filters( 'bp_members_admin_css' , $css ); wp_enqueue_style( 'bp-members-css' , $css , array (), bp_get_version() ); wp_style_add_data( 'bp-members-css' , 'rtl' , true ); if ( $min ) { wp_style_add_data( 'bp-members-css' , 'suffix' , $min ); } // Only load JavaScript for BuddyPress profile. if ( get_current_screen()->id == $this ->user_page ) { $js = $this ->js_url . "admin{$min}.js" ; /** * Filters the JS URL to enqueue in the Members admin area. * * @since BuddyPress 2.0.0 * * @param string $js URL to the JavaScript admin file to load. */ $js = apply_filters( 'bp_members_admin_js' , $js ); wp_enqueue_script( 'bp-members-js' , $js , array ( 'jquery' ), bp_get_version(), true ); } /** * Fires after all of the members JavaScript and CSS are enqueued. * * @since BuddyPress 2.0.0 * * @param string $id ID of the current screen. * @param array $screen_id Array of allowed screens to add scripts and styles to. */ do_action( 'bp_members_admin_enqueue_scripts' , get_current_screen()->id, $this ->screen_id ); } /** * Create the Profile navigation in Edit User & Edit Profile pages. * * @since BuddyPress 2.0.0 * * @param object|null $user User to create profile navigation for. * @param string $active Which profile to highlight. * @return string|null */ public function profile_nav( $user = null, $active = 'WordPress' ) { // Bail if no user ID exists here. if ( empty ( $user ->ID ) ) { return ; } // Add the user ID to query arguments when not editing yourself. if ( false === $this ->is_self_profile ) { $query_args = array ( 'user_id' => $user ->ID ); } else { $query_args = array (); } // Conditionally add a referer if it exists in the existing request. if ( ! empty ( $_REQUEST [ 'wp_http_referer' ] ) ) { $wp_http_referer = wp_unslash( $_REQUEST [ 'wp_http_referer' ] ); $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) ); $query_args [ 'wp_http_referer' ] = urlencode( $wp_http_referer ); } // Setup the two distinct "edit" URL's. $community_url = add_query_arg( $query_args , $this ->edit_profile_url ); $wordpress_url = add_query_arg( $query_args , $this ->edit_url ); $bp_active = false; $wp_active = ' nav-tab-active' ; if ( 'BuddyPress' === $active ) { $bp_active = ' nav-tab-active' ; $wp_active = false; } ?> <h2 id= "profile-nav" class = "nav-tab-wrapper" > <?php /** * In configs where BuddyPress is not network activated, as regular * admins do not have the capacity to edit other users, we must add * this check. */ if ( current_user_can( 'edit_user' , $user ->ID ) ) : ?> <a class = "nav-tab<?php echo esc_attr( $wp_active ); ?>" href= "<?php echo esc_url( $wordpress_url );?>" ><?php _e( 'Profile' , 'buddyboss' ); ?></a> <?php endif ; ?> <a class = "nav-tab<?php echo esc_attr( $bp_active ); ?>" href= "<?php echo esc_url( $community_url );?>" ><?php _e( 'Extended Profile' , 'buddyboss' ); ?></a> </h2> <?php } /** * Set up the user's profile admin page. * * Loaded before the page is rendered, this function does all initial * setup, including: processing form requests, registering contextual * help, and setting up screen options. * * @since BuddyPress 2.0.0 */ public function user_admin_load() { // Get the user ID. $user_id = $this ->get_user_id(); // Can current user edit this profile? if ( ! $this ->member_can_edit( $user_id ) ) { wp_die( __( 'You cannot edit the requested user.' , 'buddyboss' ) ); } // Build redirection URL. $redirect_to = remove_query_arg( array ( 'action' , 'error' , 'updated' , 'spam' , 'ham' , 'delete_avatar' ), $_SERVER [ 'REQUEST_URI' ] ); $doaction = ! empty ( $_REQUEST [ 'action' ] ) ? $_REQUEST [ 'action' ] : false; if ( ! empty ( $_REQUEST [ 'user_status' ] ) ) { $spam = (bool) ( 'spam' === $_REQUEST [ 'user_status' ] ); if ( $spam !== bp_is_user_spammer( $user_id ) ) { $doaction = $_REQUEST [ 'user_status' ]; } } /** * Fires at the start of the signups admin load. * * @since BuddyPress 2.0.0 * * @param string $doaction Current bulk action being processed. * @param array $_REQUEST Current $_REQUEST global. */ do_action_ref_array( 'bp_members_admin_load' , array ( $doaction , $_REQUEST ) ); /** * Filters the allowed actions for use in the user admin page. * * @since BuddyPress 2.0.0 * * @param array $value Array of allowed actions to use. */ $allowed_actions = apply_filters( 'bp_members_admin_allowed_actions' , array ( 'update' , 'delete_avatar' , 'spam' , 'ham' ) ); // Prepare the display of the Community Profile screen. if ( ! in_array( $doaction , $allowed_actions ) ) { add_screen_option( 'layout_columns' , array ( 'default' => 2, 'max' => 2, ) ); get_current_screen()->add_help_tab( array ( 'id' => 'bp-profile-edit-overview' , 'title' => __( 'Overview' , 'buddyboss' ), 'content' => '<p>' . __( 'This is the admin view of a user\'s profile.' , 'buddyboss' ) . '</p>' . '<p>' . __( 'In the main column, you can edit the fields of the user\'s extended profile.' , 'buddyboss' ) . '</p>' . '<p>' . __( 'In the right-hand column, you can update the user\'s status, delete the user\'s avatar, and view recent statistics.' , 'buddyboss' ) . '</p>' ) ); // Help panel - sidebar links. get_current_screen()->set_help_sidebar( '<p><strong>' . __( 'For more information:' , 'buddyboss' ) . '</strong></p>' . '<p>' . __( '<a href="https://www.buddyboss.com/resources/">Documentation</a>' , 'buddyboss' ) . '</p>' ); // Register metaboxes for the edit screen. add_meta_box( 'submitdiv' , __( 'Status' , 'buddyboss' ), array ( $this , 'user_admin_status_metabox' ), get_current_screen()->id, 'side' , 'core' ); // In case xprofile is not active. $this ->stats_metabox->context = 'normal' ; $this ->stats_metabox->priority = 'core' ; /** * Fires before loading the profile fields if component is active. * * Plugins should not use this hook, please use 'bp_members_admin_user_metaboxes' instead. * * @since BuddyPress 2.0.0 * * @param int $user_id Current user ID for the screen. * @param string $id Current screen ID. * @param object $stats_metabox Object holding position data for use with the stats metabox. */ do_action_ref_array( 'bp_members_admin_xprofile_metabox' , array ( $user_id , get_current_screen()->id, $this ->stats_metabox ) ); // If xProfile is inactive, difficult to know what's profile we're on. if ( 'normal' === $this ->stats_metabox->context ) { $display_name = bp_core_get_user_displayname( $user_id ); } else { $display_name = __( 'Member' , 'buddyboss' ); } // User Stat metabox. add_meta_box( 'bp_members_admin_user_stats' , sprintf( __( "%s's Stats" , 'buddyboss' ), $display_name ), array ( $this , 'user_admin_stats_metabox' ), get_current_screen()->id, sanitize_key( $this ->stats_metabox->context ), sanitize_key( $this ->stats_metabox->priority ) ); // profile type metabox. Only added if profile types have been registered. $member_types = bp_get_member_types(); if ( ! empty ( $member_types ) ) { add_meta_box( 'bp_members_admin_member_type' , __( 'Profile Type' , 'buddyboss' ), array ( $this , 'user_admin_member_type_metabox' ), get_current_screen()->id, 'side' , 'core' ); } /** * Fires at the end of the Community Profile screen. * * Plugins can restrict metabox to "bp_moderate" admins by checking if * the first argument ($this->is_self_profile) is false in their callback. * They can also restrict their metabox to self profile editing * by setting it to true. * * @since BuddyPress 2.0.0 * * @param bool $is_self_profile Whether or not it is the current user's profile. * @param int $user_id Current user ID. */ do_action( 'bp_members_admin_user_metaboxes' , $this ->is_self_profile, $user_id ); // Enqueue JavaScript files. wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'dashboard' ); // Spam or Ham user. } elseif ( in_array( $doaction , array ( 'spam' , 'ham' ) ) && empty ( $this ->is_self_profile ) ) { check_admin_referer( 'edit-bp-profile_' . $user_id ); if ( bp_core_process_spammer_status( $user_id , $doaction ) ) { $redirect_to = add_query_arg( 'updated' , $doaction , $redirect_to ); } else { $redirect_to = add_query_arg( 'error' , $doaction , $redirect_to ); } bp_core_redirect( $redirect_to ); // Update other stuff once above ones are done. } else { $this ->redirect = $redirect_to ; /** * Fires at end of user profile admin load if doaction does not match any available actions. * * @since BuddyPress 2.0.0 * * @param string $doaction Current bulk action being processed. * @param int $user_id Current user ID. * @param array $_REQUEST Current $_REQUEST global. * @param string $redirect Determined redirect url to send user to. */ do_action_ref_array( 'bp_members_admin_update_user' , array ( $doaction , $user_id , $_REQUEST , $this ->redirect ) ); bp_core_redirect( $this ->redirect ); } } /** * Display the user's profile. * * @since BuddyPress 2.0.0 */ public function user_admin() { if ( ! bp_current_user_can( 'bp_moderate' ) && empty ( $this ->is_self_profile ) ) { die ( '-1' ); } // Get the user ID. $user_id = $this ->get_user_id(); $user = get_user_to_edit( $user_id ); // Construct title. if ( true === $this ->is_self_profile ) { $title = __( 'Profile' , 'buddyboss' ); } else { $title = __( 'Edit User' , 'buddyboss' ); } // Construct URL for form. $request_url = remove_query_arg( array ( 'action' , 'error' , 'updated' , 'spam' , 'ham' ), $_SERVER [ 'REQUEST_URI' ] ); $form_action_url = add_query_arg( 'action' , 'update' , $request_url ); $wp_http_referer = false; if ( ! empty ( $_REQUEST [ 'wp_http_referer' ] ) ) { $wp_http_referer = wp_unslash( $_REQUEST [ 'wp_http_referer' ] ); $wp_http_referer = remove_query_arg( array ( 'action' , 'updated' ), $wp_http_referer ); $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) ); } // Prepare notice for admin. $notice = $this ->get_user_notice(); if ( ! empty ( $notice ) ) : ?> <div <?php if ( 'updated' === $notice [ 'class' ] ) : ?>id= "message" <?php endif ; ?> class = "<?php echo esc_attr( $notice['class'] ); ?>" > <p><?php echo esc_html( $notice [ 'message' ] ); ?></p> <?php if ( ! empty ( $wp_http_referer ) && ( 'updated' === $notice [ 'class' ] ) ) : ?> <p><a href= "<?php echo esc_url( $wp_http_referer ); ?>" ><?php esc_html_e( '← Back to Users' , 'buddyboss' ); ?></a></p> <?php endif ; ?> </div> <?php endif ; ?> <div class = "wrap" id= "community-profile-page" > <?php if ( version_compare( $GLOBALS [ 'wp_version' ], '4.8' , '>=' ) ) : ?> <h1 class = "wp-heading-inline" ><?php echo esc_html( $title ); ?></h1> <?php if ( empty ( $this ->is_self_profile ) ) : ?> <?php if ( current_user_can( 'create_users' ) ) : ?> <a href= "user-new.php" class = "page-title-action" ><?php echo esc_html__( 'Add New' , 'buddyboss' ); ?></a> <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?> <a href= "user-new.php" class = "page-title-action" ><?php echo esc_html__( 'Add Existing' , 'buddyboss' ); ?></a> <?php endif ; ?> <?php endif ; ?> <hr class = "wp-header-end" > <?php else : ?> <h1><?php echo esc_html( $title ); ?> <?php if ( empty ( $this ->is_self_profile ) ) : ?> <?php if ( current_user_can( 'create_users' ) ) : ?> <a href= "user-new.php" class = "add-new-h2" ><?php echo esc_html__( 'Add New' , 'buddyboss' ); ?></a> <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?> <a href= "user-new.php" class = "add-new-h2" ><?php echo esc_html__( 'Add Existing' , 'buddyboss' ); ?></a> <?php endif ; ?> <?php endif ; ?> </h1> <?php endif ; ?> <?php if ( ! empty ( $user ) ) : $this ->profile_nav( $user , 'BuddyPress' ); ?> <form action= "<?php echo esc_url( $form_action_url ); ?>" id= "your-profile" method= "post" > <div id= "poststuff" > <div id= "post-body" class = "metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>" > <div id= "postbox-container-1" class = "postbox-container" > <?php do_meta_boxes( get_current_screen()->id, 'side' , $user ); ?> </div> <div id= "postbox-container-2" class = "postbox-container" > <?php do_meta_boxes( get_current_screen()->id, 'normal' , $user ); ?> <?php do_meta_boxes( get_current_screen()->id, 'advanced' , $user ); ?> </div> </div><!-- #post-body --> </div><!-- #poststuff --> <?php wp_nonce_field( 'closedpostboxes' , 'closedpostboxesnonce' , false ); ?> <?php wp_nonce_field( 'meta-box-order' , 'meta-box-order-nonce' , false ); ?> <?php wp_nonce_field( 'edit-bp-profile_' . $user ->ID ); ?> </form> <?php else : ?> <p><?php printf( '%1$s <a href="%2$s">%3$s</a>' , __( 'No user found with this ID.' , 'buddyboss' ), esc_url( bp_get_admin_url( 'users.php' ) ), __( 'Go back and try again.' , 'buddyboss' ) ); ?></p> <?php endif ; ?> </div><!-- .wrap --> <?php } /** * Render the Status metabox for user's profile screen. * * Actions are: * - Update profile fields if xProfile component is active * - Spam/Unspam user * * @since BuddyPress 2.0.0 * * @param WP_User|null $user The WP_User object to be edited. */ public function user_admin_status_metabox( $user = null ) { // Bail if no user id or if the user has not activated their account yet. if ( empty ( $user ->ID ) ) { return ; } // Bail if user has not been activated yet (how did you get here?). if ( isset( $user ->user_status ) && ( 2 == $user ->user_status ) ) : ?> <p class = "not-activated" ><?php esc_html_e( 'User account has not yet been activated' , 'buddyboss' ); ?></p><br/> <?php return ; endif ; ?> <div class = "submitbox" id= "submitcomment" > <div id= "minor-publishing" > <div id= "misc-publishing-actions" > <?php // Get the spam status once here to compare against below. $is_spammer = bp_is_user_spammer( $user ->ID ); /** * In configs where BuddyPress is not network activated, * regular admins cannot mark a user as a spammer on front * end. This prevent them to do it in the back end. * * Also prevent admins from marking themselves or other * admins as spammers. */ if ( ( empty ( $this ->is_self_profile ) && ( ! in_array( $user ->user_login, get_super_admins() ) ) && empty ( $this ->subsite_activated ) ) || ( ! empty ( $this ->subsite_activated ) && current_user_can( 'manage_network_users' ) ) ) : ?> <div class = "misc-pub-section" id= "comment-status-radio" > <label class = "approved" ><input type= "radio" name= "user_status" value= "ham" <?php checked( $is_spammer , false ); ?>><?php esc_html_e( 'Active' , 'buddyboss' ); ?></label><br /> <label class = "spam" ><input type= "radio" name= "user_status" value= "spam" <?php checked( $is_spammer , true ); ?>><?php esc_html_e( 'Spammer' , 'buddyboss' ); ?></label> </div> <?php endif ;?> <div class = "misc-pub-section curtime misc-pub-section-last" > <?php // Translators: Publish box date format, see http://php.net/date. $datef = __( 'M j, Y @ G:i' , 'buddyboss' ); $date = date_i18n( $datef , strtotime ( $user ->user_registered ) ); ?> <span id= "timestamp" ><?php printf( __( 'Registered on: %s' , 'buddyboss' ), '<strong>' . $date . '</strong>' ); ?></span> </div> </div> <!-- #misc-publishing-actions --> <div class = "clear" ></div> </div><!-- #minor-publishing --> <div id= "major-publishing-actions" > <div id= "publishing-action" > <a class = "button bp-view-profile" href= "<?php echo esc_url( bp_core_get_user_domain( $user->ID ) ); ?>" target= "_blank" ><?php esc_html_e( 'View Profile' , 'buddyboss' ); ?></a> <?php submit_button( esc_html__( 'Update Profile' , 'buddyboss' ), 'primary' , 'save' , false ); ?> </div> <div class = "clear" ></div> </div><!-- #major-publishing-actions --> </div><!-- #submitcomment --> <?php } /** * Render the fallback metabox in case a user has been marked as a spammer. * * @since BuddyPress 2.0.0 * * @param WP_User|null $user The WP_User object to be edited. */ public function user_admin_spammer_metabox( $user = null ) { ?> <p><?php printf( __( '%s has been marked as a spammer. All BuddyPress data associated with the user has been removed' , 'buddyboss' ), esc_html( bp_core_get_user_displayname( $user ->ID ) ) ) ;?></p> <?php } /** * Render the Stats metabox to moderate inappropriate images. * * @since BuddyPress 2.0.0 * * @param WP_User|null $user The WP_User object to be edited. */ public function user_admin_stats_metabox( $user = null ) { // Bail if no user ID. if ( empty ( $user ->ID ) ) { return ; } // If account is not activated last activity is the time user registered. if ( isset( $user ->user_status ) && 2 == $user ->user_status ) { $last_active = $user ->user_registered; // Account is activated, getting user's last activity. } else { $last_active = bp_get_user_last_activity( $user ->ID ); } $datef = __( 'M j, Y @ G:i' , 'buddyboss' ); $date = date_i18n( $datef , strtotime ( $last_active ) ); ?> <ul> <li class = "bp-members-profile-stats" ><?php printf( __( 'Last active: %1$s' , 'buddyboss' ), '<strong>' . $date . '</strong>' ); ?></li> <?php // Loading other stats only if user has activated their account. if ( empty ( $user ->user_status ) ) { /** * Fires in the user stats metabox if the user has activated their account. * * @since BuddyPress 2.0.0 * * @param array $value Array holding the user ID. * @param object $user Current displayed user object. */ do_action( 'bp_members_admin_user_stats' , array ( 'user_id' => $user ->ID ), $user ); } ?> </ul> <?php } /** * Render the profile type metabox. * * @since BuddyPress 2.2.0 * * @param WP_User|null $user The WP_User object to be edited. */ public function user_admin_member_type_metabox( $user = null ) { // Bail if no user ID. if ( empty ( $user ->ID ) ) { return ; } $types = bp_get_member_types( array (), 'objects' ); $current_type = bp_get_member_type( $user ->ID ); ?> <label for = "bp-members-profile-member-type" class = "screen-reader-text" ><?php /* translators: accessibility text */ esc_html_e( 'Select profile type' , 'buddyboss' ); ?></label> <select name= "bp-members-profile-member-type" id= "bp-members-profile-member-type" > <option value= "" <?php selected( '' , $current_type ); ?>><?php /* translators: no option picked in select box */ esc_attr_e( '----' , 'buddyboss' ); ?></option> <?php foreach ( $types as $type ) : ?> <option value= "<?php echo esc_attr( $type->name ) ?>" <?php selected( $type ->name, $current_type ) ?>><?php echo esc_html( $type ->labels[ 'singular_name' ] ) ?></option> <?php endforeach ; ?> </select> <?php wp_nonce_field( 'bp-member-type-change-' . $user ->ID, 'bp-member-type-nonce' ); } /** * Process changes from the profile type metabox. * * @since BuddyPress 2.2.0 */ public function process_member_type_update() { if ( ! isset( $_POST [ 'bp-member-type-nonce' ] ) || ! isset( $_POST [ 'bp-members-profile-member-type' ] ) ) { return ; } $user_id = $this ->get_user_id(); check_admin_referer( 'bp-member-type-change-' . $user_id , 'bp-member-type-nonce' ); // Permission check. if ( ! bp_current_user_can( 'bp_moderate' ) && $user_id != bp_loggedin_user_id() ) { return ; } // profile type string must either reference a valid profile type, or be empty. $member_type = stripslashes ( $_POST [ 'bp-members-profile-member-type' ] ); if ( ! empty ( $member_type ) && ! bp_get_member_type_object( $member_type ) ) { return ; } if ( '' !== $member_type ) { // Get post id of selected profile type. $post_id = bp_member_type_post_by_type( $member_type ); // Get selected profile type role. $selected_member_type_wp_roles = get_post_meta( $post_id , '_bp_member_type_wp_roles' , true ); if ( $user_id === get_current_user_id() ) { if ( 'administrator' !== $selected_member_type_wp_roles [0] ) { if ( empty ( $selected_member_type_wp_roles ) ) { /* * If an invalid profile type is passed, someone's doing something * fishy with the POST request, so we can fail silently. */ if ( bp_set_member_type( $user_id , $member_type ) ) { // @todo Success messages can't be posted because other stuff happens on the page load. } } else { $bp_error_message_string = __( 'You cannot assign yourself to this profile type as doing so would remove your Administrator role and lock you out of the WordPress admin. You first need to associate this profile type to the Administrator role, and then you can assign it to yourself.' , 'buddyboss' ); $error_message = apply_filters( 'bp_invalid_role_selection_extended_profile' , $bp_error_message_string ); // Define the settings error to display add_settings_error( 'bp-invalid-role-selection-extended-profile' , 'bp-invalid-role-selection-extended-profile' , $error_message , 'error' ); set_transient( 'bp_invalid_role_selection_extended_profile' , get_settings_errors(), 30 ); return ; } } else { $bp_current_user = new WP_User( get_current_user_id() ); // Remove role $bp_current_user ->remove_role( $bp_current_user ->roles[0] ); // Add role $bp_current_user ->add_role( $selected_member_type_wp_roles [0] ); } } else { $bp_user = new WP_User( $user_id ); // Remove role $bp_user ->remove_role( $bp_user ->roles[0] ); // Add role $bp_user ->add_role( $selected_member_type_wp_roles [0] ); } } /* * If an invalid profile type is passed, someone's doing something * fishy with the POST request, so we can fail silently. */ if ( bp_set_member_type( $user_id , $member_type ) ) { // @todo Success messages can't be posted because other stuff happens on the page load. } } /** * Add a link to Profile in Users listing row actions. * * @since BuddyPress 2.0.0 * * @param array|string $actions WordPress row actions (edit, delete). * @param object|null $user The object for the user row. * @return null|string|array Merged actions. */ public function row_actions( $actions = '' , $user = null ) { // Bail if no user ID. if ( empty ( $user ->ID ) ) { return ; } // Setup args array. $args = array (); // Add the user ID if it's not for the current user. if ( $user ->ID !== $this ->current_user_id ) { $args [ 'user_id' ] = $user ->ID; } // Add the referer. $wp_http_referer = wp_unslash( $_SERVER [ 'REQUEST_URI' ] ); $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) ); $args [ 'wp_http_referer' ] = urlencode( $wp_http_referer ); // Add the "Extended" link if the current user can edit this user. if ( current_user_can( 'edit_user' , $user ->ID ) || bp_current_user_can( 'bp_moderate' ) ) { // Add query args and setup the Extended link. $edit_profile = add_query_arg( $args , $this ->edit_profile_url ); $edit_profile_link = sprintf( '<a href="%1$s">%2$s</a>' , esc_url( $edit_profile ), esc_html__( 'Extended' , 'buddyboss' ) ); /** * Check the edit action is available * and preserve the order edit | profile | remove/delete. */ if ( ! empty ( $actions [ 'edit' ] ) ) { $edit_action = $actions [ 'edit' ]; unset( $actions [ 'edit' ] ); $new_edit_actions = array ( 'edit' => $edit_action , 'edit-profile' => $edit_profile_link , ); // If not available simply add the edit profile action. } else { $new_edit_actions = array ( 'edit-profile' => $edit_profile_link ); } $actions = array_merge ( $new_edit_actions , $actions ); } return $actions ; } /** * Add a filter to edit profile url in WP Admin Bar. * * @since BuddyPress 2.1.0 */ public function add_edit_profile_url_filter() { add_filter( 'bp_members_edit_profile_url' , array ( $this , 'filter_adminbar_profile_link' ), 10, 3 ); } /** * Filter the profile url. * * @since BuddyPress 2.1.0 * * @param string $profile_link Profile Link for admin bar. * @param string $url Profile URL. * @param int $user_id User ID. * @return string */ public function filter_adminbar_profile_link( $profile_link = '' , $url = '' , $user_id = 0 ) { if ( ! is_super_admin( $user_id ) && is_admin() ) { $profile_link = user_admin_url( 'profile.php' ); } return $profile_link ; } /** * Remove the filter to edit profile url in WP Admin Bar. * * @since BuddyPress 2.1.0 */ public function remove_edit_profile_url_filter() { remove_filter( 'bp_members_edit_profile_url' , array ( $this , 'filter_adminbar_profile_link' ), 10 ); } /** Signups Management ****************************************************/ /** * Display the admin preferences about signups pagination. * * @since BuddyPress 2.0.0 * * @param int $value Value for signup option. * @param string $option Value for the option key. * @param int $new_value Value for the saved option. * @return int The pagination preferences. */ public function signup_screen_options( $value = 0, $option = '' , $new_value = 0 ) { if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option ) { return $value ; } // Per page. $new_value = (int) $new_value ; if ( $new_value < 1 || $new_value > 999 ) { return $value ; } return $new_value ; } /** * Make sure no signups will show in users list. * * This is needed to handle signups that may have not been activated * before the 2.0.0 upgrade. * * @since BuddyPress 2.0.0 * * @param WP_User_Query|null $query The users query. * @return WP_User_Query|null The users query without the signups. */ public function remove_signups_from_user_query( $query = null ) { global $wpdb ; // Bail if this is an ajax request. if ( defined( 'DOING_AJAX' ) ) { return ; } // Bail if updating BuddyPress. if ( bp_is_update() ) { return ; } // Bail if there is no current admin screen. if ( ! function_exists( 'get_current_screen' ) || ! get_current_screen() ) { return ; } // Get current screen. $current_screen = get_current_screen(); // Bail if not on a users page. if ( ! isset( $current_screen ->id ) || $this ->users_page !== $current_screen ->id ) { return ; } // Bail if already querying by an existing role. if ( ! empty ( $query ->query_vars[ 'role' ] ) ) { return ; } $query ->query_where .= " AND {$wpdb->users}.user_status != 2" ; } /** * Filter the WP Users List Table views to include 'bp-signups'. * * @since BuddyPress 2.0.0 * * @param array $views WP List Table views. * @return array The views with the signup view added. */ public function signup_filter_view( $views = array () ) { global $role ; // Remove the 'current' class from All if we're on the signups view. if ( 'registered' === $role ) { $views [ 'all' ] = str_replace ( 'class="current"' , '' , $views [ 'all' ] ); $class = 'current' ; } else { $class = '' ; } $signups = BP_Signup::count_signups(); if ( is_network_admin() ) { $base_url = network_admin_url( 'users.php' ); } else { $base_url = bp_get_admin_url( 'users.php' ); } $url = add_query_arg( 'page' , 'bp-signups' , $base_url ); $text = sprintf( __( 'Pending %s' , 'buddyboss' ), '<span class="count">(' . number_format_i18n( $signups ) . ')</span>' ); $views [ 'registered' ] = sprintf( '<a href="%1$s" class="%2$s">%3$s</a>' , esc_url( $url ), $class , $text ); return $views ; } /** * Load the Signup WP Users List table. * * @since BuddyPress 2.0.0 * * @param string $class The name of the class to use. * @param string $required The parent class. * @return WP_List_Table|null The List table. */ public static function get_list_table_class( $class = '' , $required = '' ) { if ( empty ( $class ) ) { return ; } if ( ! empty ( $required ) ) { require_once ( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' ); } return new $class (); } /** * Set up the signups admin page. * * Loaded before the page is rendered, this function does all initial * setup, including: processing form requests, registering contextual * help, and setting up screen options. * * @since BuddyPress 2.0.0 * * @global $bp_members_signup_list_table */ public function signups_admin_load() { global $bp_members_signup_list_table ; // Build redirection URL. $redirect_to = remove_query_arg( array ( 'action' , 'error' , 'updated' , 'activated' , 'notactivated' , 'deleted' , 'notdeleted' , 'resent' , 'notresent' , 'do_delete' , 'do_resend' , 'do_activate' , '_wpnonce' , 'signup_ids' ), $_SERVER [ 'REQUEST_URI' ] ); $doaction = bp_admin_list_table_current_bulk_action(); /** * Fires at the start of the signups admin load. * * @since BuddyPress 2.0.0 * * @param string $doaction Current bulk action being processed. * @param array $_REQUEST Current $_REQUEST global. */ do_action( 'bp_signups_admin_load' , $doaction , $_REQUEST ); /** * Filters the allowed actions for use in the user signups admin page. * * @since BuddyPress 2.0.0 * * @param array $value Array of allowed actions to use. */ $allowed_actions = apply_filters( 'bp_signups_admin_allowed_actions' , array ( 'do_delete' , 'do_activate' , 'do_resend' ) ); // Prepare the display of the Community Profile screen. if ( ! in_array( $doaction , $allowed_actions ) || ( -1 == $doaction ) ) { if ( is_network_admin() ) { $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_MS_List_Table' , 'ms-users' ); } else { $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_List_Table' , 'users' ); } // The per_page screen option. add_screen_option( 'per_page' , array ( 'label' => __( 'Pending Accounts' , 'buddyboss' ) ) ); get_current_screen()->add_help_tab( array ( 'id' => 'bp-signups-overview' , 'title' => __( 'Overview' , 'buddyboss' ), 'content' => '<p>' . __( 'This is the administration screen for pending accounts on your site.' , 'buddyboss' ) . '</p>' . '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.' , 'buddyboss' ) . '</p>' . '<p>' . __( 'You can reorder the list of your pending accounts by clicking on the Username, Email or Registered column headers.' , 'buddyboss' ) . '</p>' . '<p>' . __( 'Using the search form, you can find pending accounts more easily. The Username and Email fields will be included in the search.' , 'buddyboss' ) . '</p>' ) ); get_current_screen()->add_help_tab( array ( 'id' => 'bp-signups-actions' , 'title' => __( 'Actions' , 'buddyboss' ), 'content' => '<p>' . __( 'Hovering over a row in the pending accounts list will display action links that allow you to manage pending accounts. You can perform the following actions:' , 'buddyboss' ) . '</p>' . '<ul><li>' . __( '"Email" takes you to the confirmation screen before being able to send the activation link to the desired pending account. You can only send the activation email once per day.' , 'buddyboss' ) . '</li>' . '<li>' . __( '"Delete" allows you to delete a pending account from your site. You will be asked to confirm this deletion.' , 'buddyboss' ) . '</li></ul>' . '<p>' . __( 'By clicking on a Username you will be able to activate a pending account from the confirmation screen.' , 'buddyboss' ) . '</p>' . '<p>' . __( 'Bulk actions allow you to perform these 3 actions for the selected rows.' , 'buddyboss' ) . '</p>' ) ); // Help panel - sidebar links. get_current_screen()->set_help_sidebar( '<p><strong>' . __( 'For more information:' , 'buddyboss' ) . '</strong></p>' . '<p>' . __( '<a href="https://www.buddyboss.com/resources/">Documentation</a>' , 'buddyboss' ) . '</p>' ); // Add accessible hidden headings and text for the Pending Users screen. get_current_screen()->set_screen_reader_content( array ( /* translators: accessibility text */ 'heading_views' => __( 'Filter users list' , 'buddyboss' ), /* translators: accessibility text */ 'heading_pagination' => __( 'Pending users list navigation' , 'buddyboss' ), /* translators: accessibility text */ 'heading_list' => __( 'Pending users list' , 'buddyboss' ), ) ); } else { if ( ! empty ( $_REQUEST [ 'signup_ids' ] ) ) { $signups = wp_parse_id_list( $_REQUEST [ 'signup_ids' ] ); } // Handle resent activation links. if ( 'do_resend' == $doaction ) { // Nonce check. check_admin_referer( 'signups_resend' ); $resent = BP_Signup::resend( $signups ); if ( empty ( $resent ) ) { $redirect_to = add_query_arg( 'error' , $doaction , $redirect_to ); } else { $query_arg = array ( 'updated' => 'resent' ); if ( ! empty ( $resent [ 'resent' ] ) ) { $query_arg [ 'resent' ] = count ( $resent [ 'resent' ] ); } if ( ! empty ( $resent [ 'errors' ] ) ) { $query_arg [ 'notsent' ] = count ( $resent [ 'errors' ] ); set_transient( '_bp_admin_signups_errors' , $resent [ 'errors' ], 30 ); } $redirect_to = add_query_arg( $query_arg , $redirect_to ); } bp_core_redirect( $redirect_to ); // Handle activated accounts. } elseif ( 'do_activate' == $doaction ) { // Nonce check. check_admin_referer( 'signups_activate' ); $activated = BP_Signup::activate( $signups ); if ( empty ( $activated ) ) { $redirect_to = add_query_arg( 'error' , $doaction , $redirect_to ); } else { $query_arg = array ( 'updated' => 'activated' ); if ( ! empty ( $activated [ 'activated' ] ) ) { $query_arg [ 'activated' ] = count ( $activated [ 'activated' ] ); } if ( ! empty ( $activated [ 'errors' ] ) ) { $query_arg [ 'notactivated' ] = count ( $activated [ 'errors' ] ); set_transient( '_bp_admin_signups_errors' , $activated [ 'errors' ], 30 ); } $redirect_to = add_query_arg( $query_arg , $redirect_to ); } bp_core_redirect( $redirect_to ); // Handle sign-ups delete. } elseif ( 'do_delete' == $doaction ) { // Nonce check. check_admin_referer( 'signups_delete' ); $deleted = BP_Signup:: delete ( $signups ); if ( empty ( $deleted ) ) { $redirect_to = add_query_arg( 'error' , $doaction , $redirect_to ); } else { $query_arg = array ( 'updated' => 'deleted' ); if ( ! empty ( $deleted [ 'deleted' ] ) ) { $query_arg [ 'deleted' ] = count ( $deleted [ 'deleted' ] ); } if ( ! empty ( $deleted [ 'errors' ] ) ) { $query_arg [ 'notdeleted' ] = count ( $deleted [ 'errors' ] ); set_transient( '_bp_admin_signups_errors' , $deleted [ 'errors' ], 30 ); } $redirect_to = add_query_arg( $query_arg , $redirect_to ); } bp_core_redirect( $redirect_to ); // Plugins can update other stuff from here. } else { $this ->redirect = $redirect_to ; /** * Fires at end of signups admin load if doaction does not match any actions. * * @since BuddyPress 2.0.0 * * @param string $doaction Current bulk action being processed. * @param array $_REQUEST Current $_REQUEST global. * @param string $redirect Determined redirect url to send user to. */ do_action( 'bp_members_admin_update_signups' , $doaction , $_REQUEST , $this ->redirect ); bp_core_redirect( $this ->redirect ); } } } /** * Display any activation errors. * * @since BuddyPress 2.0.0 */ public function signups_display_errors() { // Look for sign-up errors. $errors = get_transient( '_bp_admin_signups_errors' ); // Bail if no activation errors. if ( empty ( $errors ) ) { return ; } // Loop through errors and display them. foreach ( $errors as $error ) : ?> <li><?php echo esc_html( $error [0] );?>: <?php echo esc_html( $error [1] );?></li> <?php endforeach ; // Delete the redirect transient. delete_transient( '_bp_admin_signups_errors' ); } /** * Get admin notice when viewing the sign-up page. * * @since BuddyPress 2.1.0 * * @return array */ private function get_signup_notice() { // Setup empty notice for return value. $notice = array (); // Updates. if ( ! empty ( $_REQUEST [ 'updated' ] ) ) { switch ( $_REQUEST [ 'updated' ] ) { case 'resent' : $notice = array ( 'class' => 'updated' , 'message' => '' ); if ( ! empty ( $_REQUEST [ 'resent' ] ) ) { $notice [ 'message' ] .= sprintf( _n( '%s activation email successfully sent! ' , '%s activation emails successfully sent! ' , absint( $_REQUEST [ 'resent' ] ), 'buddyboss' ), number_format_i18n( absint( $_REQUEST [ 'resent' ] ) ) ); } if ( ! empty ( $_REQUEST [ 'notsent' ] ) ) { $notice [ 'message' ] .= sprintf( _n( '%s activation email was not sent.' , '%s activation emails were not sent.' , absint( $_REQUEST [ 'notsent' ] ), 'buddyboss' ), number_format_i18n( absint( $_REQUEST [ 'notsent' ] ) ) ); if ( empty ( $_REQUEST [ 'resent' ] ) ) { $notice [ 'class' ] = 'error' ; } } break ; case 'activated' : $notice = array ( 'class' => 'updated' , 'message' => '' ); if ( ! empty ( $_REQUEST [ 'activated' ] ) ) { $notice [ 'message' ] .= sprintf( _n( '%s account successfully activated! ' , '%s accounts successfully activated! ' , absint( $_REQUEST [ 'activated' ] ), 'buddyboss' ), number_format_i18n( absint( $_REQUEST [ 'activated' ] ) ) ); } if ( ! empty ( $_REQUEST [ 'notactivated' ] ) ) { $notice [ 'message' ] .= sprintf( _n( '%s account was not activated.' , '%s accounts were not activated.' , absint( $_REQUEST [ 'notactivated' ] ), 'buddyboss' ), number_format_i18n( absint( $_REQUEST [ 'notactivated' ] ) ) ); if ( empty ( $_REQUEST [ 'activated' ] ) ) { $notice [ 'class' ] = 'error' ; } } break ; case 'deleted' : $notice = array ( 'class' => 'updated' , 'message' => '' ); if ( ! empty ( $_REQUEST [ 'deleted' ] ) ) { $notice [ 'message' ] .= sprintf( _n( '%s sign-up successfully deleted!' , '%s sign-ups successfully deleted!' , absint( $_REQUEST [ 'deleted' ] ), 'buddyboss' ), number_format_i18n( absint( $_REQUEST [ 'deleted' ] ) ) ); } if ( ! empty ( $_REQUEST [ 'notdeleted' ] ) ) { $notice [ 'message' ] .= sprintf( _n( '%s sign-up was not deleted.' , '%s sign-ups were not deleted.' , absint( $_REQUEST [ 'notdeleted' ] ), 'buddyboss' ), number_format_i18n( absint( $_REQUEST [ 'notdeleted' ] ) ) ); if ( empty ( $_REQUEST [ 'deleted' ] ) ) { $notice [ 'class' ] = 'error' ; } } break ; } } // Errors. if ( ! empty ( $_REQUEST [ 'error' ] ) ) { switch ( $_REQUEST [ 'error' ] ) { case 'do_resend' : $notice = array ( 'class' => 'error' , 'message' => esc_html__( 'There was a problem sending the activation emails. Please try again.' , 'buddyboss' ), ); break ; case 'do_activate' : $notice = array ( 'class' => 'error' , 'message' => esc_html__( 'There was a problem activating accounts. Please try again.' , 'buddyboss' ), ); break ; case 'do_delete' : $notice = array ( 'class' => 'error' , 'message' => esc_html__( 'There was a problem deleting sign-ups. Please try again.' , 'buddyboss' ), ); break ; } } return $notice ; } /** * Signups admin page router. * * Depending on the context, display * - the list of signups, * - or the delete confirmation screen, * - or the activate confirmation screen, * - or the "resend" email confirmation screen. * * Also prepare the admin notices. * * @since BuddyPress 2.0.0 */ public function signups_admin() { $doaction = bp_admin_list_table_current_bulk_action(); // Prepare notices for admin. $notice = $this ->get_signup_notice(); // Display notices. if ( ! empty ( $notice ) ) : if ( 'updated' === $notice [ 'class' ] ) : ?> <div id= "message" class = "<?php echo esc_attr( $notice['class'] ); ?>" > <?php else : ?> <div class = "<?php echo esc_attr( $notice['class'] ); ?>" > <?php endif ; ?> <p><?php echo $notice [ 'message' ]; ?></p> <?php if ( ! empty ( $_REQUEST [ 'notactivated' ] ) || ! empty ( $_REQUEST [ 'notdeleted' ] ) || ! empty ( $_REQUEST [ 'notsent' ] ) ) :?> <ul><?php $this ->signups_display_errors();?></ul> <?php endif ;?> </div> <?php endif ; // Show the proper screen. switch ( $doaction ) { case 'activate' : case 'delete' : case 'resend' : $this ->signups_admin_manage( $doaction ); break ; default : $this ->signups_admin_index(); break ; } } /** * This is the list of the Pending accounts (signups). * * @since BuddyPress 2.0.0 * * @global $plugin_page * @global $bp_members_signup_list_table */ public function signups_admin_index() { global $plugin_page , $bp_members_signup_list_table ; $usersearch = ! empty ( $_REQUEST [ 's' ] ) ? stripslashes ( $_REQUEST [ 's' ] ) : '' ; // Prepare the group items for display. $bp_members_signup_list_table ->prepare_items(); if ( is_network_admin() ) { $form_url = network_admin_url( 'users.php' ); } else { $form_url = bp_get_admin_url( 'users.php' ); } $form_url = add_query_arg( array ( 'page' => 'bp-signups' , ), $form_url ); $search_form_url = remove_query_arg( array ( 'action' , 'deleted' , 'notdeleted' , 'error' , 'updated' , 'delete' , 'activate' , 'activated' , 'notactivated' , 'resend' , 'resent' , 'notresent' , 'do_delete' , 'do_activate' , 'do_resend' , 'action2' , '_wpnonce' , 'signup_ids' ), $_SERVER [ 'REQUEST_URI' ] ); ?> <div class = "wrap" > <?php if ( version_compare( $GLOBALS [ 'wp_version' ], '4.8' , '>=' ) ) : ?> <h1 class = "wp-heading-inline" ><?php _e( 'Users' , 'buddyboss' ); ?></h1> <?php if ( current_user_can( 'create_users' ) ) : ?> <a href= "user-new.php" class = "page-title-action" ><?php echo esc_html__( 'Add New' , 'buddyboss' ); ?></a> <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?> <a href= "user-new.php" class = "page-title-action" ><?php echo esc_html__( 'Add Existing' , 'buddyboss' ); ?></a> <?php endif ; if ( $usersearch ) { printf( '<span class="subtitle">' . __( 'Search results for "%s"' , 'buddyboss' ) . '</span>' , esc_html( $usersearch ) ); } ?> <hr class = "wp-header-end" > <?php else : ?> <h1><?php _e( 'Users' , 'buddyboss' ); ?> <?php if ( current_user_can( 'create_users' ) ) : ?> <a href= "user-new.php" class = "add-new-h2" ><?php echo esc_html__( 'Add New' , 'buddyboss' ); ?></a> <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?> <a href= "user-new.php" class = "add-new-h2" ><?php echo esc_html__( 'Add Existing' , 'buddyboss' ); ?></a> <?php endif ; if ( $usersearch ) { printf( '<span class="subtitle">' . __( 'Search results for "%s"' , 'buddyboss' ) . '</span>' , esc_html( $usersearch ) ); } ?> </h1> <?php endif ; ?> <?php // Display each signups on its own row. ?> <?php $bp_members_signup_list_table ->views(); ?> <form id= "bp-signups-search-form" action= "<?php echo esc_url( $search_form_url ) ;?>" > <input type= "hidden" name= "page" value= "<?php echo esc_attr( $plugin_page ); ?>" /> <?php $bp_members_signup_list_table ->search_box( __( 'Search Pending Users' , 'buddyboss' ), 'bp-signups' ); ?> </form> <form id= "bp-signups-form" action= "<?php echo esc_url( $form_url );?>" method= "post" > <?php $bp_members_signup_list_table ->display(); ?> </form> </div> <?php } /** * This is the confirmation screen for actions. * * @since BuddyPress 2.0.0 * * @param string $action Delete, activate, or resend activation link. * * @return null|false */ public function signups_admin_manage( $action = '' ) { if ( ! current_user_can( $this ->capability ) || empty ( $action ) ) { die ( '-1' ); } // Get the user IDs from the URL. $ids = false; if ( ! empty ( $_POST [ 'allsignups' ] ) ) { $ids = wp_parse_id_list( $_POST [ 'allsignups' ] ); } elseif ( ! empty ( $_GET [ 'signup_id' ] ) ) { $ids = absint( $_GET [ 'signup_id' ] ); } if ( empty ( $ids ) ) { return false; } // Query for signups, and filter out those IDs that don't // correspond to an actual signup. $signups_query = BP_Signup::get( array ( 'include' => $ids , ) ); $signups = $signups_query [ 'signups' ]; $signup_ids = wp_list_pluck( $signups , 'signup_id' ); // Set up strings. switch ( $action ) { case 'delete' : $header_text = __( 'Delete Pending Accounts' , 'buddyboss' ); if ( 1 == count ( $signup_ids ) ) { $helper_text = __( 'You are about to delete the following account:' , 'buddyboss' ); } else { $helper_text = __( 'You are about to delete the following accounts:' , 'buddyboss' ); } break ; case 'activate' : $header_text = __( 'Activate Pending Accounts' , 'buddyboss' ); if ( 1 == count ( $signup_ids ) ) { $helper_text = __( 'You are about to activate the following account:' , 'buddyboss' ); } else { $helper_text = __( 'You are about to activate the following accounts:' , 'buddyboss' ); } break ; case 'resend' : $header_text = __( 'Resend Activation Emails' , 'buddyboss' ); if ( 1 == count ( $signup_ids ) ) { $helper_text = __( 'You are about to resend an activation email to the following account:' , 'buddyboss' ); } else { $helper_text = __( 'You are about to resend an activation email to the following accounts:' , 'buddyboss' ); } break ; } // These arguments are added to all URLs. $url_args = array ( 'page' => 'bp-signups' ); // These arguments are only added when performing an action. $action_args = array ( 'action' => 'do_' . $action , 'signup_ids' => implode( ',' , $signup_ids ) ); if ( is_network_admin() ) { $base_url = network_admin_url( 'users.php' ); } else { $base_url = bp_get_admin_url( 'users.php' ); } $cancel_url = add_query_arg( $url_args , $base_url ); $action_url = wp_nonce_url( add_query_arg( array_merge ( $url_args , $action_args ), $base_url ), 'signups_' . $action ); // Prefetch registration field data. $fdata = array (); if ( 'activate' === $action && bp_is_active( 'xprofile' ) ) { $field_groups = bp_xprofile_get_groups( array ( 'exclude_fields' => 1, 'update_meta_cache' => false, 'fetch_fields' => true, ) ); foreach ( $field_groups as $fg ) { foreach ( $fg ->fields as $f ) { $fdata [ $f ->id ] = $f ->name; } } } ?> <div class = "wrap" > <h1><?php echo esc_html( $header_text ); ?></h1> <p><?php echo esc_html( $helper_text ); ?></p> <ol class = "bp-signups-list" > <?php foreach ( $signups as $signup ) : $last_notified = mysql2date( 'Y/m/d g:i:s a' , $signup ->date_sent ); $profile_field_ids = array (); // Get all xprofile field IDs except field 1. if ( ! empty ( $signup ->meta[ 'profile_field_ids' ] ) ) { $profile_field_ids = array_flip ( explode ( ',' , $signup ->meta[ 'profile_field_ids' ] ) ); unset( $profile_field_ids [1] ); } ?> <li> <strong><?php echo esc_html( $signup ->user_login ) ?></strong> <?php if ( 'activate' == $action ) : ?> <table class = "wp-list-table widefat fixed striped" > <tbody> <tr> <td class = "column-fields" ><?php esc_html_e( 'Display Name' , 'buddyboss' ); ?></td> <td><?php echo esc_html( $signup ->user_name ); ?></td> </tr> <tr> <td class = "column-fields" ><?php esc_html_e( 'Email' , 'buddyboss' ); ?></td> <td><?php echo sanitize_email( $signup ->user_email ); ?></td> </tr> <?php if ( bp_is_active( 'xprofile' ) && ! empty ( $profile_field_ids ) ) : ?> <?php foreach ( $profile_field_ids as $pid => $noop ) : $field_value = isset( $signup ->meta[ "field_{$pid}" ] ) ? $signup ->meta[ "field_{$pid}" ] : '' ; ?> <tr> <td class = "column-fields" ><?php echo esc_html( $fdata [ $pid ] ); ?></td> <td><?php echo $this ->format_xprofile_field_for_display( $field_value ); ?></td> </tr> <?php endforeach ; ?> <?php endif ; ?> </tbody> </table> <?php endif ; ?> <?php if ( 'resend' == $action ) : ?> <p class = "description" > <?php printf( esc_html__( 'Last notified: %s' , 'buddyboss' ), $last_notified ) ;?> <?php if ( ! empty ( $signup ->recently_sent ) ) : ?> <span class = "attention wp-ui-text-notification" > <?php esc_html_e( '(less than 24 hours ago)' , 'buddyboss' ); ?></span> <?php endif ; ?> </p> <?php endif ; ?> </li> <?php endforeach ; ?> </ol> <?php if ( 'delete' === $action ) : ?> <p><strong><?php esc_html_e( 'This action cannot be undone.' , 'buddyboss' ) ?></strong></p> <?php endif ; ?> <a class = "button-primary" href= "<?php echo esc_url( $action_url ); ?>" ><?php esc_html_e( 'Confirm' , 'buddyboss' ); ?></a> <a class = "button" href= "<?php echo esc_url( $cancel_url ); ?>" ><?php esc_html_e( 'Cancel' , 'buddyboss' ) ?></a> </div> <?php } /** Users List Management ****************************************************/ /** * Display a dropdown to bulk change the profile type of selected user(s). * * @since BuddyPress 2.7.0 * * @param string $which Where this dropdown is displayed - top or bottom. */ public function users_table_output_type_change_select( $which = 'top' ) { // Bail if current user cannot promote users. if ( ! bp_current_user_can( 'promote_users' ) ) { return ; } // `$which` is only passed in WordPress 4.6+. Avoid duplicating controls in earlier versions. static $displayed = false; if ( version_compare( bp_get_major_wp_version(), '4.6' , '<' ) && $displayed ) { return ; } $displayed = true; $id_name = 'bottom' === $which ? 'bp_change_type2' : 'bp_change_type' ; $types = bp_get_member_types( array (), 'objects' ); ?> <label class = "screen-reader-text" for = "<?php echo $id_name; ?>" ><?php _e( 'Change profile type to…' , 'buddyboss' ) ?></label> <select name= "<?php echo $id_name; ?>" id= "<?php echo $id_name; ?>" style= "display:inline-block;float:none;" > <option value= "" ><?php _e( 'Change profile type to…' , 'buddyboss' ) ?></option> <?php foreach ( $types as $type ) : ?> <option value= "<?php echo esc_attr( $type->name ); ?>" ><?php echo esc_html( $type ->labels[ 'singular_name' ] ); ?></option> <?php endforeach ; ?> <option value= "remove_member_type" ><?php _e( 'No Profile Type' , 'buddyboss' ) ?></option> </select> <?php wp_nonce_field( 'bp-bulk-users-change-type-' . bp_loggedin_user_id(), 'bp-bulk-users-change-type-nonce' ); submit_button( __( 'Change' , 'buddyboss' ), 'button' , 'bp_change_member_type' , false ); } /** * Process bulk profile type change submission from the WP admin users list table. * * @since BuddyPress 2.7.0 */ public function users_table_process_bulk_type_change() { // Output the admin notice. $this ->users_type_change_notice(); // Flag for custom error message. $bp_error_message = false; // Bail if no users are specified or if this isn't a BuddyPress action. if ( empty ( $_REQUEST [ 'users' ] ) || ( empty ( $_REQUEST [ 'bp_change_type' ] ) && empty ( $_REQUEST [ 'bp_change_type2' ] ) ) || empty ( $_REQUEST [ 'bp_change_member_type' ] ) ) { return ; } // Bail if nonce check fails. check_admin_referer( 'bp-bulk-users-change-type-' . bp_loggedin_user_id(), 'bp-bulk-users-change-type-nonce' ); // Bail if current user cannot promote users. if ( ! bp_current_user_can( 'promote_users' ) ) { return ; } $new_type = '' ; if ( ! empty ( $_REQUEST [ 'bp_change_type2' ] ) ) { $new_type = sanitize_text_field( $_REQUEST [ 'bp_change_type2' ] ); } elseif ( ! empty ( $_REQUEST [ 'bp_change_type' ] ) ) { $new_type = sanitize_text_field( $_REQUEST [ 'bp_change_type' ] ); } // Check that the selected type actually exists. if ( 'remove_member_type' != $new_type && null === bp_get_member_type_object( $new_type ) ) { $error = true; } else { // Run through user ids. $error = false; foreach ( ( array ) $_REQUEST [ 'users' ] as $user_id ) { $user_id = (int) $user_id ; // Get the old profile type to check against. $member_type = bp_get_member_type( $user_id ); if ( 'remove_member_type' === $new_type ) { // Remove the current profile type, if there's one to remove. if ( $member_type ) { $removed = bp_remove_member_type( $user_id , $member_type ); if ( false === $removed || is_wp_error( $removed ) ) { $error = true; } } } else { if ( $user_id === get_current_user_id() ) { // Set the new profile type. if ( $new_type !== $member_type ) { // Get post id of selected profile type. $post_id = bp_member_type_post_by_type( $new_type ); // Get selected profile type role. $selected_member_type_wp_roles = get_post_meta( $post_id , '_bp_member_type_wp_roles' , true ); if ( empty ( $selected_member_type_wp_roles ) ) { $set = bp_set_member_type( $user_id , $new_type ); if ( false === $set || is_wp_error( $set ) ) { $error = true; } } else { if ( 'administrator' !== $selected_member_type_wp_roles [0] ) { $bp_error_message = true; $error = true; } else { $set = bp_set_member_type( $user_id , $new_type ); if ( false === $set || is_wp_error( $set ) ) { $error = true; } } } } } else { // Set the new profile type. if ( $new_type !== $member_type ) { $set = bp_set_member_type( $user_id , $new_type ); if ( false === $set || is_wp_error( $set ) ) { $error = true; } } } } } } // If there were any errors, show the error message. if ( $error ) { if ( true === $bp_error_message ) { $redirect = add_query_arg( array ( 'updated' => 'member-type-change-owner-error' ), wp_get_referer() ); } else { $redirect = add_query_arg( array ( 'updated' => 'member-type-change-error' ), wp_get_referer() ); } } else { $redirect = add_query_arg( array ( 'updated' => 'member-type-change-success' ), wp_get_referer() ); } wp_redirect( $redirect ); exit (); } /** * Display an admin notice upon profile type bulk update. * * @since BuddyPress 2.7.0 */ public function users_type_change_notice() { $updated = isset( $_REQUEST [ 'updated' ] ) ? $_REQUEST [ 'updated' ] : false; // Display feedback. if ( $updated && in_array( $updated , array ( 'member-type-change-error' , 'member-type-change-success' , 'member-type-change-owner-error' ), true ) ) { if ( 'member-type-change-error' === $updated ) { $notice = __( 'There was an error while changing the profile type. Please try again.' , 'buddyboss' ); $type = 'error' ; } elseif ( 'member-type-change-owner-error' === $updated ) { $notice = __( 'You cannot assign yourself to this profile type as doing so would remove your Administrator role and lock you out of the WordPress admin. You first need to associate this profile type to the Administrator role, and then you can assign it to yourself.' , 'buddyboss' ); $type = 'error' ; } else { $notice = __( 'Profile type was changed successfully.' , 'buddyboss' ); $type = 'updated' ; } bp_core_add_admin_notice( $notice , $type ); } } /** * Add profile type column to the WordPress admin users list table. * * @since BuddyPress 2.7.0 * * @param array $columns Users table columns. * * @return array $columns */ public function users_table_add_type_column( $columns = array () ) { $columns [ bp_get_member_type_tax_name() ] = __( 'Profile Type' , 'buddyboss' ); return $columns ; } /** * Return member's type for display in the WP admin users list table. * * @since BuddyPress 2.7.0 * * @param string $retval * @param string $column_name * @param int $user_id * * @return string profile type as a link to filter all users. */ public function users_table_populate_type_cell( $retval = '' , $column_name = '' , $user_id = 0 ) { // Only looking for profile type column. if ( bp_get_member_type_tax_name() !== $column_name ) { return $retval ; } // Get the profile type. $type = bp_get_member_type( $user_id ); // Output the profile type link. if ( $type_obj = bp_get_member_type_object( $type ) ) { $url = add_query_arg( array ( 'bp-member-type' => urlencode( $type ) ) ); $retval = '<a href="' . esc_url( $url ) . '">' . esc_html( $type_obj ->labels[ 'singular_name' ] ) . '</a>' ; } return $retval ; } /** * Filter WP Admin users list table to include users of the specified type. * * @param WP_Query $query * * @since BuddyPress 2.7.0 */ public function users_table_filter_by_type( $query ) { global $pagenow ; if ( is_admin() && 'users.php' === $pagenow && ! empty ( $_REQUEST [ 'bp-member-type' ] ) ) { $type_slug = sanitize_text_field( $_REQUEST [ 'bp-member-type' ] ); // Check that the type is registered. if ( null == bp_get_member_type_object( $type_slug ) ) { return ; } // Get the list of users that are assigned to this profile type. $type = bp_get_term_by( 'slug' , $type_slug , bp_get_member_type_tax_name() ); if ( empty ( $type ->term_id ) ) { return ; } $user_ids = bp_get_objects_in_term( $type ->term_id, bp_get_member_type_tax_name() ); if ( $user_ids && ! is_wp_error( $user_ids ) ) { $query ->set( 'include' , ( array ) $user_ids ); } } } /** * Formats a signup's xprofile field data for display. * * Operates recursively on arrays, which are then imploded with commas. * * @since BuddyPress 2.8.0 * * @param string|array $value Field value. * @return string */ protected function format_xprofile_field_for_display( $value ) { if ( is_array ( $value ) ) { $value = array_map ( array ( $this , 'format_xprofile_field_for_display' ), $value ); $value = implode( ', ' , $value ); } else { $value = stripslashes ( $value ); $value = esc_html( $value ); } return $value ; } } |
Changelog
Version | Description |
---|---|
BuddyPress 2.0.0 | Introduced. |
Methods
- __construct — Constructor method.
- add_edit_profile_url_filter — Add a filter to edit profile url in WP Admin Bar.
- admin_head — Remove the Edit Profile page.
- admin_menus — Create the All Users / Profile > Edit Profile and All Users Signups submenus.
- bp_group_layout_update_option — Set Cookie to reset the previous layout stored in browser storage.
- bp_profile_layout_update_option — Set Cookie to reset the previous layout stored in browser storage.
- bp_registration_update_option — Update site registrations options based on the BuddyBoss general registration settings.
- bp_registration_update_site_option — Update the BuddyBoss > Settings > General > Registrations options based on the Multi Site registration settings.
- bp_update_registration_update_option — Update site registrations options based on the WordPress settings on plugin activate.
- enqueue_scripts — Add some specific styling to the Edit User and Edit User's Profile page.
- filter_adminbar_profile_link — Filter the profile url.
- format_xprofile_field_for_display — Formats a signup's xprofile field data for display.
- get_list_table_class — Load the Signup WP Users List table.
- get_signup_notice — Get admin notice when viewing the sign-up page.
- get_user_id — Get the user ID.
- get_user_notice — Get admin notice when saving a user or member profile.
- member_can_edit — Can the current user edit the one displayed.
- multisite_registration_on — Create registration pages when multisite user registration is turned on.
- process_member_type_update — Process changes from the profile type metabox.
- profile_admin_head — Highlight the Users menu if on Edit Profile and check if on the user's admin profile.
- profile_nav — Create the Profile navigation in Edit User & Edit Profile pages.
- register_members_admin — Setup BP Members Admin.
- remove_edit_profile_url_filter — Remove the filter to edit profile url in WP Admin Bar.
- remove_signups_from_user_query — Make sure no signups will show in users list.
- row_actions — Add a link to Profile in Users listing row actions.
- setup_actions — Set admin-related actions and filters.
- setup_globals — Set admin-related globals.
- signup_filter_view — Filter the WP Users List Table views to include 'bp-signups'.
- signup_screen_options — Display the admin preferences about signups pagination.
- signups_admin — Signups admin page router.
- signups_admin_index — This is the list of the Pending accounts (signups).
- signups_admin_load — Set up the signups admin page.
- signups_admin_manage — This is the confirmation screen for actions.
- signups_display_errors — Display any activation errors.
- single_site_registration_on — Create registration pages when single site registration is turned on.
- user_admin — Display the user's profile.
- user_admin_load — Set up the user's profile admin page.
- user_admin_member_type_metabox — Render the profile type metabox.
- user_admin_spammer_metabox — Render the fallback metabox in case a user has been marked as a spammer.
- user_admin_stats_metabox — Render the Stats metabox to moderate inappropriate images.
- user_admin_status_metabox — Render the Status metabox for user's profile screen.
- user_profile_menu — Create the /user/ admin Profile submenus for all members.
- users_table_add_type_column — Add profile type column to the WordPress admin users list table.
- users_table_filter_by_type — Filter WP Admin users list table to include users of the specified type.
- users_table_output_type_change_select — Display a dropdown to bulk change the profile type of selected user(s).
- users_table_populate_type_cell — Return member's type for display in the WP admin users list table.
- users_table_process_bulk_type_change — Process bulk profile type change submission from the WP admin users list table.
- users_type_change_notice — Display an admin notice upon profile type bulk update.
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.