bp_get_new_group_invite_friend_list

Return a list of friends who can be invited to a group.

Description

(false|string) bp_get_new_group_invite_friend_list( (array) $args = array() ); 

Returns (false|string)

HTML list of checkboxes, or false

Parameters (1)

0. $args — Optional. (array) => array()
Array of arguments for friends list output.

Usage

  1. if ( !function_exists( 'bp_get_new_group_invite_friend_list' ) ) { 
  2. require_once '/bp-groups/bp-groups-template.php'; 
  3.  
  4. // Array of arguments for friends list output. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_new_group_invite_friend_list($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-groups/bp-groups-template.php  
  1. function bp_get_new_group_invite_friend_list( $args = array() ) { 
  2.  
  3. // Bail if no friends component. 
  4. if ( ! bp_is_active( 'friends' ) ) { 
  5. return false; 
  6.  
  7. // Parse arguments. 
  8. $r = wp_parse_args( $args, array( 
  9. 'user_id' => bp_loggedin_user_id(),  
  10. 'group_id' => false,  
  11. 'separator' => 'li' 
  12. ) ); 
  13.  
  14. // No group passed, so look for new or current group ID's. 
  15. if ( empty( $r['group_id'] ) ) { 
  16. $bp = buddypress(); 
  17. $r['group_id'] = ! empty( $bp->groups->new_group_id ) 
  18. ? $bp->groups->new_group_id 
  19. : $bp->groups->current_group->id; 
  20.  
  21. // Setup empty items array. 
  22. $items = array(); 
  23.  
  24. // Get user's friends who are not in this group already. 
  25. $friends = friends_get_friends_invite_list( $r['user_id'], $r['group_id'] ); 
  26.  
  27. if ( ! empty( $friends ) ) { 
  28.  
  29. // Get already invited users. 
  30. $invites = groups_get_invites_for_group( $r['user_id'], $r['group_id'] ); 
  31.  
  32. for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) { 
  33. $checked = in_array( (int) $friends[ $i ]['id'], (array) $invites ); 
  34. $items[] = '<' . $r['separator'] . '><label for="f-' . esc_attr( $friends[ $i ]['id'] ) . '"><input' . checked( $checked, true, false ) . ' type="checkbox" name="friends[]" id="f-' . esc_attr( $friends[ $i ]['id'] ) . '" value="' . esc_attr( $friends[ $i ]['id'] ) . '" /> ' . esc_html( $friends[ $i ]['full_name'] ) . '</label></' . $r['separator'] . '>'; 
  35.  
  36. /** 
  37. * Filters the array of friends who can be invited to a group. 
  38. * @since 2.4.0 
  39. * @param array $items Array of friends. 
  40. * @param array $r Parsed arguments from bp_get_new_group_invite_friend_list() 
  41. * @param array $args Unparsed arguments from bp_get_new_group_invite_friend_list() 
  42. */ 
  43. $invitable_friends = apply_filters( 'bp_get_new_group_invite_friend_list', $items, $r, $args ); 
  44.  
  45. if ( ! empty( $invitable_friends ) && is_array( $invitable_friends ) ) { 
  46. $retval = implode( "\n", $invitable_friends ); 
  47. } else { 
  48. $retval = false; 
  49.  
  50. return $retval;