Changeset 13103 for trunk/src/bp-groups/bp-groups-functions.php
- Timestamp:
- 09/09/2021 02:01:40 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r13101 r13103 78 78 * Possible values are `'id'` or `'slug'`. 79 79 * @param string|int $value (Required) A value for the $field. A Group ID or slug. 80 * @return BP_Groups_Group| falseThe Group object if found, false otherwise.80 * @return BP_Groups_Group|bool The Group object if found, false otherwise. 81 81 */ 82 82 function bp_get_group_by( $field, $value ) { … … 104 104 * @since 10.0.0 105 105 * 106 * @global BP_Groups_Template $groups_template Groups template object. 107 * 106 108 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object. 107 109 * Default: false. 108 * @return BP_Groups_Group| falseThe Group object if found, false otherwise.110 * @return BP_Groups_Group|bool The Group object if found, false otherwise. 109 111 */ 110 112 function bp_get_group( $group = false ) { … … 115 117 if ( $group instanceof BP_Groups_Group ) { 116 118 $group_obj = $group; 117 } elseif ( is_string( $group ) ) { 118 $group_obj = bp_get_group_by( 'slug', $group ); 119 } elseif ( is_numeric( $group ) ) { 120 $group_obj = bp_get_group_by( 'id', $group ); 121 } elseif ( isset( $groups_template->group ) && is_object( $groups_template->group ) ) { 119 120 // Nothing requested? Let's use the current Group of the Groups Loop, if available. 121 } elseif ( ! $group && isset( $groups_template->group ) && is_object( $groups_template->group ) ) { 122 122 $group_obj = $groups_template->group; 123 } else { 124 $current_group = null; 125 126 // Let's get the current group if we can. 127 if ( did_action( 'bp_groups_set_current_group' ) ) { 128 $current_group = groups_get_current_group(); 129 } 130 131 $field = ''; 132 if ( is_string( $group ) ) { 133 $field = 'slug'; 134 } elseif ( is_numeric( $group ) ) { 135 $field = 'id'; 136 $group = (int) $group; 137 } 138 139 // Let's use the current Group if it matches with the requested field value. 140 if ( isset( $current_group->{$field} ) && $current_group->{$field} === $group ) { 141 $group_obj = $current_group; 142 } else { 143 $group_obj = bp_get_group_by( $field, $group ); 144 } 123 145 } 124 146 … … 482 504 $bp = buddypress(); 483 505 484 return in_array( $status, (array) $bp->groups->valid_status );506 return in_array( $status, (array) $bp->groups->valid_status, true ); 485 507 } 486 508 … … 534 556 * 535 557 * @param string $group_slug The group's slug. 536 * @return int|null The group ID on success ;null on failure.558 * @return int|null The group ID on success, null on failure. 537 559 */ 538 560 function groups_get_id( $group_slug ) { … … 546 568 * 547 569 * @param string $group_slug The group's slug. 548 * @return int|null The group ID on success ;null on failure.570 * @return int|null The group ID on success, null on failure. 549 571 */ 550 572 function groups_get_id_by_previous_slug( $group_slug ) { … … 685 707 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 686 708 } 687 add_action( 'groups_join_group', 688 add_action( 'groups_leave_group', 689 add_action( 'groups_created_group', 709 add_action( 'groups_join_group', 'groups_update_last_activity' ); 710 add_action( 'groups_leave_group', 'groups_update_last_activity' ); 711 add_action( 'groups_created_group', 'groups_update_last_activity' ); 690 712 691 713 /** General Group Functions ***************************************************/ … … 824 846 * 825 847 * @since 1.2.3 826 * 827 * @param int $group_id Group ID. 828 * @return int Count of confirmed members for the group. 829 */ 830 function groups_get_total_member_count( $group_id ) { 831 return BP_Groups_Group::get_total_member_count( $group_id ); 848 * @since 10.0.0 Updated to use `bp_get_group`. 849 * 850 * @param int|string|BP_Groups_Group $group The Group ID, the Group Slug or the Group object. 851 * @param bool $skip_cache Optional. Skip grabbing from cache. Defaults to false. 852 * @return int|bool Count of confirmed members for the group. False if group doesn't exist. 853 */ 854 function groups_get_total_member_count( $group, $skip_cache = false ) { 855 856 $group = bp_get_group( $group ); 857 858 if ( empty( $group->id ) ) { 859 return false; 860 } 861 862 return (int) BP_Groups_Group::get_total_member_count( $group->id, (bool) $skip_cache ); 832 863 } 833 864 … … 919 950 * 920 951 * @since 1.2.0 921 * 952 * @since 10.0.0 Added the `$skip_cache` parameter. 953 * 954 * @param bool $skip_cache Optional. Skip getting count from cache. 955 * Defaults to false. 922 956 * @return int 923 957 */ 924 function groups_get_total_group_count() { 925 $count = wp_cache_get( 'bp_total_group_count', 'bp' ); 926 927 if ( false === $count ) { 928 $count = BP_Groups_Group::get_total_group_count(); 929 wp_cache_set( 'bp_total_group_count', $count, 'bp' ); 930 } 931 932 return $count; 958 function groups_get_total_group_count( $skip_cache = false ) { 959 return (int) BP_Groups_Group::get_total_group_count( $skip_cache ); 933 960 } 934 961 … … 950 977 function groups_get_user_groups( $user_id = 0, $pag_num = 0, $pag_page = 0 ) { 951 978 952 if ( empty( $user_id ) ) 979 if ( empty( $user_id ) ) { 953 980 $user_id = bp_displayed_user_id(); 981 } 954 982 955 983 return BP_Groups_Member::get_group_ids( $user_id, $pag_num, $pag_page ); … … 1179 1207 * @since 1.5.0 1180 1208 * 1181 * @return BP_Groups_Group The current group object. 1209 * @global BuddyPress $bp The one true BuddyPress instance. 1210 * 1211 * @return BP_Groups_Group|bool The current group object or false. 1182 1212 */ 1183 1213 function groups_get_current_group() { … … 1193 1223 * @since 1.5.0 1194 1224 * 1195 * @param BP_Groups_Group $current_group Current BP_Groups_Group object.1225 * @param BP_Groups_Group|bool $current_group Current BP_Groups_Group object or false. 1196 1226 */ 1197 1227 return apply_filters( 'groups_get_current_group', $current_group );
Note: See TracChangeset
for help on using the changeset viewer.