Changeset 14076
- Timestamp:
- 11/03/2024 10:01:19 PM (5 months ago)
- Location:
- trunk/src/bp-groups
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r14070 r14076 21 21 * @since 1.5.0 22 22 * 23 * @return bool True if set, False if empty.23 * @return bool 24 24 */ 25 25 function bp_groups_has_directory() { 26 26 $bp = buddypress(); 27 27 28 return (bool) !empty( $bp->pages->groups->id );28 return ! empty( $bp->pages->groups->id ); 29 29 } 30 30 … … 45 45 function groups_get_group( $group_id ) { 46 46 /* 47 * Backward compatibil ty.47 * Backward compatibility. 48 48 * Old-style arguments take the form of an array or a query string. 49 49 */ … … 91 91 } 92 92 93 $group = groups_get_group( array( 'group_id' => (int) $group_id ));93 $group = groups_get_group( (int) $group_id ); 94 94 95 95 if ( empty( $group->id ) ) { … … 200 200 // Pass an existing group ID. 201 201 if ( ! empty( $group_id ) ) { 202 $group = groups_get_group( $group_id );203 $name = ! empty( $name ) ? $name : $group->name;204 $slug = ! empty( $slug ) ? $slug : $group->slug;205 $creator_id = ! empty( $creator_id ) ? $creator_id : $group->creator_id;206 $description = ! empty( $description ) ? $description : $group->description;207 $status = ! is_null( $status ) ? $status : $group->status;208 $parent_id = ! is_null( $parent_id ) ? $parent_id : $group->parent_id;202 $group = groups_get_group( $group_id ); 203 $name = ! empty( $name ) ? $name : $group->name; 204 $slug = ! empty( $slug ) ? $slug : $group->slug; 205 $creator_id = ! empty( $creator_id ) ? $creator_id : $group->creator_id; 206 $description = ! empty( $description ) ? $description : $group->description; 207 $status = ! is_null( $status ) ? $status : $group->status; 208 $parent_id = ! is_null( $parent_id ) ? $parent_id : $group->parent_id; 209 209 $enable_forum = ! is_null( $enable_forum ) ? $enable_forum : $group->enable_forum; 210 210 $date_created = ! is_null( $date_created ) ? $date_created : $group->date_created; … … 215 215 } 216 216 217 // Create a new group.217 // Create a new group. 218 218 } else { 219 219 // Instantiate new group object. 220 $group = new BP_Groups_Group ;220 $group = new BP_Groups_Group(); 221 221 222 222 // Check for null values, reset to sensible defaults. 223 $status = ! is_null( $status ) ? $status : 'public';224 $parent_id = ! is_null( $parent_id ) ? $parent_id : 0;223 $status = ! is_null( $status ) ? $status : 'public'; 224 $parent_id = ! is_null( $parent_id ) ? $parent_id : 0; 225 225 $enable_forum = ! is_null( $enable_forum ) ? $enable_forum : 0; 226 226 $date_created = ! is_null( $date_created ) ? $date_created : bp_core_current_time(); … … 259 259 // If this is a new group, set up the creator as the first member and admin. 260 260 if ( empty( $group_id ) ) { 261 $member = new BP_Groups_Member ;261 $member = new BP_Groups_Member(); 262 262 $member->group_id = $group->id; 263 263 $member->user_id = $group->creator_id; … … 536 536 $slug = sanitize_title( $slug ); 537 537 538 if ( 'wp' == substr( $slug, 0, 2 ) ) 538 if ( 'wp' == substr( $slug, 0, 2 ) ) { 539 539 $slug = substr( $slug, 2, strlen( $slug ) - 2 ); 540 541 if ( in_array( $slug, (array) $bp->groups->forbidden_names ) ) 540 } 541 542 if ( in_array( $slug, (array) $bp->groups->forbidden_names ) ) { 542 543 $slug = $slug . '-' . rand(); 544 } 543 545 544 546 if ( BP_Groups_Group::check_slug( $slug ) ) { 545 547 do { 546 548 $slug = $slug . '-' . rand(); 547 } 548 while ( BP_Groups_Group::check_slug( $slug ) ); 549 } while ( BP_Groups_Group::check_slug( $slug ) ); 549 550 } 550 551 … … 682 683 // Check if the user has an outstanding request. If so, delete it. 683 684 if ( groups_check_for_membership_request( $user_id, $group_id ) ) { 684 groups_delete_membership_request( null, $user_id, $group_id );685 groups_delete_membership_request( 0, $user_id, $group_id ); 685 686 } 686 687 … … 737 738 * @param int|string|BP_Groups_Group $group The Group ID, the Group Slug or the Group object. 738 739 * Default: the current group's ID. 739 * @return bool False on failure.740 740 */ 741 741 function groups_update_last_activity( $group = 0 ) { … … 744 744 745 745 if ( empty( $group->id ) ) { 746 return false;746 return; 747 747 } 748 748 … … 868 868 869 869 // Perform the group member query (extends BP_User_Query). 870 $members = new BP_Group_Member_Query( array( 871 'group_id' => $r['group_id'], 872 'per_page' => $r['per_page'], 873 'page' => $r['page'], 874 'group_role' => $r['group_role'], 875 'exclude' => $r['exclude'], 876 'search_terms' => $r['search_terms'], 877 'type' => $r['type'], 878 ) ); 870 $members = new BP_Group_Member_Query( 871 array( 872 'group_id' => $r['group_id'], 873 'per_page' => $r['per_page'], 874 'page' => $r['page'], 875 'group_role' => $r['group_role'], 876 'exclude' => $r['exclude'], 877 'search_terms' => $r['search_terms'], 878 'type' => $r['type'], 879 ) 880 ); 879 881 880 882 // Structure the return value as expected by the template functions. … … 959 961 ); 960 962 961 $groups = BP_Groups_Group::get( array( 962 'type' => $r['type'], 963 'user_id' => $r['user_id'], 964 'include' => $r['include'], 965 'exclude' => $r['exclude'], 966 'slug' => $r['slug'], 967 'parent_id' => $r['parent_id'], 968 'search_terms' => $r['search_terms'], 969 'search_columns' => $r['search_columns'], 970 'group_type' => $r['group_type'], 971 'group_type__in' => $r['group_type__in'], 972 'group_type__not_in' => $r['group_type__not_in'], 973 'meta_query' => $r['meta_query'], 974 'date_query' => $r['date_query'], 975 'show_hidden' => $r['show_hidden'], 976 'status' => $r['status'], 977 'per_page' => $r['per_page'], 978 'page' => $r['page'], 979 'update_meta_cache' => $r['update_meta_cache'], 980 'update_admin_cache' => $r['update_admin_cache'], 981 'order' => $r['order'], 982 'orderby' => $r['orderby'], 983 'fields' => $r['fields'], 984 ) ); 963 $groups = BP_Groups_Group::get( 964 array( 965 'type' => $r['type'], 966 'user_id' => $r['user_id'], 967 'include' => $r['include'], 968 'exclude' => $r['exclude'], 969 'slug' => $r['slug'], 970 'parent_id' => $r['parent_id'], 971 'search_terms' => $r['search_terms'], 972 'search_columns' => $r['search_columns'], 973 'group_type' => $r['group_type'], 974 'group_type__in' => $r['group_type__in'], 975 'group_type__not_in' => $r['group_type__not_in'], 976 'meta_query' => $r['meta_query'], 977 'date_query' => $r['date_query'], 978 'show_hidden' => $r['show_hidden'], 979 'status' => $r['status'], 980 'per_page' => $r['per_page'], 981 'page' => $r['page'], 982 'update_meta_cache' => $r['update_meta_cache'], 983 'update_admin_cache' => $r['update_admin_cache'], 984 'order' => $r['order'], 985 'orderby' => $r['orderby'], 986 'fields' => $r['fields'], 987 ) 988 ); 985 989 986 990 /** … … 1056 1060 * @since 2.6.0 1057 1061 * 1058 * @param int $user_id ID of the user.1059 * @param array $args {1062 * @param int $user_id ID of the user. 1063 * @param array $args { 1060 1064 * Array of optional args. 1061 * @param bool|null 1062 * 1063 * @param bool|null 1064 * 1065 * @param bool|null 1066 * 1067 * @param bool|null 1068 * 1069 * @param bool|null 1070 * 1071 * @param string 1072 * 1073 * @param string 1065 * @param bool|null $is_confirmed Whether to return only confirmed memberships. Pass `null` to disable this 1066 * filter. Default: true. 1067 * @param bool|null $is_banned Whether to return only banned memberships. Pass `null` to disable this filter. 1068 * Default: false. 1069 * @param bool|null $is_admin Whether to return only admin memberships. Pass `null` to disable this filter. 1070 * Default: false. 1071 * @param bool|null $is_mod Whether to return only mod memberships. Pass `null` to disable this filter. 1072 * Default: false. 1073 * @param bool|null $invite_sent Whether to return only memberships with 'invite_sent'. Pass `null` to disable 1074 * this filter. Default: false. 1075 * @param string $orderby Field to order by. Accepts 'id' (membership ID), 'group_id', 'date_modified'. 1076 * Default: 'group_id'. 1077 * @param string $order Sort order. Accepts 'ASC' or 'DESC'. Default: 'ASC'. 1074 1078 * } 1075 1079 * @return array Array of matching group memberships, keyed by group ID. … … 1112 1116 $invitation_ids = array(); 1113 1117 if ( true !== $r['is_confirmed'] || false !== $r['invite_sent'] ) { 1114 $invitation_ids = groups_get_invites( array( 1115 'user_id' => $user_id, 1116 'invite_sent' => 'all', 1117 'type' => 'all', 1118 'fields' => 'ids' 1119 ) ); 1118 $invitation_ids = groups_get_invites( 1119 array( 1120 'user_id' => $user_id, 1121 'invite_sent' => 'all', 1122 'type' => 'all', 1123 'fields' => 'ids', 1124 ) 1125 ); 1120 1126 1121 1127 // Prime the invitations cache. 1122 1128 $uncached_invitation_ids = bp_get_non_cached_ids( $invitation_ids, 'bp_groups_invitations_as_memberships' ); 1123 1129 if ( $uncached_invitation_ids ) { 1124 $uncached_invitations = groups_get_invites( array( 1125 'id' => $uncached_invitation_ids, 1126 'invite_sent' => 'all', 1127 'type' => 'all' 1128 ) ); 1130 $uncached_invitations = groups_get_invites( 1131 array( 1132 'id' => $uncached_invitation_ids, 1133 'invite_sent' => 'all', 1134 'type' => 'all', 1135 ) 1136 ); 1129 1137 foreach ( $uncached_invitations as $uncached_invitation ) { 1130 1138 // Reshape the result as a membership db entry. 1131 $invitation = new StdClass;1139 $invitation = new StdClass(); 1132 1140 $invitation->id = $uncached_invitation->id; 1133 1141 $invitation->group_id = $uncached_invitation->item_id; … … 1244 1252 function groups_total_groups_for_user( $user_id = 0 ) { 1245 1253 1246 if ( empty( $user_id ) ) 1254 if ( empty( $user_id ) ) { 1247 1255 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 1256 } 1248 1257 1249 1258 $count = wp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' ); … … 1330 1339 * @param array $value Array of parts related to the groups avatar upload directory. 1331 1340 */ 1332 return apply_filters( 'groups_avatar_upload_dir', array( 1333 'path' => $path, 1334 'url' => $newurl, 1335 'subdir' => $newsubdir, 1336 'basedir' => $newbdir, 1337 'baseurl' => $newburl, 1338 'error' => false 1339 ) ); 1341 return apply_filters( 1342 'groups_avatar_upload_dir', 1343 array( 1344 'path' => $path, 1345 'url' => $newurl, 1346 'subdir' => $newsubdir, 1347 'basedir' => $newbdir, 1348 'baseurl' => $newburl, 1349 'error' => false, 1350 ) 1351 ); 1340 1352 } 1341 1353 … … 1351 1363 function bp_groups_get_group_roles() { 1352 1364 return array( 1353 'admin' => (object) array(1365 'admin' => (object) array( 1354 1366 'id' => 'admin', 1355 1367 'name' => __( 'Administrator', 'buddypress' ), … … 1360 1372 'is_mod' => false, 1361 1373 ), 1362 'mod' => (object) array(1374 'mod' => (object) array( 1363 1375 'id' => 'mod', 1364 1376 'name' => __( 'Moderator', 'buddypress' ), … … 1401 1413 $is_admin = false; 1402 1414 1403 $user_groups = bp_get_user_groups( $user_id, array( 1404 'is_admin' => true, 1405 ) ); 1415 $user_groups = bp_get_user_groups( 1416 $user_id, 1417 array( 1418 'is_admin' => true, 1419 ) 1420 ); 1406 1421 1407 1422 if ( isset( $user_groups[ $group_id ] ) ) { … … 1424 1439 $is_mod = false; 1425 1440 1426 $user_groups = bp_get_user_groups( $user_id, array( 1427 'is_mod' => true, 1428 ) ); 1441 $user_groups = bp_get_user_groups( 1442 $user_id, 1443 array( 1444 'is_mod' => true, 1445 ) 1446 ); 1429 1447 1430 1448 if ( isset( $user_groups[ $group_id ] ) ) { … … 1447 1465 $is_member = false; 1448 1466 1449 $user_groups = bp_get_user_groups( $user_id, array( 1450 'is_admin' => null, 1451 'is_mod' => null, 1452 ) ); 1467 $user_groups = bp_get_user_groups( 1468 $user_id, 1469 array( 1470 'is_admin' => null, 1471 'is_mod' => null, 1472 ) 1473 ); 1453 1474 1454 1475 if ( isset( $user_groups[ $group_id ] ) ) { … … 1471 1492 $is_banned = false; 1472 1493 1473 $user_groups = bp_get_user_groups( $user_id, array( 1474 'is_confirmed' => null, 1475 'is_banned' => true, 1476 ) ); 1494 $user_groups = bp_get_user_groups( 1495 $user_id, 1496 array( 1497 'is_confirmed' => null, 1498 'is_banned' => true, 1499 ) 1500 ); 1477 1501 1478 1502 if ( isset( $user_groups[ $group_id ] ) ) { … … 1514 1538 } 1515 1539 1516 $args = array(1517 'user_id' 1518 'item_id' 1540 $args = array( 1541 'user_id' => $user_id, 1542 'item_id' => $group_id, 1519 1543 ); 1520 1544 $invites_class = new BP_Groups_Invitation_Manager(); … … 1607 1631 * @return array Array of group IDs. 1608 1632 */ 1609 1633 function groups_get_invited_to_group_ids( $user_id = 0 ) { 1610 1634 if ( empty( $user_id ) ) { 1611 1635 $user_id = bp_loggedin_user_id(); 1612 1636 } 1613 1637 1614 $group_ids = groups_get_invites( array( 1615 'user_id' => $user_id, 1616 'invite_sent' => 'sent', 1617 'fields' => 'item_ids' 1618 ) ); 1638 $group_ids = groups_get_invites( 1639 array( 1640 'user_id' => $user_id, 1641 'invite_sent' => 'sent', 1642 'fields' => 'item_ids', 1643 ) 1644 ); 1619 1645 1620 1646 return array_unique( $group_ids ); … … 1697 1723 1698 1724 $invites_class = new BP_Groups_Invitation_Manager(); 1699 $success = $invites_class->delete( array( 1700 'user_id' => $user_id, 1701 'item_id' => $group_id, 1702 'inviter_id' => $inviter_id, 1703 ) ); 1725 $success = $invites_class->delete( 1726 array( 1727 'user_id' => $user_id, 1728 'item_id' => $group_id, 1729 'inviter_id' => $inviter_id, 1730 ) 1731 ); 1704 1732 1705 1733 if ( $success ) { … … 1733 1761 function groups_accept_invite( $user_id, $group_id ) { 1734 1762 $invites_class = new BP_Groups_Invitation_Manager(); 1735 $args = array(1763 $args = array( 1736 1764 'user_id' => $user_id, 1737 1765 'item_id' => $group_id, … … 1760 1788 1761 1789 $invites_class = new BP_Groups_Invitation_Manager(); 1762 $success = $invites_class->delete( array( 1763 'user_id' => $user_id, 1764 'item_id' => $group_id, 1765 'inviter_id' => $inviter_id, 1766 ) ); 1790 $success = $invites_class->delete( 1791 array( 1792 'user_id' => $user_id, 1793 'item_id' => $group_id, 1794 'inviter_id' => $inviter_id, 1795 ) 1796 ); 1767 1797 1768 1798 /** … … 1799 1829 1800 1830 $invites_class = new BP_Groups_Invitation_Manager(); 1801 $success = $invites_class->delete( array( 1802 'user_id' => $user_id, 1803 'item_id' => $group_id, 1804 'inviter_id' => $inviter_id, 1805 ) ); 1831 $success = $invites_class->delete( 1832 array( 1833 'user_id' => $user_id, 1834 'item_id' => $group_id, 1835 'inviter_id' => $inviter_id, 1836 ) 1837 ); 1806 1838 1807 1839 /** … … 1973 2005 * @return int|bool ID of the first found membership if found, otherwise false. 1974 2006 */ 1975 2007 function groups_check_has_invite_from_user( $user_id, $group_id, $inviter_id = false, $type = 'sent' ) { 1976 2008 if ( empty( $user_id ) || empty( $group_id ) ) { 1977 2009 return false; … … 2337 2369 2338 2370 $invites_class = new BP_Groups_Invitation_Manager(); 2339 $request_id = $invites_class->add_request( $inv_args );2371 $request_id = $invites_class->add_request( $inv_args ); 2340 2372 2341 2373 // If a new request was created, send the emails. … … 2389 2421 2390 2422 $invites_class = new BP_Groups_Invitation_Manager(); 2391 $args = array(2423 $args = array( 2392 2424 'user_id' => $user_id, 2393 2425 'item_id' => $group_id, … … 2413 2445 function groups_reject_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) { 2414 2446 2415 if ( ! empty( $membership_id ) ) {2447 if ( ! empty( $membership_id ) ) { 2416 2448 /* translators: 1: the name of the method. 2: the name of the file. */ 2417 2449 _deprecated_argument( __METHOD__, '5.0.0', sprintf( esc_html__( 'Argument `membership_id` passed to %1$s is deprecated. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 2448 2480 * requested. Provide this value along with $user_id to 2449 2481 * override $membership_id. 2450 * @return false|BP_Groups_Member True on success, false on failure.2482 * @return int|false Number of records deleted. False if the user is not a member of the group. 2451 2483 */ 2452 2484 function groups_delete_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) { 2453 if ( ! empty( $membership_id ) ) {2485 if ( ! empty( $membership_id ) ) { 2454 2486 /* translators: 1: the name of the method. 2: the name of the file. */ 2455 2487 _deprecated_argument( __METHOD__, '5.0.0', sprintf( esc_html__( 'Argument `membership_id` passed to %1$s is deprecated. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 2461 2493 2462 2494 $invites_class = new BP_Groups_Invitation_Manager(); 2463 $success = $invites_class->delete_requests( array( 2464 'user_id' => $user_id, 2465 'item_id' => $group_id 2466 ) ); 2467 2468 return $success; 2495 2496 return $invites_class->delete_requests( 2497 array( 2498 'user_id' => $user_id, 2499 'item_id' => $group_id, 2500 ) 2501 ); 2469 2502 } 2470 2503 … … 2499 2532 } 2500 2533 2501 $args = array(2534 $args = array( 2502 2535 'user_id' => $user_id, 2503 2536 'item_id' => $group_id, … … 2508 2541 } 2509 2542 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2543 /** 2544 * Get an array of group IDs to which a user has requested membership. 2545 * 2546 * @since 5.0.0 2547 * 2548 * @param int $user_id The user ID. 2549 * 2550 * @return array Array of group IDs. 2551 */ 2552 function groups_get_membership_requested_group_ids( $user_id = 0 ) { 2520 2553 if ( ! $user_id ) { 2521 2554 $user_id = bp_loggedin_user_id(); 2522 2555 } 2523 2556 2524 $group_ids = groups_get_requests( array( 2525 'user_id' => $user_id, 2526 'fields' => 'item_ids' 2527 ) ); 2557 $group_ids = groups_get_requests( 2558 array( 2559 'user_id' => $user_id, 2560 'fields' => 'item_ids', 2561 ) 2562 ); 2528 2563 2529 2564 return $group_ids; 2530 2565 } 2531 2566 2532 2533 2534 2535 2536 2537 * @param int $user_id The userID.2538 2539 2540 2541 2567 /** 2568 * Get an array of group IDs to which a user has requested membership. 2569 * 2570 * @since 5.0.0 2571 * 2572 * @param int $group_id The group ID. 2573 * 2574 * @return array Array of group IDs. 2575 */ 2576 function groups_get_membership_requested_user_ids( $group_id = 0 ) { 2542 2577 if ( ! $group_id ) { 2543 2578 $group_id = bp_get_current_group_id(); 2544 2579 } 2545 2580 2546 $requests = groups_get_requests( array( 2547 'item_id' => $group_id, 2548 'fields' => 'user_ids' 2549 ) ); 2581 $requests = groups_get_requests( 2582 array( 2583 'item_id' => $group_id, 2584 'fields' => 'user_ids', 2585 ) 2586 ); 2550 2587 2551 2588 return $requests; … … 2720 2757 do_action( 'groups_remove_data_for_user', $user_id ); 2721 2758 } 2722 add_action( 'wpmu_delete_user', 2759 add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' ); 2723 2760 add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' ); 2724 2761 … … 2749 2786 // Get child groups and set the parent to the deleted parent's parent. 2750 2787 $grandparent_group_id = $group->parent_id; 2751 $child_args = array(2788 $child_args = array( 2752 2789 'parent_id' => $group->id, 2753 2790 'show_hidden' => true, … … 2755 2792 'update_meta_cache' => false, 2756 2793 ); 2757 $children = groups_get_groups( $child_args );2758 $children = $children['groups'];2794 $children = groups_get_groups( $child_args ); 2795 $children = $children['groups']; 2759 2796 2760 2797 foreach ( $children as $cgroup ) { … … 2783 2820 * @return string The unique Group taxonomy slug. 2784 2821 */ 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2822 function bp_get_group_type_tax_name() { 2823 /** 2824 * Filters the slug of the Group type taxonomy. 2825 * 2826 * @since 7.0.0 2827 * 2828 * @param string $value Group type taxonomy slug. 2829 */ 2830 return apply_filters( 'bp_get_group_type_tax_name', 'bp_group_type' ); 2831 } 2795 2832 2796 2833 /** … … 3049 3086 // Make sure the relevant labels have been filled in. 3050 3087 $default_name = isset( $r['labels']['name'] ) ? $r['labels']['name'] : ucfirst( $r['name'] ); 3051 $r['labels'] = array_merge( array( 3052 'name' => $default_name, 3053 'singular_name' => $default_name, 3054 ), $r['labels'] ); 3088 $r['labels'] = array_merge( 3089 array( 3090 'name' => $default_name, 3091 'singular_name' => $default_name, 3092 ), 3093 $r['labels'] 3094 ); 3055 3095 3056 3096 // Directory slug. … … 3060 3100 $directory_slug = $r['has_directory']; 3061 3101 3062 // Otherwise fall back on group type.3102 // Otherwise fall back on group type. 3063 3103 } else { 3064 3104 $directory_slug = $group_type; … … 3348 3388 * @since 2.6.0 3349 3389 * 3350 * @param int 3351 * @param string 3390 * @param int $group_id ID of the user. 3391 * @param string $group_type Group type. 3352 3392 * @return bool|WP_Error $deleted True on success. False or WP_Error on failure. 3353 3393 */ … … 3436 3476 * @since 2.6.0 3437 3477 * 3438 * @param int $group_id ID of the group. 3439 * @return array|null $value See {@see bp_groups_set_group_type()}. 3478 * @param int $group_id ID of the group. 3440 3479 */ 3441 3480 function bp_remove_group_type_on_group_delete( $group_id = 0 ) { … … 3469 3508 } 3470 3509 3471 $memberships = BP_Groups_Member::get_user_memberships( $user->ID, array( 3472 'type' => 'membership', 3473 'page' => $page, 3474 'per_page' => $number, 3475 ) ); 3510 $memberships = BP_Groups_Member::get_user_memberships( 3511 $user->ID, 3512 array( 3513 'type' => 'membership', 3514 'page' => $page, 3515 'per_page' => $number, 3516 ) 3517 ); 3476 3518 3477 3519 foreach ( $memberships as $membership ) { … … 3558 3600 } 3559 3601 3560 $requests = groups_get_requests( array( 3561 'user_id' => $user->ID, 3562 'page' => $page, 3563 'per_page' => $number, 3564 ) ); 3602 $requests = groups_get_requests( 3603 array( 3604 'user_id' => $user->ID, 3605 'page' => $page, 3606 'per_page' => $number, 3607 ) 3608 ); 3565 3609 3566 3610 foreach ( $requests as $request ) { … … 3624 3668 } 3625 3669 3626 $invitations = groups_get_invites( array( 3627 'inviter_id' => $user->ID, 3628 'page' => $page, 3629 'per_page' => $number, 3630 ) ); 3670 $invitations = groups_get_invites( 3671 array( 3672 'inviter_id' => $user->ID, 3673 'page' => $page, 3674 'per_page' => $number, 3675 ) 3676 ); 3631 3677 3632 3678 foreach ( $invitations as $invitation ) { … … 3694 3740 } 3695 3741 3696 $invitations = groups_get_invites( array( 3697 'user_id' => $user->ID, 3698 'page' => $page, 3699 'per_page' => $number, 3700 ) ); 3742 $invitations = groups_get_invites( 3743 array( 3744 'user_id' => $user->ID, 3745 'page' => $page, 3746 'per_page' => $number, 3747 ) 3748 ); 3701 3749 3702 3750 foreach ( $invitations as $invitation ) { … … 3756 3804 3757 3805 $processed = array(); 3758 $values = array();3806 $values = array(); 3759 3807 foreach ( $records as $record ) { 3760 $values[] = $wpdb->prepare(3761 "(%d, %d, %s, %s, %d, %d, %s, %s, %s, %d, %d)",3808 $values[] = $wpdb->prepare( 3809 '(%d, %d, %s, %s, %d, %d, %s, %s, %s, %d, %d)', 3762 3810 (int) $record->user_id, 3763 3811 (int) $record->inviter_id, … … 3776 3824 3777 3825 $table_name = BP_Invitation_Manager::get_table_name(); 3778 $query = "INSERT INTO {$table_name} (user_id, inviter_id, invitee_email, class, item_id, secondary_item_id, type, content, date_modified, invite_sent, accepted) VALUES ";3779 $query .= implode(', ', $values );3780 $query .= ';';3826 $query = "INSERT INTO {$table_name} (user_id, inviter_id, invitee_email, class, item_id, secondary_item_id, type, content, date_modified, invite_sent, accepted) VALUES "; 3827 $query .= implode( ', ', $values ); 3828 $query .= ';'; 3781 3829 $wpdb->query( $query ); 3782 3830 … … 3828 3876 3829 3877 foreach ( array_keys( $registered_group_extensions ) as $group_extension_class ) { 3830 $extension = new $group_extension_class ;3878 $extension = new $group_extension_class(); 3831 3879 3832 3880 add_action( 'bp_actions', array( $extension, '_register' ), 8 ); … … 3861 3909 * 3862 3910 * @param bool $defer True to defer, false otherwise. 3863 * @param int $group_id The group's ID.3911 * @param int $group_id The group's ID. 3864 3912 */ 3865 3913 function bp_groups_defer_group_members_count( $defer = true, $group_id = 0 ) { … … 3874 3922 } 3875 3923 3876 if 3924 if ( $group_id ) { 3877 3925 bp_groups_update_group_members_count( 0, (int) $group_id ); 3878 3926 } … … 4160 4208 * @since 12.0.0 4161 4209 * 4162 * @param array $chunks An array of BP URL default slugs.4210 * @param array $chunks An array of BP URL default slugs. 4163 4211 * @param string $context Whether to get chunks for the 'read', 'create' or 'manage' contexts. 4164 4212 * @return array An associative array containing group's customized path chunks. … … 4198 4246 if ( is_numeric( $chunk ) ) { 4199 4247 $path_chunks[ $key_action_variables ][] = $chunk; 4200 } else { 4201 if ( isset( $group_screens[ $chunk ]['rewrite_id'] ) ) { 4248 } elseif ( isset( $group_screens[ $chunk ]['rewrite_id'] ) ) { 4202 4249 $item_action_variable_rewrite_id = $group_screens[ $chunk ]['rewrite_id']; 4203 4250 $path_chunks[ $key_action_variables ][] = bp_rewrites_get_slug( 'groups', $item_action_variable_rewrite_id, $chunk ); 4204 } else { 4205 $path_chunks[ $key_action_variables ][] = $chunk; 4206 } 4251 } else { 4252 $path_chunks[ $key_action_variables ][] = $chunk; 4207 4253 } 4208 4254 } -
trunk/src/bp-groups/classes/class-bp-group-extension.php
r13878 r14076 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 if ( ! class_exists( 'BP_Group_Extension', false ) ) : 13 if ( class_exists( 'BP_Group_Extension', false ) ) { 14 return; 15 } 16 14 17 /** 15 18 * API for creating group extensions without having to hardcode the content into … … 767 770 768 771 foreach ( $screens as $context => &$screen ) { 769 $screen['enabled'] 770 $screen['name'] 771 $screen['slug'] 772 773 $screen['screen_callback'] = $this->get_screen_callback( $context, 'screen' 772 $screen['enabled'] = true; 773 $screen['name'] = $this->name; 774 $screen['slug'] = $this->slug; 775 776 $screen['screen_callback'] = $this->get_screen_callback( $context, 'screen' ); 774 777 $screen['screen_save_callback'] = $this->get_screen_callback( $context, 'screen_save' ); 775 778 } … … 887 890 $this->params['show_tab'] = 'anyone'; 888 891 } 889 890 892 } else { 891 893 /* … … 927 929 928 930 switch ( $access_condition ) { 929 case 'admin' 931 case 'admin': 930 932 $meets_condition = groups_is_user_admin( bp_loggedin_user_id(), $this->group_id ); 931 933 break; 932 934 933 case 'mod' 935 case 'mod': 934 936 $meets_condition = groups_is_user_mod( bp_loggedin_user_id(), $this->group_id ); 935 937 break; 936 938 937 case 'member' 939 case 'member': 938 940 $meets_condition = groups_is_user_member( bp_loggedin_user_id(), $this->group_id ); 939 941 break; 940 942 941 case 'loggedin' 943 case 'loggedin': 942 944 $meets_condition = is_user_logged_in(); 943 945 break; 944 946 945 case 'noone' 947 case 'noone': 946 948 $meets_condition = false; 947 949 break; 948 950 949 case 'anyone' 950 default 951 case 'anyone': 952 default: 951 953 $meets_condition = true; 952 954 break; … … 1035 1037 // When we are viewing the extension display page, set the title and options title. 1036 1038 if ( bp_is_current_action( $this->slug ) ) { 1037 add_filter( 'bp_group_user_has_access', 1039 add_filter( 'bp_group_user_has_access', array( $this, 'group_access_protection' ), 10, 2 ); 1038 1040 1039 1041 $extension_name = $this->name; 1040 1042 add_action( 1041 1043 'bp_template_content_header', 1042 function () use ( $extension_name ) {1044 function () use ( $extension_name ) { 1043 1045 echo esc_attr( $extension_name ); 1044 1046 } … … 1046 1048 add_action( 1047 1049 'bp_template_title', 1048 function () use ( $extension_name ) {1050 function () use ( $extension_name ) { 1049 1051 echo esc_attr( $extension_name ); 1050 1052 } … … 1292 1294 $this->edit_screen_template = '/groups/single/home'; 1293 1295 } else { 1294 add_action( 'bp_template_content_header', function () { 1295 echo '<ul class="content-header-nav">'; 1296 bp_group_admin_tabs(); 1297 echo '</ul>'; 1298 } ); 1296 add_action( 1297 'bp_template_content_header', 1298 function () { 1299 echo '<ul class="content-header-nav">'; 1300 bp_group_admin_tabs(); 1301 echo '</ul>'; 1302 } 1303 ); 1299 1304 add_action( 'bp_template_content', array( &$this, 'call_edit_screen' ) ); 1300 1305 $this->edit_screen_template = '/groups/single/plugins'; … … 1380 1385 * @param string $value URL to redirect to. 1381 1386 */ 1382 $redirect_to = apply_filters( 'bp_group_extension_edit_screen_save_redirect', bp_get_requested_url( 1387 $redirect_to = apply_filters( 'bp_group_extension_edit_screen_save_redirect', bp_get_requested_url() ); 1383 1388 1384 1389 bp_core_redirect( $redirect_to ); … … 1390 1395 * Load the template that houses the Edit screen. 1391 1396 * 1392 * Separated out into a callback so that it can run after all other 1397 * Separated out into a callback so that it can run after all others 1393 1398 * Group Extensions have had a chance to register their navigation, to 1394 1399 * avoid missing tabs. … … 1401 1406 */ 1402 1407 public function call_edit_screen_template_loader() { 1403 bp_core_load_template( $this->edit_screen_template );1408 bp_core_load_template( (array) $this->edit_screen_template ); 1404 1409 } 1405 1410 … … 1773 1778 1774 1779 switch ( $key ) { 1775 case 'enable_create_step' 1780 case 'enable_create_step': 1776 1781 $this->screens['create']['enabled'] = $value; 1777 1782 break; 1778 1783 1779 case 'enable_edit_item' 1784 case 'enable_edit_item': 1780 1785 $this->screens['edit']['enabled'] = $value; 1781 1786 break; 1782 1787 1783 case 'enable_admin_item' 1788 case 'enable_admin_item': 1784 1789 $this->screens['admin']['enabled'] = $value; 1785 1790 break; 1786 1791 1787 case 'create_step_position' 1792 case 'create_step_position': 1788 1793 $this->screens['create']['position'] = $value; 1789 1794 break; 1790 1795 1791 1796 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'. 1792 case 'admin_name' 1797 case 'admin_name': 1793 1798 $this->screens['edit']['name'] = $value; 1794 1799 break; 1795 1800 1796 case 'admin_slug' 1801 case 'admin_slug': 1797 1802 $this->screens['edit']['slug'] = $value; 1798 1803 break; 1799 1804 1800 case 'create_name' 1805 case 'create_name': 1801 1806 $this->screens['create']['name'] = $value; 1802 1807 break; 1803 1808 1804 case 'create_slug' 1809 case 'create_slug': 1805 1810 $this->screens['create']['slug'] = $value; 1806 1811 break; 1807 1812 1808 case 'admin_metabox_context' 1813 case 'admin_metabox_context': 1809 1814 $this->screens['admin']['metabox_context'] = $value; 1810 1815 break; 1811 1816 1812 case 'admin_metabox_priority' 1817 case 'admin_metabox_priority': 1813 1818 $this->screens['admin']['metabox_priority'] = $value; 1814 1819 break; 1815 1820 1816 default 1821 default: 1817 1822 $this->data[ $key ] = $value; 1818 1823 break; … … 1887 1892 1888 1893 switch ( $property ) { 1889 case 'enable_create_step' 1894 case 'enable_create_step': 1890 1895 $lpc['screens']['create']['enabled'] = (bool) $value; 1891 1896 break; 1892 1897 1893 case 'enable_edit_item' 1898 case 'enable_edit_item': 1894 1899 $lpc['screens']['edit']['enabled'] = (bool) $value; 1895 1900 break; 1896 1901 1897 case 'enable_admin_item' 1902 case 'enable_admin_item': 1898 1903 $lpc['screens']['admin']['enabled'] = (bool) $value; 1899 1904 break; 1900 1905 1901 case 'create_step_position' 1906 case 'create_step_position': 1902 1907 $lpc['screens']['create']['position'] = $value; 1903 1908 break; 1904 1909 1905 1910 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'. 1906 case 'admin_name' 1911 case 'admin_name': 1907 1912 $lpc['screens']['edit']['name'] = $value; 1908 1913 break; 1909 1914 1910 case 'admin_slug' 1915 case 'admin_slug': 1911 1916 $lpc['screens']['edit']['slug'] = $value; 1912 1917 break; 1913 1918 1914 case 'create_name' 1919 case 'create_name': 1915 1920 $lpc['screens']['create']['name'] = $value; 1916 1921 break; 1917 1922 1918 case 'create_slug' 1923 case 'create_slug': 1919 1924 $lpc['screens']['create']['slug'] = $value; 1920 1925 break; 1921 1926 1922 case 'admin_metabox_context' 1927 case 'admin_metabox_context': 1923 1928 $lpc['screens']['admin']['metabox_context'] = $value; 1924 1929 break; 1925 1930 1926 case 'admin_metabox_priority' 1931 case 'admin_metabox_priority': 1927 1932 $lpc['screens']['admin']['metabox_priority'] = $value; 1928 1933 break; 1929 1934 1930 default 1935 default: 1931 1936 $lpc[ $property ] = $value; 1932 1937 break; … … 1960 1965 foreach ( $properties as $property ) { 1961 1966 switch ( $property ) { 1962 case 'enable_create_step' 1967 case 'enable_create_step': 1963 1968 $lp['enable_create_step'] = $params['screens']['create']['enabled']; 1964 1969 break; 1965 1970 1966 case 'enable_edit_item' 1971 case 'enable_edit_item': 1967 1972 $lp['enable_edit_item'] = $params['screens']['edit']['enabled']; 1968 1973 break; 1969 1974 1970 case 'enable_admin_item' 1975 case 'enable_admin_item': 1971 1976 $lp['enable_admin_item'] = $params['screens']['admin']['enabled']; 1972 1977 break; 1973 1978 1974 case 'create_step_position' 1979 case 'create_step_position': 1975 1980 $lp['create_step_position'] = $params['screens']['create']['position']; 1976 1981 break; 1977 1982 1978 1983 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'. 1979 case 'admin_name' 1984 case 'admin_name': 1980 1985 $lp['admin_name'] = $params['screens']['edit']['name']; 1981 1986 break; 1982 1987 1983 case 'admin_slug' 1988 case 'admin_slug': 1984 1989 $lp['admin_slug'] = $params['screens']['edit']['slug']; 1985 1990 break; 1986 1991 1987 case 'create_name' 1992 case 'create_name': 1988 1993 $lp['create_name'] = $params['screens']['create']['name']; 1989 1994 break; 1990 1995 1991 case 'create_slug' 1996 case 'create_slug': 1992 1997 $lp['create_slug'] = $params['screens']['create']['slug']; 1993 1998 break; 1994 1999 1995 case 'admin_metabox_context' 2000 case 'admin_metabox_context': 1996 2001 $lp['admin_metabox_context'] = $params['screens']['admin']['metabox_context']; 1997 2002 break; 1998 2003 1999 case 'admin_metabox_priority' 2004 case 'admin_metabox_priority': 2000 2005 $lp['admin_metabox_priority'] = $params['screens']['admin']['metabox_priority']; 2001 2006 break; 2002 2007 2003 default 2008 default: 2004 2009 // All other items get moved over. 2005 2010 $lp[ $property ] = $params[ $property ]; … … 2007 2012 // Also reapply to the object, for backpat. 2008 2013 $this->{$property} = $params[ $property ]; 2009 2010 2014 break; 2011 2015 } … … 2013 2017 } 2014 2018 } 2015 endif; // End class_exists check. -
trunk/src/bp-groups/classes/class-bp-group-member-query.php
r13372 r14076 46 46 * 47 47 * @since 1.8.1 48 * @var null|array Null if not yet defined, otherwise an array of int s.48 * @var null|array Null if not yet defined, otherwise an array of integers. 49 49 */ 50 50 protected $group_member_ids; … … 101 101 public function do_wp_user_query() { 102 102 if ( ! $this->query_vars_raw['count'] ) { 103 returnparent::do_wp_user_query();103 parent::do_wp_user_query(); 104 104 } 105 105 … … 109 109 * @since 10.3.0 110 110 * 111 * @param array $ valueArray of arguments for the user query.111 * @param array $arguments Array of arguments for the user query. 112 112 * @param BP_User_Query $user_query Current BP_User_Query instance. 113 113 */ … … 122 122 // Overrides 123 123 'blog_id' => 0, // BP does not require blog roles. 124 'count_total' => false // We already have a count.124 'count_total' => false, // We already have a count. 125 125 126 126 ), … … 145 145 * @since 1.8.0 146 146 * 147 * @param array $include Existing group IDs in the $includeparameter,148 * as calculated in BP_User_Query.147 * @param array $include_ids Existing group IDs in the `$include_ids` parameter, 148 * as calculated in BP_User_Query. 149 149 * @return array 150 150 */ 151 public function get_include_ids( $include = array() ) {151 public function get_include_ids( $include_ids = array() ) { 152 152 // The following args are specific to group member queries, and 153 153 // are not present in the query_vars of a normal BP_User_Query. … … 176 176 } 177 177 178 if ( ! empty( $include ) ) {179 $group_member_ids = array_intersect( $include , $group_member_ids );178 if ( ! empty( $include_ids ) ) { 179 $group_member_ids = array_intersect( $include_ids, $group_member_ids ); 180 180 } 181 181 … … 187 187 * 188 188 * @since 1.8.0 189 * 190 * @global wpdb $wpdb WordPress database abstraction object. 189 191 * 190 192 * @return array $ids User IDs of relevant group member ids. … … 208 210 209 211 // Group id. 210 $group_ids = wp_parse_id_list( $this->query_vars['group_id'] );211 $group_ids = implode( ',', $group_ids );212 $group_ids = wp_parse_id_list( $this->query_vars['group_id'] ); 213 $group_ids = implode( ',', $group_ids ); 212 214 $sql['where'][] = "group_id IN ({$group_ids})"; 213 215 214 216 // If is_confirmed. 215 $is_confirmed = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0;216 $sql['where'][] = $wpdb->prepare( "is_confirmed = %d", $is_confirmed );217 $is_confirmed = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0; 218 $sql['where'][] = $wpdb->prepare( 'is_confirmed = %d', $is_confirmed ); 217 219 218 220 // If invite_sent. 219 221 if ( ! is_null( $this->query_vars['invite_sent'] ) ) { 220 $invite_sent = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0;221 $sql['where'][] = $wpdb->prepare( "invite_sent = %d", $invite_sent );222 $invite_sent = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0; 223 $sql['where'][] = $wpdb->prepare( 'invite_sent = %d', $invite_sent ); 222 224 } 223 225 … … 228 230 // Empty: inviter_id = 0. (pass false, 0, or empty array). 229 231 if ( empty( $inviter_id ) ) { 230 $sql['where'][] = "inviter_id = 0";231 232 // The string 'any' matches any non-zero value (inviter_id != 0).232 $sql['where'][] = 'inviter_id = 0'; 233 234 // The string 'any' matches any non-zero value (inviter_id != 0). 233 235 } elseif ( 'any' === $inviter_id ) { 234 $sql['where'][] = "inviter_id != 0";235 236 // Assume that a list of inviter IDs has been passed.236 $sql['where'][] = 'inviter_id != 0'; 237 238 // Assume that a list of inviter IDs has been passed. 237 239 } else { 238 240 // Parse and sanitize. … … 240 242 if ( ! empty( $inviter_ids ) ) { 241 243 $inviter_ids_sql = implode( ',', $inviter_ids ); 242 $sql['where'][] = "inviter_id IN ({$inviter_ids_sql})";244 $sql['where'][] = "inviter_id IN ({$inviter_ids_sql})"; 243 245 } 244 246 } … … 248 250 // is_admin = 1, mods have is_mod = 1, banned have is_banned = 249 251 // 1, and members have all three set to 0. 250 $roles = ! empty( $this->query_vars['group_role'] ) ? $this->query_vars['group_role'] : array();252 $roles = ! empty( $this->query_vars['group_role'] ) ? $this->query_vars['group_role'] : array(); 251 253 if ( is_string( $roles ) ) { 252 254 $roles = explode( ',', $roles ); … … 277 279 } 278 280 279 // When querying for a set of roles *not* containing 'member',280 // simply construct a list of is_* = 1 clauses.281 // When querying for a set of roles *not* containing 'member', 282 // simply construct a list of is_* = 1 clauses. 281 283 } else { 282 284 $role_columns = array(); … … 300 302 // 'first_joined', the order will be overridden in 301 303 // BP_Group_Member_Query::set_orderby(). 302 $sql['orderby'] = "ORDER BY date_modified";304 $sql['orderby'] = 'ORDER BY date_modified'; 303 305 $sql['order'] = 'first_joined' === $this->query_vars['type'] ? 'ASC' : 'DESC'; 304 306 … … 327 329 $invite_args['type'] = 'request'; 328 330 329 /*330 * The string 'any' matches any non-zero value (inviter_id != 0).331 * These are invitations, not requests.332 */331 /* 332 * The string 'any' matches any non-zero value (inviter_id != 0). 333 * These are invitations, not requests. 334 */ 333 335 } elseif ( 'any' === $inviter_id ) { 334 336 $invite_args['type'] = 'invite'; 335 337 336 // Assume that a list of inviter IDs has been passed.338 // Assume that a list of inviter IDs has been passed. 337 339 } else { 338 340 $invite_args['type'] = 'invite'; … … 407 409 408 410 // The first param in the FIELD() clause is the sort column id. 409 $gm_ids = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) );411 $gm_ids = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) ); 410 412 $gm_ids_sql = implode( ',', $gm_ids ); 411 413 412 $query->uid_clauses['orderby'] = "ORDER BY FIELD(" . $gm_ids_sql . ")";414 $query->uid_clauses['orderby'] = 'ORDER BY FIELD(' . $gm_ids_sql . ')'; 413 415 } 414 416 … … 422 424 * 423 425 * Additional data fetched: 424 * 425 * 426 * - is_banned 427 * - date_modified 426 428 * 427 429 * @since 1.8.0 430 * 431 * @global wpdb $wpdb WordPress database abstraction object. 428 432 * 429 433 * @param BP_User_Query $query BP_User_Query object. Because we're 430 434 * filtering the current object, we use 431 * $this inside ofthe method instead.435 * $this inside the method instead. 432 436 * @param string $user_ids_sql Sanitized, comma-separated string of 433 437 * the user ids returned by the main query. … … 457 461 458 462 // Add accurate invitation info from the invitations table. 459 $invites = groups_get_invites( array( 460 'user_id' => $user_ids_sql, 461 'item_id' => $this->query_vars['group_id'], 462 'type' => 'all', 463 ) ); 463 $invites = groups_get_invites( 464 array( 465 'user_id' => $user_ids_sql, 466 'item_id' => $this->query_vars['group_id'], 467 'type' => 'all', 468 ) 469 ); 464 470 foreach ( $invites as $invite ) { 465 471 if ( isset( $this->results[ $invite->user_id ] ) ) { … … 504 510 * @since 2.1.0 505 511 * 512 * @global wpdb $wpdb WordPress database abstraction object. 513 * 506 514 * @param BP_User_Query $query BP_User_Query object. 507 515 * @param array $gm_ids array of group member ids. … … 532 540 'user_id IN (' . implode( ',', wp_parse_id_list( $gm_ids ) ) . ')', 533 541 'item_id = ' . absint( $query->query_vars['group_id'] ), 534 $wpdb->prepare( "component = %s", buddypress()->groups->id ),542 $wpdb->prepare( 'component = %s', buddypress()->groups->id ), 535 543 ); 536 544 … … 552 560 public function populate_extras() { 553 561 if ( ! $this->query_vars_raw['count'] ) { 554 returnparent::populate_extras();562 parent::populate_extras(); 555 563 } 556 564 -
trunk/src/bp-groups/classes/class-bp-groups-member.php
r13890 r14076 148 148 149 149 // User and group are not empty, and ID is. 150 if ( ! empty( $user_id ) && !empty( $group_id ) && empty( $id ) ) {150 if ( ! empty( $user_id ) && ! empty( $group_id ) && empty( $id ) ) { 151 151 $this->user_id = $user_id; 152 152 $this->group_id = $group_id; 153 153 154 if ( ! empty( $populate ) ) {154 if ( ! empty( $populate ) ) { 155 155 $this->populate(); 156 156 } … … 158 158 159 159 // ID is not empty. 160 if ( ! empty( $id ) ) {160 if ( ! empty( $id ) ) { 161 161 $this->id = $id; 162 162 163 if ( ! empty( $populate ) ) {163 if ( ! empty( $populate ) ) { 164 164 $this->populate(); 165 165 } … … 171 171 * 172 172 * @since 1.6.0 173 * 174 * @global wpdb $wpdb WordPress database abstraction object. 173 175 */ 174 176 public function populate() { … … 177 179 $bp = buddypress(); 178 180 179 if ( $this->user_id && $this->group_id && ! $this->id )181 if ( $this->user_id && $this->group_id && ! $this->id ) { 180 182 $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id ); 181 182 if ( !empty( $this->id ) ) 183 } 184 185 if ( ! empty( $this->id ) ) { 183 186 $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE id = %d", $this->id ); 184 185 $member = $wpdb->get_row($sql); 186 187 if ( !empty( $member ) ) { 187 } 188 189 $member = $wpdb->get_row( $sql ); 190 191 if ( ! empty( $member ) ) { 188 192 $this->id = (int) $member->id; 189 193 $this->group_id = (int) $member->group_id; … … 210 214 */ 211 215 public function __get( $key ) { 212 switch ( $key) {213 case 'user' :214 216 if ( $key == 'user' ) { 217 // @todo fix this. 218 return $this->get_user_object( $this->user_id ); 215 219 } 216 220 } … … 226 230 public function __isset( $key ) { 227 231 switch ( $key ) { 228 case 'user' 232 case 'user': 229 233 return true; 230 234 231 default 235 default: 232 236 return isset( $this->{$key} ); 233 237 } … … 256 260 * @since 1.6.0 257 261 * 262 * @global wpdb $wpdb WordPress database abstraction object. 263 * 258 264 * @return bool 259 265 */ … … 263 269 $bp = buddypress(); 264 270 265 $this->user_id = apply_filters( 'groups_member_user_id_before_save', $this->user_id,$this->id );266 $this->group_id = apply_filters( 'groups_member_group_id_before_save', $this->group_id,$this->id );267 $this->inviter_id = apply_filters( 'groups_member_inviter_id_before_save', $this->inviter_id,$this->id );268 $this->is_admin = apply_filters( 'groups_member_is_admin_before_save', $this->is_admin,$this->id );269 $this->is_mod = apply_filters( 'groups_member_is_mod_before_save', $this->is_mod,$this->id );270 $this->is_banned = apply_filters( 'groups_member_is_banned_before_save', $this->is_banned,$this->id );271 $this->user_title = apply_filters( 'groups_member_user_title_before_save', $this->user_title,$this->id );271 $this->user_id = apply_filters( 'groups_member_user_id_before_save', $this->user_id, $this->id ); 272 $this->group_id = apply_filters( 'groups_member_group_id_before_save', $this->group_id, $this->id ); 273 $this->inviter_id = apply_filters( 'groups_member_inviter_id_before_save', $this->inviter_id, $this->id ); 274 $this->is_admin = apply_filters( 'groups_member_is_admin_before_save', $this->is_admin, $this->id ); 275 $this->is_mod = apply_filters( 'groups_member_is_mod_before_save', $this->is_mod, $this->id ); 276 $this->is_banned = apply_filters( 'groups_member_is_banned_before_save', $this->is_banned, $this->id ); 277 $this->user_title = apply_filters( 'groups_member_user_title_before_save', $this->user_title, $this->id ); 272 278 $this->date_modified = apply_filters( 'groups_member_date_modified_before_save', $this->date_modified, $this->id ); 273 $this->is_confirmed = apply_filters( 'groups_member_is_confirmed_before_save', $this->is_confirmed,$this->id );274 $this->comments = apply_filters( 'groups_member_comments_before_save', $this->comments,$this->id );275 $this->invite_sent = apply_filters( 'groups_member_invite_sent_before_save', $this->invite_sent,$this->id );279 $this->is_confirmed = apply_filters( 'groups_member_is_confirmed_before_save', $this->is_confirmed, $this->id ); 280 $this->comments = apply_filters( 'groups_member_comments_before_save', $this->comments, $this->id ); 281 $this->invite_sent = apply_filters( 'groups_member_invite_sent_before_save', $this->invite_sent, $this->id ); 276 282 277 283 /** … … 291 297 } 292 298 293 if ( ! empty( $this->id ) ) {299 if ( ! empty( $this->id ) ) { 294 300 $sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id ); 295 301 } else { … … 302 308 } 303 309 304 if ( ! $wpdb->query( $sql ) )310 if ( ! $wpdb->query( $sql ) ) { 305 311 return false; 312 } 306 313 307 314 $this->id = $wpdb->insert_id; … … 371 378 */ 372 379 public function ban() { 373 if ( ! empty( $this->is_admin ) )380 if ( ! empty( $this->is_admin ) ) { 374 381 return false; 375 376 $this->is_mod = 0; 382 } 383 384 $this->is_mod = 0; 377 385 $this->is_banned = 1; 378 386 … … 388 396 */ 389 397 public function unban() { 390 if ( ! empty( $this->is_admin ) )398 if ( ! empty( $this->is_admin ) ) { 391 399 return false; 400 } 392 401 393 402 $this->is_banned = 0; … … 413 422 */ 414 423 public function accept_request() { 415 $this->is_confirmed = 1;424 $this->is_confirmed = 1; 416 425 $this->date_modified = bp_core_current_time(); 417 426 } … … 421 430 * 422 431 * @since 1.6.0 432 * 433 * @global wpdb $wpdb WordPress database abstraction object. 423 434 * 424 435 * @return bool … … 439 450 $sql = $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id ); 440 451 441 if ( ! $result = $wpdb->query( $sql ) )452 if ( ! $result = $wpdb->query( $sql ) ) { 442 453 return false; 454 } 443 455 444 456 // Update the user's group count. … … 473 485 * Refresh the `total_member_count` for a group. 474 486 * 475 * The request skip the current cache so that we always grab the la stest total count.487 * The request skip the current cache so that we always grab the latest total count. 476 488 * 477 489 * @since 1.8.0 … … 488 500 * 489 501 * @since 1.6.0 502 * 503 * @global wpdb $wpdb WordPress database abstraction object. 490 504 * 491 505 * @param int $user_id ID of the user. … … 529 543 * 530 544 * @since 1.6.0 545 * 546 * @global wpdb $wpdb WordPress database abstraction object. 531 547 * 532 548 * @param int $user_id ID of the user. … … 544 560 545 561 $pag_sql = ''; 546 if ( !empty( $limit ) && !empty( $page ) ) 547 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 562 if ( ! empty( $limit ) && ! empty( $page ) ) { 563 $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) ); 564 } 548 565 549 566 $bp = buddypress(); … … 551 568 // If the user is logged in and viewing their own groups, we can show hidden and private groups. 552 569 if ( $user_id != bp_loggedin_user_id() ) { 553 $group_sql = $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0{$pag_sql}", $user_id );570 $group_sql = $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0{$pag_sql}", $user_id ); 554 571 $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) ); 555 572 } else { 556 $group_sql = $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0{$pag_sql}", $user_id );573 $group_sql = $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0{$pag_sql}", $user_id ); 557 574 $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT group_id) FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id ) ); 558 575 } … … 560 577 $groups = $wpdb->get_col( $group_sql ); 561 578 562 return array( 'groups' => $groups, 'total' => (int) $total_groups ); 579 return array( 580 'groups' => $groups, 581 'total' => (int) $total_groups, 582 ); 563 583 } 564 584 … … 567 587 * 568 588 * @since 1.6.0 589 * 590 * @global wpdb $wpdb WordPress database abstraction object. 569 591 * 570 592 * @param int $user_id ID of the user. … … 583 605 global $wpdb; 584 606 585 $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = ''; 586 607 $pag_sql = $hidden_sql = $filter_sql = ''; 587 608 $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id ); 588 609 589 if ( !empty( $limit ) && !empty( $page ) ) 590 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 591 592 if ( !empty( $filter ) ) { 610 if ( ! empty( $limit ) && ! empty( $page ) ) { 611 $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) ); 612 } 613 614 if ( ! empty( $filter ) ) { 593 615 $search_terms_like = '%' . bp_esc_like( $filter ) . '%'; 594 $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );595 } 596 597 if ( $user_id != bp_loggedin_user_id() ) 616 $filter_sql = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like ); 617 } 618 619 if ( $user_id != bp_loggedin_user_id() ) { 598 620 $hidden_sql = " AND g.status != 'hidden'"; 621 } 599 622 600 623 $bp = buddypress(); … … 603 626 $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_banned = 0 AND m.is_confirmed = 1 ORDER BY m.date_modified DESC" ); 604 627 605 return array( 'groups' => $paged_groups, 'total' => $total_groups ); 628 return array( 629 'groups' => $paged_groups, 630 'total' => $total_groups, 631 ); 606 632 } 607 633 … … 610 636 * 611 637 * @since 1.6.0 638 * 639 * @global wpdb $wpdb WordPress database abstraction object. 612 640 * 613 641 * @param int $user_id ID of the user. … … 626 654 global $wpdb; 627 655 628 $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = ''; 629 656 $pag_sql = $hidden_sql = $filter_sql = ''; 630 657 $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id ); 631 658 632 if ( !empty( $limit ) && !empty( $page ) ) 633 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 634 635 if ( !empty( $filter ) ) { 659 if ( ! empty( $limit ) && ! empty( $page ) ) { 660 $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) ); 661 } 662 663 if ( ! empty( $filter ) ) { 636 664 $search_terms_like = '%' . bp_esc_like( $filter ) . '%'; 637 $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );638 } 639 640 if ( $user_id != bp_loggedin_user_id() ) 665 $filter_sql = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like ); 666 } 667 668 if ( $user_id != bp_loggedin_user_id() ) { 641 669 $hidden_sql = " AND g.status != 'hidden'"; 670 } 642 671 643 672 $bp = buddypress(); … … 646 675 $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY date_modified ASC" ); 647 676 648 return array( 'groups' => $paged_groups, 'total' => $total_groups ); 677 return array( 678 'groups' => $paged_groups, 679 'total' => $total_groups, 680 ); 649 681 } 650 682 … … 653 685 * 654 686 * @since 1.6.0 687 * 688 * @global wpdb $wpdb WordPress database abstraction object. 655 689 * 656 690 * @param int $user_id ID of the user. … … 673 707 $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id ); 674 708 675 if ( !empty( $limit ) && !empty( $page ) ) 676 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 677 678 if ( !empty( $filter ) ) { 709 if ( ! empty( $limit ) && ! empty( $page ) ) { 710 $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) ); 711 } 712 713 if ( ! empty( $filter ) ) { 679 714 $search_terms_like = '%' . bp_esc_like( $filter ) . '%'; 680 $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );681 } 682 683 if ( $user_id != bp_loggedin_user_id() ) 715 $filter_sql = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like ); 716 } 717 718 if ( $user_id != bp_loggedin_user_id() ) { 684 719 $hidden_sql = " AND g.status != 'hidden'"; 720 } 685 721 686 722 $bp = buddypress(); … … 689 725 $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC" ); 690 726 691 return array( 'groups' => $paged_groups, 'total' => $total_groups ); 727 return array( 728 'groups' => $paged_groups, 729 'total' => $total_groups, 730 ); 692 731 } 693 732 … … 696 735 * 697 736 * @since 2.4.0 737 * 738 * @global wpdb $wpdb WordPress database abstraction object. 698 739 * 699 740 * @param int $user_id ID of the user. … … 718 759 719 760 if ( $limit && $page ) { 720 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit ), intval( $limit ) );761 $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) ); 721 762 } 722 763 723 764 if ( $filter ) { 724 765 $search_terms_like = '%' . bp_esc_like( $filter ) . '%'; 725 $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );766 $filter_sql = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like ); 726 767 } 727 768 … … 733 774 $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_banned = 1 ORDER BY date_modified ASC" ); 734 775 735 return array( 'groups' => $paged_groups, 'total' => $total_groups ); 776 return array( 777 'groups' => $paged_groups, 778 'total' => $total_groups, 779 ); 736 780 } 737 781 … … 740 784 * 741 785 * @since 1.6.0 786 * 787 * @global wpdb $wpdb WordPress database abstraction object. 742 788 * 743 789 * @param int $user_id Optional. Default: ID of the displayed user. … … 747 793 global $wpdb; 748 794 749 if ( empty( $user_id ) ) 795 if ( empty( $user_id ) ) { 750 796 $user_id = bp_displayed_user_id(); 751 752 $bp = buddypress(); 753 754 if ( $user_id != bp_loggedin_user_id() && !bp_current_user_can( 'bp_moderate' ) ) { 797 } 798 799 $bp = buddypress(); 800 801 if ( $user_id != bp_loggedin_user_id() && ! bp_current_user_can( 'bp_moderate' ) ) { 755 802 return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) ); 756 } else {757 return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) ); 758 }803 } 804 805 return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) ); 759 806 } 760 807 … … 797 844 * @since 4.0.0 798 845 * 799 * @param int $user_id ID of the user. 846 * @global wpdb $wpdb WordPress database abstraction object. 847 * 848 * @param int $user_id ID of the user. 800 849 * @param array $args { 801 850 * Array of optional arguments. … … 814 863 $bp = buddypress(); 815 864 816 $r = array_merge( array( 817 'page' => 1, 818 'per_page' => 20, 819 'type' => 'membership', 820 ), $args ); 865 $r = array_merge( 866 array( 867 'page' => 1, 868 'per_page' => 20, 869 'type' => 'membership', 870 ), 871 $args 872 ); 821 873 822 874 $sql = array( … … 828 880 829 881 switch ( $r['type'] ) { 830 case 'pending_request' : 831 return groups_get_requests( array( 832 'user_id' => $user_id, 833 'page' => $r['page'], 834 'per_page' => $r['per_page'], 835 ) ); 836 break; 837 838 case 'pending_received_invitation' : 839 return groups_get_invites( array( 840 'user_id' => $user_id, 841 'page' => $r['page'], 842 'per_page' => $r['per_page'], 843 ) ); 844 break; 845 846 case 'pending_sent_invitation' : 847 return groups_get_invites( array( 848 'inviter_id' => $user_id, 849 'page' => $r['page'], 850 'per_page' => $r['per_page'], 851 ) ); 852 break; 853 854 case 'membership' : 855 default : 856 $sql['where'] = $wpdb->prepare( "user_id = %d AND is_confirmed = 1", $user_id ); 857 break; 882 case 'pending_request': 883 return groups_get_requests( 884 array( 885 'user_id' => $user_id, 886 'page' => $r['page'], 887 'per_page' => $r['per_page'], 888 ) 889 ); 890 891 case 'pending_received_invitation': 892 return groups_get_invites( 893 array( 894 'user_id' => $user_id, 895 'page' => $r['page'], 896 'per_page' => $r['per_page'], 897 ) 898 ); 899 900 case 'pending_sent_invitation': 901 return groups_get_invites( 902 array( 903 'inviter_id' => $user_id, 904 'page' => $r['page'], 905 'per_page' => $r['per_page'], 906 ) 907 ); 908 909 case 'membership': 910 default: 911 $sql['where'] = $wpdb->prepare( 'user_id = %d AND is_confirmed = 1', $user_id ); 912 break; 858 913 } 859 914 860 915 if ( $r['page'] && $r['per_page'] ) { 861 $sql['limits'] = $wpdb->prepare( "LIMIT %d, %d", ( $r['page'] - 1 ) * $r['per_page'], $r['per_page'] );916 $sql['limits'] = $wpdb->prepare( 'LIMIT %d, %d', ( $r['page'] - 1 ) * $r['per_page'], $r['per_page'] ); 862 917 } 863 918 … … 931 986 * @param int $user_id ID of the user. 932 987 * @param int $group_id ID of the group. 933 * @return int Number of records deleted.988 * @return int|false Number of records deleted. False if the user is not a member of the group. 934 989 */ 935 990 public static function delete_request( $user_id, $group_id ) { … … 941 996 * 942 997 * @since 1.6.0 998 * 999 * @global wpdb $wpdb WordPress database abstraction object. 943 1000 * 944 1001 * @param int $user_id ID of the user. … … 949 1006 global $wpdb; 950 1007 951 if ( empty( $user_id ) ) 1008 if ( empty( $user_id ) ) { 952 1009 return false; 1010 } 953 1011 954 1012 $bp = buddypress(); … … 961 1019 * 962 1020 * @since 1.6.0 1021 * 1022 * @global wpdb $wpdb WordPress database abstraction object. 963 1023 * 964 1024 * @param int $user_id ID of the user. … … 969 1029 global $wpdb; 970 1030 971 if ( empty( $user_id ) ) 1031 if ( empty( $user_id ) ) { 972 1032 return false; 1033 } 973 1034 974 1035 $bp = buddypress(); … … 981 1042 * 982 1043 * @since 1.6.0 1044 * 1045 * @global wpdb $wpdb WordPress database abstraction object. 983 1046 * 984 1047 * @param int $user_id ID of the user. … … 989 1052 global $wpdb; 990 1053 991 if ( empty( $user_id ) ) 1054 if ( empty( $user_id ) ) { 992 1055 return false; 1056 } 993 1057 994 1058 $bp = buddypress(); … … 1001 1065 * 1002 1066 * @since 1.6.0 1067 * 1068 * @global wpdb $wpdb WordPress database abstraction object. 1003 1069 * 1004 1070 * @param int $user_id ID of the user. … … 1010 1076 global $wpdb; 1011 1077 1012 if ( empty( $user_id ) ) 1078 if ( empty( $user_id ) ) { 1013 1079 return false; 1080 } 1014 1081 1015 1082 $bp = buddypress(); … … 1024 1091 * 1025 1092 * @since 1.2.6 1093 * 1094 * @global wpdb $wpdb WordPress database abstraction object. 1026 1095 * 1027 1096 * @param int $user_id ID of the user. … … 1032 1101 global $wpdb; 1033 1102 1034 if ( empty( $user_id ) ) 1103 if ( empty( $user_id ) ) { 1035 1104 return false; 1105 } 1036 1106 1037 1107 $bp = buddypress(); … … 1060 1130 * @since 1.6.0 1061 1131 * 1132 * @global wpdb $wpdb WordPress database abstraction object. 1133 * 1062 1134 * @param int $user_id ID of the user. 1063 1135 * @param int $total_groups Max number of group IDs to return. Default: 5. … … 1072 1144 if ( bp_is_my_profile() ) { 1073 1145 return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) ); 1074 } else {1075 return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) ); 1076 }1146 } 1147 1148 return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) ); 1077 1149 } 1078 1150 … … 1081 1153 * 1082 1154 * @since 1.6.0 1155 * 1156 * @global wpdb $wpdb WordPress database abstraction object. 1083 1157 * 1084 1158 * @param int $group_id ID of the group. … … 1098 1172 * @since 1.6.0 1099 1173 * 1100 * @param int 1174 * @param int $group_id ID of the group. 1101 1175 * @return array Info about group admins (user_id + date_modified). 1102 1176 */ … … 1131 1205 * @since 2.7.0 1132 1206 * 1207 * @global wpdb $wpdb WordPress database abstraction object. 1208 * 1133 1209 * @param array $group_ids IDs of the groups. 1134 * @return bool1135 1210 */ 1136 1211 public static function prime_group_admins_mods_cache( $group_ids ) { … … 1140 1215 1141 1216 if ( $uncached ) { 1142 $bp = buddypress();1143 $uncached_sql = implode( ',', array_map( 'intval', $uncached ) );1217 $bp = buddypress(); 1218 $uncached_sql = implode( ',', array_map( 'intval', $uncached ) ); 1144 1219 $group_admin_mods = $wpdb->get_results( "SELECT user_id, group_id, date_modified, is_admin, is_mod FROM {$bp->groups->table_name_members} WHERE group_id IN ({$uncached_sql}) AND ( is_admin = 1 OR is_mod = 1 ) AND is_banned = 0" ); 1145 1220 … … 1147 1222 if ( $group_admin_mods ) { 1148 1223 foreach ( $group_admin_mods as $group_admin_mod ) { 1149 $obj = new stdClass();1150 $obj->user_id = $group_admin_mod->user_id;1224 $obj = new stdClass(); 1225 $obj->user_id = $group_admin_mod->user_id; 1151 1226 $obj->date_modified = $group_admin_mod->date_modified; 1152 1227 … … 1209 1284 * @since 2.6.0 1210 1285 * 1286 * @global wpdb $wpdb WordPress database abstraction object. 1287 * 1211 1288 * @param int|string|array $membership_ids Single membership ID or comma-separated/array list of membership IDs. 1212 1289 * @return array … … 1218 1295 1219 1296 $membership_ids = implode( ',', wp_parse_id_list( $membership_ids ) ); 1297 1220 1298 return $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name_members} WHERE id IN ({$membership_ids})" ); 1221 1299 } … … 1235 1313 /** 1236 1314 * Get members of a group. 1315 * 1316 * @global wpdb $wpdb WordPress database abstraction object. 1237 1317 * 1238 1318 * @deprecated 1.6.0 … … 1252 1332 1253 1333 $pag_sql = ''; 1254 if ( !empty( $limit ) && !empty( $page ) ) 1255 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 1334 if ( ! empty( $limit ) && ! empty( $page ) ) { 1335 $pag_sql = $wpdb->prepare( 'LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) ); 1336 } 1256 1337 1257 1338 $exclude_admins_sql = ''; 1258 if ( !empty( $exclude_admins_mods ) ) 1259 $exclude_admins_sql = "AND is_admin = 0 AND is_mod = 0"; 1339 if ( ! empty( $exclude_admins_mods ) ) { 1340 $exclude_admins_sql = 'AND is_admin = 0 AND is_mod = 0'; 1341 } 1260 1342 1261 1343 $banned_sql = ''; 1262 if ( !empty( $exclude_banned ) ) 1263 $banned_sql = " AND is_banned = 0"; 1344 if ( ! empty( $exclude_banned ) ) { 1345 $banned_sql = ' AND is_banned = 0'; 1346 } 1264 1347 1265 1348 $exclude_sql = ''; 1266 if ( ! empty( $exclude ) ) {1349 if ( ! empty( $exclude ) ) { 1267 1350 $exclude = implode( ',', wp_parse_id_list( $exclude ) ); 1268 1351 $exclude_sql = " AND m.user_id NOT IN ({$exclude})"; … … 1306 1389 1307 1390 // Fetch whether or not the user is a friend. 1308 foreach ( (array) $members as $user ) 1391 foreach ( (array) $members as $user ) { 1309 1392 $user_ids[] = $user->user_id; 1393 } 1310 1394 1311 1395 $user_ids = implode( ',', wp_parse_id_list( $user_ids ) ); … … 1315 1399 for ( $i = 0, $count = count( $members ); $i < $count; ++$i ) { 1316 1400 foreach ( (array) $friend_status as $status ) { 1317 if ( $status->initiator_user_id == $members[ $i]->user_id || $status->friend_user_id == $members[$i]->user_id ) {1318 $members[ $i]->is_friend = $status->is_confirmed;1401 if ( $status->initiator_user_id == $members[ $i ]->user_id || $status->friend_user_id == $members[ $i ]->user_id ) { 1402 $members[ $i ]->is_friend = $status->is_confirmed; 1319 1403 } 1320 1404 } … … 1322 1406 } 1323 1407 1324 return array( 'members' => $members, 'count' => $total_member_count ); 1408 return array( 1409 'members' => $members, 1410 'count' => $total_member_count, 1411 ); 1325 1412 } 1326 1413 … … 1329 1416 * 1330 1417 * @since 2.6.0 1418 * 1419 * @global wpdb $wpdb WordPress database abstraction object. 1331 1420 * 1332 1421 * @param int $user_id ID of the user. … … 1347 1436 * 1348 1437 * @since 1.6.0 1438 * 1439 * @global wpdb $wpdb WordPress database abstraction object. 1349 1440 * 1350 1441 * @param int $group_id ID of the group. … … 1373 1464 */ 1374 1465 public static function delete_all_for_user( $user_id ) { 1375 $group_ids = BP_Groups_Member::get_group_ids( $user_id );1466 $group_ids = self::get_group_ids( $user_id ); 1376 1467 1377 1468 foreach ( $group_ids['groups'] as $group_id ) { … … 1379 1470 // If the user is a sole group admin, install a site admin as their replacement. 1380 1471 if ( count( groups_get_group_admins( $group_id ) ) < 2 ) { 1381 $admin = get_users( array( 1382 'blog_id' => bp_get_root_blog_id(), 1383 'fields' => 'id', 1384 'number' => 1, 1385 'orderby' => 'ID', 1386 'role' => 'administrator', 1387 ) ); 1472 $admin = get_users( 1473 array( 1474 'blog_id' => bp_get_root_blog_id(), 1475 'fields' => 'id', 1476 'number' => 1, 1477 'orderby' => 'ID', 1478 'role' => 'administrator', 1479 ) 1480 ); 1388 1481 1389 1482 if ( ! empty( $admin ) ) { … … 1396 1489 } 1397 1490 1398 BP_Groups_Member::delete( $user_id, $group_id );1491 self::delete( $user_id, $group_id ); 1399 1492 } 1400 1493
Note: See TracChangeset
for help on using the changeset viewer.