bbp_get_dropdown

Output a select box allowing to pick which forum/topic a new topic/reply belongs in.

Description

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

Returns (string)

The dropdown

Parameters (1)

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

Usage

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

Defined (1)

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

/includes/common/template.php  
  1. function bbp_get_dropdown( $args = '' ) { 
  2.  
  3. /** Arguments *********************************************************/ 
  4.  
  5. // Parse arguments against default values 
  6. $r = bbp_parse_args( $args, array( 
  7. 'post_type' => bbp_get_forum_post_type(),  
  8. 'post_parent' => null,  
  9. 'post_status' => null,  
  10. 'selected' => 0,  
  11. 'exclude' => array(),  
  12. 'numberposts' => -1,  
  13. 'orderby' => 'menu_order title',  
  14. 'order' => 'ASC',  
  15. walker => '',  
  16.  
  17. // Output-related 
  18. 'select_id' => 'bbp_forum_id',  
  19. 'tab' => bbp_get_tab_index(),  
  20. 'options_only' => false,  
  21. 'show_none' => false,  
  22. 'disable_categories' => true,  
  23. 'disabled' => '' 
  24. ), 'get_dropdown' ); 
  25.  
  26. if ( empty( $r[walker] ) ) { 
  27. $r[walker] = new BBP_Walker_Dropdown(); 
  28. $r[walker]->tree_type = $r['post_type']; 
  29.  
  30. // Force 0 
  31. if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) { 
  32. $r['selected'] = 0; 
  33.  
  34. // Force array 
  35. if ( !empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) { 
  36. $r['exclude'] = explode( ', ', $r['exclude'] ); 
  37.  
  38. /** Setup variables ***************************************************/ 
  39.  
  40. $retval = ''; 
  41. $posts = get_posts( array( 
  42. 'post_type' => $r['post_type'],  
  43. 'post_status' => $r['post_status'],  
  44. 'exclude' => $r['exclude'],  
  45. 'post_parent' => $r['post_parent'],  
  46. 'numberposts' => $r['numberposts'],  
  47. 'orderby' => $r['orderby'],  
  48. 'order' => $r['order'],  
  49. walker => $r[walker],  
  50. 'disable_categories' => $r['disable_categories'] 
  51. ) ); 
  52.  
  53. /** Drop Down *********************************************************/ 
  54.  
  55. // Build the opening tag for the select element 
  56. if ( empty( $r['options_only'] ) ) { 
  57.  
  58. // Should this select appear disabled? 
  59. $disabled = disabled( isset(bbpress)->options[ $r['disabled'] ] ), true, false ); 
  60.  
  61. // Setup the tab index attribute 
  62. $tab = !empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : ''; 
  63.  
  64. // Open the select tag 
  65. $retval .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '"' . $disabled . $tab . '>' . "\n"; 
  66.  
  67. // Display a leading 'no-value' option, with or without custom text 
  68. if ( !empty( $r['show_none'] ) || !empty( $r['none_found'] ) ) { 
  69.  
  70. // Open the 'no-value' option tag 
  71. $retval .= "\t<option value=\"\" class=\"level-0\">"; 
  72.  
  73. // Use deprecated 'none_found' first for backpat 
  74. if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) { 
  75. $retval .= esc_html( $r['none_found'] ); 
  76.  
  77. // Use 'show_none' second 
  78. } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) { 
  79. $retval .= esc_html( $r['show_none'] ); 
  80.  
  81. // Otherwise, make some educated guesses 
  82. } else { 
  83.  
  84. // Switch the response based on post type 
  85. switch ( $r['post_type'] ) { 
  86.  
  87. // Topics 
  88. $retval .= esc_html__( 'No topics available', bbpress ); 
  89. break; 
  90.  
  91. // Forums 
  92. $retval .= esc_html__( 'No forums available', bbpress ); 
  93. break; 
  94.  
  95. // Any other 
  96. default : 
  97. $retval .= esc_html__( 'None available', bbpress ); 
  98. break; 
  99.  
  100. // Close the 'no-value' option tag 
  101. $retval .= '</option>'; 
  102.  
  103. // Items found so walk the tree 
  104. if ( !empty( $posts ) ) { 
  105. $retval .= walk_page_dropdown_tree( $posts, 0, $r ); 
  106.  
  107. // Close the selecet tag 
  108. if ( empty( $r['options_only'] ) ) { 
  109. $retval .= '</select>'; 
  110.  
  111. return apply_filters( 'bbp_get_dropdown', $retval, $r );