bp_activity_types_list

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

Description

bp_activity_types_list( (string) $output = 'select', (string) $args = '' ); 

Parameters (2)

0. $output — Optional. (string) => 'select'
Either select or checkbox.. Default: select .
1. $args — Optional. (string) => ''
Extra arguments.

Options

  • checkbox_name (string) => ''

    When returning checkboxes, sets the name attribute.

array(

    /**
     * When returning checkboxes, sets the 'name' attribute.
     *
     * @type string
     * @default ''
     */
    'checkbox_name' => ''
);        


Usage

  1. if ( !function_exists( 'bp_activity_types_list' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-template.php'; 
  3.  
  4. // Optional. Either 'select' or 'checkbox'. Default: 'select'. 
  5. $output = 'select'; 
  6.  
  7. // Optional extra arguments. 
  8. $args = array( 
  9. 'checkbox_name' => '' 
  10. ); 
  11.  
  12. // NOTICE! Understand what this does before running. 
  13. $result = bp_activity_types_list($output, $args); 
  14.  

Defined (1)

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

/bp-activity/bp-activity-template.php  
  1. function bp_activity_types_list( $output = 'select', $args = '' ) { 
  2.  
  3. $args = bp_parse_args( $args, array( 
  4. 'checkbox_name' => 'bp_activity_types',  
  5. 'selected' => array(),  
  6. ) ); 
  7.  
  8. $activities = bp_activity_get_types(); 
  9. natsort( $activities ); 
  10.  
  11. // Loop through the activity types and output markup. 
  12. foreach ( $activities as $type => $description ) { 
  13.  
  14. // See if we need to preselect the current type. 
  15. $checked = checked( true, in_array( $type, (array) $args['selected'] ), false ); 
  16. $selected = selected( true, in_array( $type, (array) $args['selected'] ), false ); 
  17.  
  18. // Switch output based on the element. 
  19. switch ( $output ) { 
  20. case 'select' : 
  21. printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) ); 
  22. break; 
  23. case 'checkbox' : 
  24. 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 ); 
  25. break; 
  26.  
  27. /** 
  28. * Fires at the end of the listing of activity types. 
  29. * This is a variable action hook. The actual hook to use will depend on the output type specified. 
  30. * Two default hooks are bp_activity_types_list_select and bp_activity_types_list_checkbox. 
  31. * @since 1.7.0 
  32. * @param array $args Array of arguments passed into function. 
  33. * @param string $type Activity type being rendered in the output. 
  34. * @param string $description Description of the activity type being rendered. 
  35. */ 
  36. do_action( 'bp_activity_types_list_' . $output, $args, $type, $description ); 
  37.  
  38. // Backpat with BP-Default for dropdown boxes only. 
  39. if ( 'select' === $output ) {