Ticket #6431: class-bp-groups-group.php.patch
File class-bp-groups-group.php.patch, 3.0 KB (added by , 9 years ago) |
---|
-
bp-groups/classes/class-bp-groups-group.php
925 925 926 926 // Populate some extra information instead of querying each time in the loop 927 927 if ( !empty( $r['populate_extras'] ) ) { 928 $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'] 928 $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'],$r['user_id']); 929 929 } 930 930 931 931 // Grab all groupmeta … … 1352 1352 * 1353 1353 * Data fetched: 1354 1354 * 1355 * - Logged-in user's status within each group (is_member,1356 * is_confirmed, is_pending, is_banned) 1355 * - User's status within each group (is_member, 1356 * is_confirmed, is_pending, is_banned). If $user_id is false the logged in user is used 1357 1357 * 1358 1358 * @param array $paged_groups Array of groups. 1359 1359 * @param string|array Array or comma-separated list of IDs matching 1360 1360 * $paged_groups. 1361 1361 * @param string $type Not used. 1362 * @param int $user_id The id for the user. 1362 1363 * @return array $paged_groups 1363 1364 */ 1364 public static function get_group_extras( &$paged_groups, &$group_ids, $type = false ) {1365 public static function get_group_extras( &$paged_groups, &$group_ids, $type = false, $user_id=false ) 1365 1366 global $wpdb; 1366 1367 1367 1368 if ( empty( $group_ids ) ) … … 1372 1373 // Sanitize group IDs 1373 1374 $group_ids = implode( ',', wp_parse_id_list( $group_ids ) ); 1374 1375 1375 // Fetch the logged-in user's status within each group 1376 if ( is_user_logged_in() ) { 1377 $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() ) ); 1376 if ( $user_id ) { 1377 $user_id = esc_sql( $user_id ); 1378 } 1379 else { 1380 if ( is_user_logged_in() ) { 1381 $user_id = bp_loggedin_user_id(); 1382 } 1383 } 1384 1385 // Fetch the user's status within each group 1386 if ( ! empty( $user_id ) ) { 1387 $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", $user_id)); 1378 1388 } else { 1379 1389 $user_status_results = array(); 1380 1390 } … … 1410 1420 $paged_groups[ $i ]->is_pending = $is_pending; 1411 1421 } 1412 1422 1413 if ( is_user_logged_in() ) {1414 $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() ));1423 if ( ! empty( $user_id ) ) { 1424 $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} )", $user_id)); 1415 1425 } else { 1416 1426 $user_banned = array(); 1417 1427 }