bp_get_group_type_list( int $group_id, array|string $r = array() )
Return a comma-delimited list of group types.
Parameters Parameters
- $group_id
-
(int) (Required) Group ID. Defaults to current group ID if on a group page.
- $r
-
(array|string) (Optional) Array of parameters. All items are optional.
- 'parent_element'
(string) Element to wrap around the list. Defaults to 'p'. - 'parent_attr'
(array) Element attributes for parent element. Defaults to array( 'class' => 'bp-group-type-list' ). - 'label'
(string|array) Plural and singular labels to add before the list. Defaults to array( 'plural' => 'Group Types:', 'singular' => 'Group Type:' ). - 'label_element'
(string) Element to wrap around the label. Defaults to 'strong'. - 'label_attr'
(array) Element attributes for label element. Defaults to array(). - 'show_all'
(bool) Whether to show all registered group types. Defaults to 'false'. If 'false', only shows group types with the 'show_in_list' parameter set to true. See bp_groups_register_group_type() for more info.
Default value: array()
- 'parent_element'
Return Return
(string)
Source Source
File: bp-groups/bp-groups-template.php
function bp_get_group_type_list( $group_id = 0, $r = array() ) { if ( empty( $group_id ) ) { $group_id = bp_get_current_group_id(); } $r = bp_parse_args( $r, array( 'parent_element' => 'p', 'parent_attr' => array( 'class' => 'bp-group-type-list', ), 'label' => array(), 'label_element' => 'strong', 'label_attr' => array(), 'show_all' => false, 'list_element' => '', 'list_element_attr' => array(), ), 'group_type_list' ); // Should the label be output? $has_label = ! empty( $r['label'] ); // Ensure backward compatibility in case developers are still using a string. if ( ! is_array( $r['label'] ) ) { $r['label'] = array( 'plural' => __( 'Group Types:', 'buddypress' ), ); } $labels = wp_parse_args( $r['label'], array( 'plural' => __( 'Group Types:', 'buddypress' ), 'singular' => __( 'Group Type:', 'buddypress' ), ) ); $retval = ''; if ( $types = bp_groups_get_group_type( $group_id, false ) ) { // Make sure we can show the type in the list. if ( false === $r['show_all'] ) { $types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types ); if ( empty( $types ) ) { return $retval; } } $before = $after = $label = ''; $count = count( $types ); if ( 1 === $count ) { $label_text = $labels['singular']; } else { $label_text = $labels['plural']; } // Render parent element. if ( ! empty( $r['parent_element'] ) ) { $parent_elem = new BP_Core_HTML_Element( array( 'element' => $r['parent_element'], 'attr' => $r['parent_attr'], ) ); // Set before and after. $before = $parent_elem->get( 'open_tag' ); $after = $parent_elem->get( 'close_tag' ); } // Render label element. if ( ! empty( $r['label_element'] ) ) { $label = new BP_Core_HTML_Element( array( 'element' => $r['label_element'], 'attr' => $r['label_attr'], 'inner_html' => esc_html( $label_text ), ) ); $label = $label->contents() . ' '; // No element, just the label. } elseif ( $has_label ) { $label = esc_html( $label_text ); } // The list of types. $list = implode( ', ', array_map( 'bp_get_group_type_directory_link', $types ) ); // Render the list of types element. if ( ! empty( $r['list_element'] ) ) { $list_element = new BP_Core_HTML_Element( array( 'element' => $r['list_element'], 'attr' => $r['list_element_attr'], 'inner_html' => $list, ) ); $list = $list_element->contents(); } // Comma-delimit each type into the group type directory link. $label .= $list; // Retval time! $retval = $before . $label . $after; } return $retval; }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
7.0.0 | The $r['label'] argument now also accept an array containing the plural & singular labels to use according to the Group's number of group types it is assigned to. |
2.7.0 | Introduced. |