| 2470 | /** |
| 2471 | * Renders a list of all the registered activity types for use in a <select> element, or as <input type="checkbox">. |
| 2472 | * |
| 2473 | * @param string $output Optional. Either 'select' or 'checkbox'. Defaults to select. |
| 2474 | * @param string|array $args Optional extra arguments: |
| 2475 | * checkbox_name - Used when type=checkbox. Sets the item's name property. |
| 2476 | * selected - Array of strings of activity types to mark as selected/checked. |
| 2477 | * @since BuddyPress (1.7) |
| 2478 | */ |
| 2479 | function bp_activity_types_list( $output = 'select', $args = '' ) { |
| 2480 | $defaults = array( |
| 2481 | 'checkbox_name' => 'bp_activity_types', |
| 2482 | 'selected' => array(), |
| 2483 | ); |
| 2484 | $args = wp_parse_args( $args, $defaults ); |
| 2485 | |
| 2486 | $activities = bp_activity_get_types(); |
| 2487 | natsort( $activities ); |
| 2488 | |
| 2489 | // Loop through the activity types and output markup |
| 2490 | foreach ( $activities as $type => $description ) { |
| 2491 | |
| 2492 | // See if we need to preselect the current type |
| 2493 | $checked = checked( true, in_array( $type, (array) $args['selected'] ), false ); |
| 2494 | $selected = selected( true, in_array( $type, (array) $args['selected'] ), false ); |
| 2495 | |
| 2496 | if ( 'select' == $output ) |
| 2497 | printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) ); |
| 2498 | |
| 2499 | elseif ( 'checkbox' == $output ) |
| 2500 | printf( '<label style="">%1$s<input type="checkbox" name="%2$s[]" value="%3$s" %4$s/></label>', esc_html( $description ), esc_attr( $args['checkbox_name'] ), esc_attr( $type ), $checked ); |
| 2501 | |
| 2502 | // Allow custom markup |
| 2503 | do_action( 'bp_activity_types_list_' . $output, $args, $type, $description ); |
| 2504 | } |
| 2505 | |
| 2506 | // Backpat with BP-Default for dropdown boxes only |
| 2507 | if ( 'select' == $output ) |
| 2508 | do_action( 'bp_activity_filter_options' ); |
| 2509 | } |
| 2510 | |
| 2511 | |