bp_get_group_type_list

Return a comma-delimited list of group types.

Description

(string) bp_get_group_type_list( (int) $group_id = 0, (array) $r = array() ); 

Returns (string)

Parameters (2)

0. $group_id — Optional. (int)
Group ID. Defaults to current group ID if on a group page.
1. $r — Optional. (array) => array()
Array of parameters. All items are optional.

Options

  • parent_element (string) => 'p'

    Element to wrap around the list.

  • parent_attr (array) => 'class'

    Element attributes for parent element.

  • label (string) => 'Group Types:'

    Label to add before the list.

  • label_element (string) => 'strong'

    Element to wrap around the label.

  • label_attr (array) => to array()

    Element attributes for label element.

array(

    /**
     * Element to wrap around the list.
     *
     * @type string
     * @default 'p'
     */
    'parent_element' => 'p',

    /**
     * Element attributes for parent element.
     *
     * @type array
     * @default 'class'
     */
    'parent_attr' => 'class',

    /**
     * Label to add before the list.
     *
     * @type string
     * @default 'Group Types:'
     */
    'label' => 'Group Types:',

    /**
     * Element to wrap around the label.
     *
     * @type string
     * @default 'strong'
     */
    'label_element' => 'strong',

    /**
     * Element attributes for label element.
     *
     * @type array
     * @default to array()
     */
    'label_attr' => to array()
);        


Usage

  1. if ( !function_exists( 'bp_get_group_type_list' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-groups/bp-groups-template.php'; 
  3.  
  4. // Group ID. Defaults to current group ID if on a group page. 
  5. $group_id = -1; 
  6.  
  7. // Array of parameters. All items are optional. 
  8. $r = array( 
  9. 'parent_element' => 'p', 
  10. 'parent_attr' => 'class', 
  11. 'label' => 'Group Types:', 
  12. 'label_element' => 'strong', 
  13. 'label_attr' => to array() 
  14. ); 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bp_get_group_type_list($group_id, $r); 
  18.  

Defined (1)

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

/bp-groups/bp-groups-template.php  
  1. function bp_get_group_type_list( $group_id = 0, $r = array() ) { 
  2. if ( empty( $group_id ) ) { 
  3. $group_id = bp_get_current_group_id(); 
  4.  
  5. $r = bp_parse_args( $r, array( 
  6. 'parent_element' => 'p',  
  7. 'parent_attr' => array( 
  8. 'class' => 'bp-group-type-list',  
  9. ),  
  10. 'label' => __( 'Group Types:', buddypress ),  
  11. 'label_element' => 'strong',  
  12. 'label_attr' => array(),  
  13. 'show_all' => false,  
  14. ), 'group_type_list' ); 
  15.  
  16. $retval = ''; 
  17.  
  18. if ( $types = bp_groups_get_group_type( $group_id, false ) ) { 
  19. // Make sure we can show the type in the list. 
  20. if ( false === $r['show_all'] ) { 
  21. $types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types ); 
  22. if ( empty( $types ) ) { 
  23. return $retval; 
  24.  
  25. $before = $after = $label = ''; 
  26.  
  27. // Render parent element. 
  28. if ( ! empty( $r['parent_element'] ) ) { 
  29. $parent_elem = new BP_Core_HTML_Element( array( 
  30. 'element' => $r['parent_element'],  
  31. 'attr' => $r['parent_attr'] 
  32. ) ); 
  33.  
  34. // Set before and after. 
  35. $before = $parent_elem->get( 'open_tag' ); 
  36. $after = $parent_elem->get( 'close_tag' ); 
  37.  
  38. // Render label element. 
  39. if ( ! empty( $r['label_element'] ) ) { 
  40. $label = new BP_Core_HTML_Element( array( 
  41. 'element' => $r['label_element'],  
  42. 'attr' => $r['label_attr'],  
  43. 'inner_html' => esc_html( $r['label'] ) 
  44. ) ); 
  45. $label = $label->contents() . ' '; 
  46.  
  47. // No element, just the label. 
  48. } else { 
  49. $label = esc_html( $r['label'] ); 
  50.  
  51. // Comma-delimit each type into the group type directory link. 
  52. $label .= implode( ', ', array_map( 'bp_get_group_type_directory_link', $types ) ); 
  53.  
  54. // Retval time! 
  55. $retval = $before . $label . $after; 
  56.  
  57. return $retval;