bp_docs_associated_group_summary

Display a summary of the associated group.

Description

bp_docs_associated_group_summary( (int) $group_id = 0 ); 

Parameters (1)

0. $group_id — Optional. (int)
The group id.

Usage

  1. if ( !function_exists( 'bp_docs_associated_group_summary' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-docs/includes/templatetags.php'; 
  3.  
  4. // The group id. 
  5. $group_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_docs_associated_group_summary($group_id); 
  9.  

Defined (1)

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

/includes/templatetags.php  
  1. function bp_docs_associated_group_summary( $group_id = 0 ) { 
  2. $html = ''; 
  3.  
  4. if ( ! $group_id ) { 
  5. if ( isset( $_GET['group'] ) ) { 
  6. $group_slug = $_GET['group']; 
  7. $group_id = BP_Groups_Group::get_id_from_slug( $group_slug ); 
  8. } else { 
  9. $doc_id = is_singular() ? get_the_ID() : 0; 
  10. $group_id = bp_docs_get_associated_group_id( $doc_id ); 
  11.  
  12. $group_id = intval( $group_id ); 
  13. if ( $group_id ) { 
  14. $group = groups_get_group( array( 'group_id' => $group_id ) ); 
  15.  
  16. if ( ! empty( $group->name ) ) { 
  17. $group_link = esc_url( bp_get_group_permalink( $group ) ); 
  18. $group_avatar = bp_core_fetch_avatar( array( 
  19. 'item_id' => $group_id,  
  20. 'object' => 'group',  
  21. 'type' => 'thumb',  
  22. 'width' => '40',  
  23. 'height' => '40',  
  24. ) ); 
  25. $_count = (int) groups_get_groupmeta( $group_id, 'total_member_count' ); 
  26. if ( 1 === $_count ) { 
  27. // Using sprintf() to avoid creating another string. 
  28. $group_member_count = sprintf( __( '%s member', 'bp-docs', $_count ), number_format_i18n( $_count ) ); 
  29. } else { 
  30. $group_member_count = sprintf( _n( '%s member', '%s members', $_count, 'bp-docs' ), number_format_i18n( $_count ) ); 
  31.  
  32. switch ( $group->status ) { 
  33. case 'public' : 
  34. $group_type_string = __( 'Public Group', 'bp-docs' ); 
  35. break; 
  36.  
  37. case 'private' : 
  38. $group_type_string = __( 'Private Group', 'bp-docs' ); 
  39. break; 
  40.  
  41. case 'hidden' : 
  42. $group_type_string = __( 'Hidden Group', 'bp-docs' ); 
  43. break; 
  44.  
  45. default : 
  46. $group_type_string = ''; 
  47. break; 
  48.  
  49. $html .= '<a href="' . $group_link . '">' . $group_avatar . '</a>'; 
  50.  
  51. $html .= '<div class="item">'; 
  52. $html .= '<a href="' . $group_link . '">' . esc_html( $group->name ) . '</a>'; 
  53. $html .= '<div class="meta">' . $group_type_string . ' / ' . $group_member_count . '</div>'; 
  54. $html .= '</div>'; 
  55.  
  56.  
  57. echo $html;