bp_activity_types_list( string $output = 'select', array|string $args = '' )

Echo a list of all registered activity types for use in dropdowns or checkbox lists.


Description Description


Parameters Parameters

$output

(Optional) Either 'select' or 'checkbox'. Default: 'select'.

Default value: 'select'

$args

(Optional) Optional extra arguments.

  • 'checkbox_name'
    (string) When returning checkboxes, sets the 'name' attribute.
  • 'selected'
    (array|string) A list of types that should be checked/ selected.

Default value: ''


Top ↑

Source Source

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

function bp_activity_types_list( $output = 'select', $args = '' ) {

	$args = bp_parse_args( $args, array(
		'checkbox_name' => 'bp_activity_types',
		'selected'      => array(),
	) );

	$activities = bp_activity_get_types();
	natsort( $activities );

	// Loop through the activity types and output markup.
	foreach ( $activities as $type => $description ) {

		// See if we need to preselect the current type.
		$checked  = checked(  true, in_array( $type, (array) $args['selected'] ), false );
		$selected = selected( true, in_array( $type, (array) $args['selected'] ), false );

		// Switch output based on the element.
		switch ( $output ) {
			case 'select' :
				printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) );
				break;
			case 'checkbox' :
				printf( '<label style="" for="%1$s[]">%2$s<input type="checkbox" id="%1$s[]" name="%1$s[]" value="%3$s" %4$s/></label>', esc_attr( $args['checkbox_name'] ), esc_html( $description ), esc_attr( $args['checkbox_name'] ), esc_attr( $args['checkbox_name'] ), esc_attr( $type ), $checked );
				break;
		}

		/**
		 * Fires at the end of the listing of activity types.
		 *
		 * This is a variable action hook. The actual hook to use will depend on the output type specified.
		 * Two default hooks are bp_activity_types_list_select and bp_activity_types_list_checkbox.
		 *
		 * @since 1.7.0
		 *
		 * @param array  $args        Array of arguments passed into function.
		 * @param string $type        Activity type being rendered in the output.
		 * @param string $description Description of the activity type being rendered.
		 */
		do_action( 'bp_activity_types_list_' . $output, $args, $type, $description );
	}

	// Backpat with BP-Default for dropdown boxes only.
	if ( 'select' === $output ) {
		do_action( 'bp_activity_filter_options' );
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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