diff --git src/bp-groups/classes/class-bp-groups-group.php src/bp-groups/classes/class-bp-groups-group.php
index 52361ff..66d788e 100644
|
|
class BP_Groups_Group { |
909 | 909 | |
910 | 910 | // Populate some extra information instead of querying each time in the loop. |
911 | 911 | if ( !empty( $r['populate_extras'] ) ) { |
912 | | $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'] ); |
| 912 | $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'], $r['user_id'] ); |
913 | 913 | } |
914 | 914 | |
915 | 915 | // Grab all groupmeta. |
… |
… |
class BP_Groups_Group { |
1186 | 1186 | foreach ( (array) $paged_groups as $group ) { |
1187 | 1187 | $group_ids[] = $group->id; |
1188 | 1188 | } |
1189 | | $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' ); |
| 1189 | $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest', $user_id ); |
1190 | 1190 | } |
1191 | 1191 | |
1192 | 1192 | return array( 'groups' => $paged_groups, 'total' => $total_groups ); |
… |
… |
class BP_Groups_Group { |
1318 | 1318 | foreach ( (array) $paged_groups as $group ) { |
1319 | 1319 | $group_ids[] = $group->id; |
1320 | 1320 | } |
1321 | | $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' ); |
| 1321 | $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest', $user_id ); |
1322 | 1322 | } |
1323 | 1323 | |
1324 | 1324 | return array( 'groups' => $paged_groups, 'total' => $total_groups ); |
… |
… |
class BP_Groups_Group { |
1340 | 1340 | * @param string|bool $type Not used. |
1341 | 1341 | * @return array $paged_groups |
1342 | 1342 | */ |
1343 | | public static function get_group_extras( &$paged_groups, &$group_ids, $type = false ) { |
| 1343 | public static function get_group_extras( &$paged_groups, &$group_ids, $type = false, $user_id = false ) { |
1344 | 1344 | global $wpdb; |
1345 | 1345 | |
1346 | | if ( empty( $group_ids ) ) |
| 1346 | if ( empty( $group_ids ) ) { |
1347 | 1347 | return $paged_groups; |
| 1348 | } |
| 1349 | |
| 1350 | $user_id = empty( $user_id ) ? bp_loggedin_user_id() : $user_id; |
1348 | 1351 | |
1349 | 1352 | $bp = buddypress(); |
1350 | 1353 | |
1351 | 1354 | // Sanitize group IDs. |
1352 | 1355 | $group_ids = implode( ',', wp_parse_id_list( $group_ids ) ); |
1353 | 1356 | |
1354 | | // Fetch the logged-in user's status within each group. |
1355 | | if ( is_user_logged_in() ) { |
1356 | | $user_status_results = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) ); |
| 1357 | // Fetch the user's status within each group. |
| 1358 | if ( ! empty( $user_id ) ) { |
| 1359 | $extras = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent, is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} )", $user_id ) ); |
1357 | 1360 | } else { |
1358 | | $user_status_results = array(); |
| 1361 | $extras = array(); |
1359 | 1362 | } |
1360 | 1363 | |
1361 | 1364 | // Reindex. |
1362 | 1365 | $user_status = array(); |
1363 | | foreach ( $user_status_results as $user_status_result ) { |
1364 | | $user_status[ $user_status_result->group_id ] = $user_status_result; |
| 1366 | foreach ( $extras as $extra ) { |
| 1367 | $user_status[ $extra->group_id ] = $extra; |
1365 | 1368 | } |
1366 | 1369 | |
| 1370 | // Mock defaults values for extras |
| 1371 | $is_member = $is_invited = $is_pending = '0'; |
| 1372 | $is_banned = false; |
| 1373 | |
1367 | 1374 | for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) { |
1368 | | $is_member = $is_invited = $is_pending = '0'; |
1369 | 1375 | $gid = $paged_groups[ $i ]->id; |
1370 | 1376 | |
1371 | 1377 | if ( isset( $user_status[ $gid ] ) ) { |
1372 | | |
1373 | | // The is_confirmed means the user is a member. |
1374 | 1378 | if ( $user_status[ $gid ]->is_confirmed ) { |
1375 | 1379 | $is_member = '1'; |
| 1380 | } |
1376 | 1381 | |
1377 | | // The invite_sent means the user has been invited. |
1378 | | } elseif ( $user_status[ $gid ]->invite_sent ) { |
| 1382 | if ( $user_status[ $gid ]->invite_sent ) { |
1379 | 1383 | $is_invited = '1'; |
| 1384 | } |
1380 | 1385 | |
1381 | | // User has sent request, but has not been confirmed. |
1382 | | } else { |
| 1386 | // If isn't member and invited update pending flag. |
| 1387 | if ( '1' !== $is_member && '1' !== $is_invited ) { |
1383 | 1388 | $is_pending = '1'; |
1384 | 1389 | } |
| 1390 | |
| 1391 | // If user is banned reset extras to default values. |
| 1392 | if ( $user_status[ $gid ]->is_banned ) { |
| 1393 | $is_member = $is_invited = $is_pending = '0'; |
| 1394 | $is_banned = true; |
| 1395 | } |
1385 | 1396 | } |
1386 | 1397 | |
1387 | | $paged_groups[ $i ]->is_member = $is_member; |
| 1398 | $paged_groups[ $i ]->is_member = $is_member; |
1388 | 1399 | $paged_groups[ $i ]->is_invited = $is_invited; |
1389 | 1400 | $paged_groups[ $i ]->is_pending = $is_pending; |
1390 | | } |
1391 | | |
1392 | | if ( is_user_logged_in() ) { |
1393 | | $user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", bp_loggedin_user_id() ) ); |
1394 | | } else { |
1395 | | $user_banned = array(); |
1396 | | } |
1397 | | |
1398 | | for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) { |
1399 | | $paged_groups[$i]->is_banned = false; |
1400 | | |
1401 | | foreach ( (array) $user_banned as $group_id ) { |
1402 | | if ( $group_id == $paged_groups[$i]->id ) { |
1403 | | $paged_groups[$i]->is_banned = true; |
1404 | | } |
1405 | | } |
| 1401 | $paged_groups[ $i ]->is_banned = $is_banned; |
1406 | 1402 | } |
1407 | 1403 | |
1408 | 1404 | return $paged_groups; |