Changeset 10373 for trunk/src/bp-groups/bp-groups-functions.php
- Timestamp:
- 11/22/2015 04:58:34 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r10351 r10373 36 36 * 37 37 * @param array|string $args { 38 * 39 * 40 * 41 * 42 * 43 * Default: false.38 * Array of al arguments. 39 * @type int $group_id ID of the group. 40 * @type bool $load_users No longer used. 41 * @type bool $populate_extras Whether to fetch membership data and other 42 * extra information about the group. 43 * Default: false. 44 44 * } 45 45 * @return BP_Groups_Group $group The group object. … … 84 84 * @type string $slug The group slug. 85 85 * @type string $status The group's status. Accepts 'public', 'private' or 86 86 * 'hidden'. Defaults to 'public'. 87 87 * @type int $enable_forum Optional. Whether the group has a forum enabled. 88 88 * If the legacy forums are enabled for this group … … 110 110 extract( $args, EXTR_SKIP ); 111 111 112 // Pass an existing group ID 112 // Pass an existing group ID. 113 113 if ( ! empty( $group_id ) ) { 114 114 $group = groups_get_group( array( 'group_id' => (int) $group_id ) ); … … 117 117 $description = ! empty( $description ) ? $description : $group->description; 118 118 119 // Groups need at least a name 119 // Groups need at least a name. 120 120 if ( empty( $name ) ) { 121 121 return false; 122 122 } 123 123 124 // Create a new group 124 // Create a new group. 125 125 } else { 126 // Instantiate new group object 126 // Instantiate new group object. 127 127 $group = new BP_Groups_Group; 128 128 } 129 129 130 // Set creator ID 130 // Set creator ID. 131 131 if ( $creator_id ) { 132 132 $group->creator_id = (int) $creator_id; … … 139 139 } 140 140 141 // Validate status 141 // Validate status. 142 142 if ( ! groups_is_valid_status( $status ) ) { 143 143 return false; 144 144 } 145 145 146 // Set group name 146 // Set group name. 147 147 $group->name = $name; 148 148 $group->description = $description; … … 152 152 $group->date_created = $date_created; 153 153 154 // Save group 154 // Save group. 155 155 if ( ! $group->save() ) { 156 156 return false; 157 157 } 158 158 159 // If this is a new group, set up the creator as the first member and admin 159 // If this is a new group, set up the creator as the first member and admin. 160 160 if ( empty( $group_id ) ) { 161 161 $member = new BP_Groups_Member; … … 217 217 * @param bool $notify_members Whether to send an email notification to group 218 218 * members about changes in these details. 219 *220 219 * @return bool True on success, false on failure. 221 220 */ … … 263 262 * @param string|bool $invite_status Optional. Who is allowed to send invitations 264 263 * to the group. 'members', 'mods', or 'admins'. 265 *266 264 * @return bool True on success, false on failure. 267 265 */ … … 271 269 $group->enable_forum = $enable_forum; 272 270 273 /** *271 /** 274 272 * Before we potentially switch the group status, if it has been changed to public 275 273 * from private and there are outstanding membership requests, auto-accept those requests. … … 278 276 groups_accept_all_pending_membership_requests( $group->id ); 279 277 280 // Now update the status 278 // Now update the status. 281 279 $group->status = $status; 282 280 … … 291 289 } 292 290 293 // Set the invite status 291 // Set the invite status. 294 292 if ( $invite_status ) 295 293 groups_update_groupmeta( $group->id, 'invite_status', $invite_status ); … … 315 313 * 316 314 * @param int $group_id ID of the group to delete. 317 *318 315 * @return bool True on success, false on failure. 319 316 */ … … 329 326 do_action( 'groups_before_delete_group', $group_id ); 330 327 331 // Get the group object 328 // Get the group object. 332 329 $group = groups_get_group( array( 'group_id' => $group_id ) ); 333 330 334 // Bail if group cannot be deleted 331 // Bail if group cannot be deleted. 335 332 if ( ! $group->delete() ) { 336 333 return false; 337 334 } 338 335 339 // Remove all outstanding invites for this group 336 // Remove all outstanding invites for this group. 340 337 groups_delete_all_group_invites( $group_id ); 341 338 … … 356 353 * 357 354 * @param string $status Status to check. 358 *359 355 * @return bool True if status is allowed, otherwise false. 360 356 */ … … 369 365 * 370 366 * @param string $slug Group slug to check. 371 *372 367 * @return string $slug A unique and sanitized slug. 373 368 */ … … 395 390 * 396 391 * @param int $group_id The numeric ID of the group. 397 *398 392 * @return string The group's slug. 399 393 */ … … 409 403 * 410 404 * @param string $group_slug The group's slug. 411 *412 405 * @return int The ID. 413 406 */ … … 424 417 * @param int $user_id Optional. ID of the user. Defaults to the currently 425 418 * logged-in user. 426 *427 419 * @return bool True on success, false on failure. 428 420 */ … … 465 457 * @param int $user_id Optional. ID of the user. Defaults to the currently 466 458 * logged-in user. 467 *468 459 * @return bool True on success, false on failure. 469 460 */ … … 481 472 groups_delete_membership_request( null, $user_id, $group_id ); 482 473 483 // User is already a member, just return true 474 // User is already a member, just return true. 484 475 if ( groups_is_user_member( $user_id, $group_id ) ) 485 476 return true; … … 504 495 $group = $bp->groups->current_group; 505 496 506 // Record this in activity streams 497 // Record this in activity streams. 507 498 groups_record_activity( array( 508 499 'type' => 'joined_group', … … 530 521 * 531 522 * @param int $group_id ID of the group. 532 *533 523 * @return array Info about group admins (user_id + date_modified). 534 524 */ … … 541 531 * 542 532 * @param int $group_id ID of the group. 543 *544 533 * @return array Info about group admins (user_id + date_modified). 545 534 */ … … 580 569 function groups_get_group_members( $args = array() ) { 581 570 582 // Backward compatibility with old method of passing arguments 571 // Backward compatibility with old method of passing arguments. 583 572 if ( ! is_array( $args ) || func_num_args() > 1 ) { 584 573 _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 612 601 // For legacy users. Use of BP_Groups_Member::get_all_for_group() 613 602 // is deprecated. func_get_args() can't be passed to a function in PHP 614 // 5.2.x, so we create a variable 603 // 5.2.x, so we create a variable. 615 604 $func_args = func_get_args(); 616 605 if ( apply_filters( 'bp_use_legacy_group_member_query', false, __FUNCTION__, $func_args ) ) { … … 618 607 } else { 619 608 620 // exclude_admins_mods and exclude_banned are legacy arguments.621 // Convert to group_role 609 // Both exclude_admins_mods and exclude_banned are legacy arguments. 610 // Convert to group_role. 622 611 if ( empty( $r['group_role'] ) ) { 623 612 $r['group_role'] = array( 'member' ); … … 633 622 } 634 623 635 // Perform the group member query (extends BP_User_Query) 624 // Perform the group member query (extends BP_User_Query). 636 625 $members = new BP_Group_Member_Query( array( 637 626 'group_id' => $r['group_id'], … … 644 633 ) ); 645 634 646 // Structure the return value as expected by the template functions 635 // Structure the return value as expected by the template functions. 647 636 $retval = array( 648 637 'members' => array_values( $members->results ), … … 658 647 * 659 648 * @param int $group_id Group ID. 660 *661 649 * @return int Count of confirmed members for the group. 662 650 */ … … 682 670 683 671 $defaults = array( 684 'type' => false, // active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts685 'order' => 'DESC', // 'ASC' or 'DESC'686 'orderby' => 'date_created', // date_created, last_activity, total_member_count, name, random 687 'user_id' => false, // Pass a user_id to limit to only groups that this user is a member of688 'include' => false, // Only include these specific groups (group_ids)689 'exclude' => false, // Do not include these specific groups (group_ids)690 'search_terms' => false, // Limit to groups that match these search terms691 'meta_query' => false, // Filter by groupmeta. See WP_Meta_Query for syntax692 'show_hidden' => false, // Show hidden groups to non-admins693 'per_page' => 20, // The number of results to return per page694 'page' => 1, // The page to return if limiting per page695 'populate_extras' => true, // Fetch meta such as is_banned and is_member696 'update_meta_cache' => true, // Pre-fetch groupmeta for queried groups672 'type' => false, // Active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts. 673 'order' => 'DESC', // 'ASC' or 'DESC' 674 'orderby' => 'date_created', // date_created, last_activity, total_member_count, name, random. 675 'user_id' => false, // Pass a user_id to limit to only groups that this user is a member of. 676 'include' => false, // Only include these specific groups (group_ids). 677 'exclude' => false, // Do not include these specific groups (group_ids). 678 'search_terms' => false, // Limit to groups that match these search terms. 679 'meta_query' => false, // Filter by groupmeta. See WP_Meta_Query for syntax. 680 'show_hidden' => false, // Show hidden groups to non-admins. 681 'per_page' => 20, // The number of results to return per page. 682 'page' => 1, // The page to return if limiting per page. 683 'populate_extras' => true, // Fetch meta such as is_banned and is_member. 684 'update_meta_cache' => true, // Pre-fetch groupmeta for queried groups. 697 685 ); 698 686 … … 769 757 * 770 758 * @param int $user_id Optional. Default: ID of the displayed user. 771 *772 759 * @return int Group count. 773 760 */ … … 816 803 * Generate the avatar upload directory path for a given group. 817 804 * 818 * @param int $group_id Optional. ID of the group. Default: ID of the 819 * current group. 805 * @param int $group_id Optional. ID of the group. Default: ID of the current group. 820 806 * @return string 821 807 */ … … 857 843 * @param int $user_id ID of the user. 858 844 * @param int $group_id ID of the group. 859 *860 845 * @return bool 861 846 */ … … 869 854 * @param int $user_id ID of the user. 870 855 * @param int $group_id ID of the group. 871 *872 856 * @return bool 873 857 */ … … 881 865 * @param int $user_id ID of the user. 882 866 * @param int $group_id ID of the group. 883 *884 867 * @return bool 885 868 */ … … 899 882 * @param int $user_id ID of the user. 900 883 * @param int $group_id ID of the group. 901 *902 884 * @return bool 903 885 */ … … 947 929 return false; 948 930 949 // Record this in activity streams 931 // Record this in activity streams. 950 932 $activity_action = sprintf( __( '%1$s posted an update in the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ); 951 933 $activity_content = $content; … … 1000 982 * 1001 983 * @param int $user_id ID of the inviting user. 1002 * @param int|bool $limit Limit to restrict to.1003 * @param int|bool $page 1004 * @param string|array|bool $exclude 1005 * 984 * @param int|bool $limit Limit to restrict to. 985 * @param int|bool $page Optional. Page offset of results to return. 986 * @param string|array|bool $exclude Array of comma-separated list of group IDs 987 * to exclude from results. 1006 988 * @return array $value IDs of users who have been invited to the group by the 1007 989 * user but have not yet accepted. … … 1021 1003 * 1022 1004 * @param int $user_id The user ID. 1023 *1024 1005 * @return int 1025 1006 */ … … 1064 1045 return false; 1065 1046 1066 // if the user has already requested membership, accept the request1047 // If the user has already requested membership, accept the request. 1067 1048 if ( $membership_id = groups_check_for_membership_request( $user_id, $group_id ) ) { 1068 1049 groups_accept_membership_request( $membership_id, $user_id, $group_id ); 1069 1050 1070 // Otherwise, create a new invitation 1051 // Otherwise, create a new invitation. 1071 1052 } elseif ( ! groups_is_user_member( $user_id, $group_id ) && ! groups_check_user_has_invite( $user_id, $group_id, 'all' ) ) { 1072 1053 $invite = new BP_Groups_Member; … … 1100 1081 * @param int $user_id ID of the user. 1101 1082 * @param int $group_id ID of the group. 1102 *1103 1083 * @return bool True on success, false on failure. 1104 1084 */ … … 1128 1108 * @param int $user_id ID of the user. 1129 1109 * @param int $group_id ID of the group. 1130 *1131 1110 * @return bool True when the user is a member of the group, otherwise false. 1132 1111 */ … … 1134 1113 1135 1114 // If the user is already a member (because BP at one point allowed two invitations to 1136 // slip through), delete all existing invitations/requests and return true 1115 // slip through), delete all existing invitations/requests and return true. 1137 1116 if ( groups_is_user_member( $user_id, $group_id ) ) { 1138 1117 if ( groups_check_user_has_invite( $user_id, $group_id ) ) { … … 1154 1133 } 1155 1134 1156 // Remove request to join 1135 // Remove request to join. 1157 1136 if ( $member->check_for_membership_request( $user_id, $group_id ) ) { 1158 1137 $member->delete_request( $user_id, $group_id ); 1159 1138 } 1160 1139 1161 // Modify group meta 1140 // Modify group meta. 1162 1141 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 1163 1142 … … 1180 1159 * @param int $user_id ID of the user. 1181 1160 * @param int $group_id ID of the group. 1182 *1183 1161 * @return bool True on success, false on failure. 1184 1162 */ … … 1205 1183 * @param int $user_id ID of the invited user. 1206 1184 * @param int $group_id ID of the group. 1207 *1208 1185 * @return bool True on success, false on failure. 1209 1186 */ … … 1243 1220 $member = new BP_Groups_Member( $invited_users[$i], $group_id ); 1244 1221 1245 // Send the actual invite 1222 // Send the actual invite. 1246 1223 groups_notification_group_invites( $group, $member, $user_id ); 1247 1224 … … 1268 1245 * @param int $user_id ID of the inviting user. 1269 1246 * @param int $group_id ID of the group. 1270 *1271 1247 * @return array $value IDs of users who have been invited to the group by the 1272 1248 * user but have not yet accepted. … … 1287 1263 * @param string $type Optional. Use 'sent' to check for sent invites, 1288 1264 * 'all' to check for all. Default: 'sent'. 1289 *1290 1265 * @return bool True if an invitation is found, otherwise false. 1291 1266 */ … … 1298 1273 * 1299 1274 * @param int $group_id ID of the group whose invitations are being deleted. 1300 *1301 1275 * @return int|null Number of rows records deleted on success, null on failure. 1302 1276 */ … … 1313 1287 * @param int $group_id ID of the group. 1314 1288 * @param string $status The new status. 'mod' or 'admin'. 1315 *1316 1289 * @return bool True on success, false on failure. 1317 1290 */ … … 1345 1318 * @param int $user_id ID of the user. 1346 1319 * @param int $group_id ID of the group. 1347 *1348 1320 * @return bool True on success, false on failure. 1349 1321 */ … … 1373 1345 * @param int $user_id ID of the user. 1374 1346 * @param int $group_id ID of the group. 1375 *1376 1347 * @return bool True on success, false on failure. 1377 1348 */ … … 1401 1372 * @param int $user_id ID of the user. 1402 1373 * @param int $group_id ID of the group. 1403 *1404 1374 * @return bool True on success, false on failure. 1405 1375 */ … … 1431 1401 * @param int $user_id ID of the user. 1432 1402 * @param int $group_id ID of the group. 1433 *1434 1403 * @return bool True on success, false on failure. 1435 1404 */ … … 1462 1431 * @param int $requesting_user_id ID of the user requesting membership. 1463 1432 * @param int $group_id ID of the group. 1464 *1465 1433 * @return bool True on success, false on failure. 1466 1434 */ 1467 1435 function groups_send_membership_request( $requesting_user_id, $group_id ) { 1468 1436 1469 // Prevent duplicate requests 1437 // Prevent duplicate requests. 1470 1438 if ( groups_check_for_membership_request( $requesting_user_id, $group_id ) ) 1471 1439 return false; 1472 1440 1473 // Check if the user is already a member or is banned 1441 // Check if the user is already a member or is banned. 1474 1442 if ( groups_is_user_member( $requesting_user_id, $group_id ) || groups_is_user_banned( $requesting_user_id, $group_id ) ) 1475 1443 return false; 1476 1444 1477 // Check if the user is already invited - if so, simply accept invite 1445 // Check if the user is already invited - if so, simply accept invite. 1478 1446 if ( groups_check_user_has_invite( $requesting_user_id, $group_id ) ) { 1479 1447 groups_accept_invite( $requesting_user_id, $group_id ); … … 1494 1462 $admins = groups_get_group_admins( $group_id ); 1495 1463 1496 // Saved okay, now send the email notification 1464 // Saved okay, now send the email notification. 1497 1465 for ( $i = 0, $count = count( $admins ); $i < $count; ++$i ) 1498 1466 groups_notification_new_membership_request( $requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id ); … … 1526 1494 * requested. Provide this value along with $user_id to 1527 1495 * override $membership_id. 1528 *1529 1496 * @return bool True on success, false on failure. 1530 1497 */ … … 1572 1539 * requested. Provide this value along with $user_id to 1573 1540 * override $membership_id. 1574 *1575 1541 * @return bool True on success, false on failure. 1576 1542 */ … … 1604 1570 * requested. Provide this value along with $user_id to 1605 1571 * override $membership_id. 1606 *1607 1572 * @return bool True on success, false on failure. 1608 1573 */ … … 1624 1589 * @param int $user_id ID of the user. 1625 1590 * @param int $group_id ID of the group. 1626 *1627 1591 * @return int|null ID of the membership if found, otherwise false. 1628 1592 */ … … 1635 1599 * 1636 1600 * @param int $group_id ID of the group. 1637 *1638 1601 * @return bool True on success, false on failure. 1639 1602 */ … … 1672 1635 * metadata entries for the specified group. 1673 1636 * Default: false. 1674 *1675 1637 * @return bool True on success, false on failure. 1676 1638 */ … … 1678 1640 global $wpdb; 1679 1641 1680 // Legacy - if no meta_key is passed, delete all for the item 1642 // Legacy - if no meta_key is passed, delete all for the item. 1681 1643 if ( empty( $meta_key ) ) { 1682 1644 $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->groupmeta} WHERE group_id = %d", $group_id ) ); 1683 1645 1684 // With no meta_key, ignore $delete_all 1646 // With no meta_key, ignore $delete_all. 1685 1647 $delete_all = false; 1686 1648 } else { … … 1708 1670 * specified meta_key. This parameter has no effect if 1709 1671 * meta_key is empty. 1710 *1711 1672 * @return mixed Metadata value. 1712 1673 */ … … 1728 1689 * metadata entries with the specified value. 1729 1690 * Otherwise, update all entries. 1730 *1731 1691 * @return bool|int $retval Returns false on failure. On successful update of existing 1732 1692 * metadata, returns true. On successful creation of new metadata, … … 1753 1713 * has a value for the key, no change will be made. 1754 1714 * Default: false. 1755 *1756 1715 * @return int|bool The meta ID on successful update, false on failure. 1757 1716 */
Note: See TracChangeset
for help on using the changeset viewer.