bp_get_member_type_list( int $user_id, array|string $r = array() )

Return a comma-delimited list of member types.


Parameters Parameters

$user_id

(int) (Required) User ID. Defaults to displayed user ID if on a member 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-member-type-list' ).
  • 'label'
    (array) Plural and singular labels to use before the list. Defaults to array( 'plural' => 'Member Types:', 'singular' => 'Member 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 member types with the 'show_in_list' parameter set to true. See bp_register_member_type() for more info.
  • 'list_element'
    (string) Element to wrap around the comma separated list of membet types. Defaults to ''.
  • 'list_element_attr'
    (string) Element attributes for list element. Defaults to array().

Default value: array()


Top ↑

Return Return

(string)


Source Source

File: bp-members/bp-members-template.php

	function bp_get_member_type_list( $user_id = 0, $r = array() ) {
		if ( empty( $user_id ) ) {
			$user_id = bp_displayed_user_id();
		}

		$r = bp_parse_args(
			$r,
			array(
				'parent_element'    => 'p',
				'parent_attr'       => array(
					'class' => 'bp-member-type-list',
				),
				'label'             => array(),
				'label_element'     => 'strong',
				'label_attr'        => array(),
				'show_all'          => false,
				'list_element'      => '',
				'list_element_attr' => array(),
			),
			'member_type_list'
		);

		// Should the label be output?
		$has_label = ! empty( $r['label'] );

		$labels = wp_parse_args(
			$r['label'],
			array(
				'plural'   => __( 'Member Types:', 'buddypress' ),
				'singular' => __( 'Member Type:', 'buddypress' ),
			)
		);

		$retval = '';
		$types  = bp_get_member_type( $user_id, false );

		if ( $types ) {
			// Make sure we can show the type in the list.
			if ( false === $r['show_all'] ) {
				$types = array_intersect( bp_get_member_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_member_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;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.