bb_get_forum_dropdown

The BuddyPress bb get forum dropdown function.

Description

bb_get_forum_dropdown( (string) $args = '' ); 

Parameters (1)

0. $args — Optional. (string) => ''
The args.

Usage

  1. if ( !function_exists( 'bb_get_forum_dropdown' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php'; 
  3.  
  4. // The args. 
  5. $args = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_get_forum_dropdown($args); 
  9.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-template.php  
  1. function bb_get_forum_dropdown( $args = '' ) { 
  2. $_args = func_get_args(); 
  3. $defaults = array( 'callback' => false, 'callback_args' => false, 'id' => 'forum_id', 'none' => false, 'selected' => false, 'tab' => false, 'hierarchical' => 1, 'depth' => 0, 'child_of' => 0, 'disable_categories' => 1, 'options_only' => false ); 
  4. if ( $args && is_string($args) && false === strpos($args, '=') ) 
  5. $args = array( 'callback' => $args ); 
  6. if ( 1 < func_num_args() ) 
  7. $args['callback_args'] = $_args[1]; 
  8.  
  9. $args = wp_parse_args( $args, $defaults ); 
  10.  
  11. extract($args, EXTR_SKIP); 
  12.  
  13. if ( !bb_forums( $args ) ) 
  14. return; 
  15.  
  16. global $forum_id, $forum; 
  17. $old_global = $forum; 
  18.  
  19. $name = esc_attr( $id ); 
  20. $id = str_replace( '_', '-', $name ); 
  21. $tab = (int) $tab; 
  22.  
  23. if ( $none && 1 == $none ) 
  24. $none = __('- None -'); 
  25.  
  26. $r = ''; 
  27. if ( !$options_only ) { 
  28. if ( $tab ) { 
  29. $tab = ' tabindex="' . $tab . '"'; 
  30. } else { 
  31. $tab = ''; 
  32. $r .= '<select name="' . $name . '" id="' . $id . '"' . $tab . '>' . "\n"; 
  33. if ( $none ) 
  34. $r .= "\n" . '<option value="0">' . $none . '</option>' . "\n"; 
  35.  
  36. $no_option_selected = true; 
  37. $options = array(); 
  38. while ( $depth = bb_forum() ) : 
  39. global $forum; // Globals + References = Pain 
  40. $pad_left = str_repeat( '   ', $depth - 1 ); 
  41. if ( $disable_categories && isset($forum->forum_is_category) && $forum->forum_is_category ) { 
  42. $options[] = array( 
  43. 'value' => 0,  
  44. 'display' => $pad_left . $forum->forum_name,  
  45. 'disabled' => true,  
  46. 'selected' => false 
  47. ); 
  48. continue; 
  49. $_selected = false; 
  50. if ( (!$selected && $forum_id == $forum->forum_id) || $selected == $forum->forum_id ) { 
  51. $_selected = true; 
  52. $no_option_selected = false; 
  53. $options[] = array( 
  54. 'value' => $forum->forum_id,  
  55. 'display' => $pad_left . $forum->forum_name,  
  56. 'disabled' => false,  
  57. 'selected' => $_selected 
  58. ); 
  59. endwhile; 
  60.  
  61. if ( 1 === count( $options ) && !$none ) { 
  62. foreach ( $options as $option_index => $option_value ) { 
  63. if ( $option_value['disabled'] ) { 
  64. return; 
  65. return '<input type="hidden" name="' . $name . '" id="' . $id . '" value="' . esc_attr( $option_value['value'] ) . '" /><span>' . esc_html( $option_value['display'] ) . '</span>'; 
  66.  
  67. foreach ($options as $option_index => $option_value) { 
  68. if (!$none && !$selected && $no_option_selected && !$option_value['disabled']) { 
  69. $option_value['selected'] = true; 
  70. $no_option_selected = false; 
  71. $option_disabled = $option_value['disabled'] ? ' disabled="disabled"' : ''; 
  72. $option_selected = $option_value['selected'] ? ' selected="selected"' : ''; 
  73. $r .= "\n" . '<option value="' . esc_attr( $option_value['value'] ) . '"' . $option_disabled . $option_selected . '>' . esc_html( $option_value['display'] ) . '</option>' . "\n"; 
  74.  
  75. $forum = $old_global; 
  76. if ( !$options_only ) 
  77. $r .= '</select>' . "\n"; 
  78.  
  79. return $r;