bbp_get_dropdown( mixed $args = '' )
Output a select box allowing to pick which forum/topic a new topic/reply belongs in.
Description
Parameters
- $args
-
(Optional) The function supports these args: - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum) - selected: Selected ID, to not have any value as selected, pass anything smaller than 0 (due to the nature of select box, the first value would of course be selected - though you can have that as none (pass 'show_none' arg)) - orderby: Defaults to 'menu_order title' - post_parent: Post parent. Defaults to 0 - post_status: Which all post_statuses to find in? Can be an array or CSV of publish, category, closed, private, spam, trash (based on post type) - if not set, these are automatically determined based on the post_type - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get all posts - walker: Which walker to use? Defaults to BBP_Walker_Dropdown - select_id: ID of the select box. Defaults to 'bbp_forum_id' - tab: Tabindex value. False or integer - options_only: Show only <options>? No <select>? - show_none: Boolean or String __( '(No Forum)', 'buddyboss' ) - disable_categories: Disable forum categories and closed forums? Defaults to true. Only for forums and when the category option is displayed.
Default value: ''
Return
(string) The dropdown
Source
File: bp-forums/common/template.php
function bbp_get_dropdown( $args = '' ) { /** Arguments *********************************************************/ // Parse arguments against default values $r = bbp_parse_args( $args, array( 'post_type' => bbp_get_forum_post_type(), 'post_parent' => null, 'post_status' => null, 'selected' => 0, 'exclude' => array(), 'numberposts' => - 1, 'orderby' => 'menu_order title', 'order' => 'ASC', 'walker' => '', // Output-related 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => false, 'show_none_default_val' => '', 'disable_categories' => true, 'disabled' => '', ), 'get_dropdown' ); if ( empty( $r['walker'] ) ) { $r['walker'] = new BBP_Walker_Dropdown(); $r['walker']->tree_type = $r['post_type']; } // Force 0 if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) { $r['selected'] = 0; } // Force array if ( !empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) { $r['exclude'] = explode( ',', $r['exclude'] ); } /** Setup variables ***************************************************/ $retval = ''; $posts = get_posts( array( 'post_type' => $r['post_type'], 'post_status' => $r['post_status'], 'exclude' => $r['exclude'], 'post_parent' => $r['post_parent'], 'numberposts' => $r['numberposts'], 'orderby' => $r['orderby'], 'order' => $r['order'], 'walker' => $r['walker'], 'disable_categories' => $r['disable_categories'] ) ); /** Drop Down *********************************************************/ // Build the opening tag for the select element if ( empty( $r['options_only'] ) ) { // Should this select appear disabled? $disabled = disabled( isset( bbpress()->options[ $r['disabled'] ] ), true, false ); // Setup the tab index attribute $tab = !empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : ''; // Open the select tag $retval .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '"' . $disabled . $tab . '>' . "\n"; } // Display a leading 'no-value' option, with or without custom text if ( !empty( $r['show_none'] ) || !empty( $r['none_found'] ) ) { // Set none field value. $val = $r['show_none_default_val']; // Open the 'no-value' option tag $retval .= "\t<option value=\"$val\" class=\"level-0\">"; // Use deprecated 'none_found' first for backpat if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) { $retval .= esc_html( $r['none_found'] ); // Use 'show_none' second } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) { $retval .= esc_html( $r['show_none'] ); // Otherwise, make some educated guesses } else { // Switch the response based on post type switch ( $r['post_type'] ) { // Topics case bbp_get_topic_post_type() : $retval .= esc_html__( 'No discussions available', 'buddyboss' ); break; // Forums case bbp_get_forum_post_type() : $retval .= esc_html__( 'No forums available', 'buddyboss' ); break; // Any other default : $retval .= esc_html__( 'None available', 'buddyboss' ); break; } } // Close the 'no-value' option tag $retval .= '</option>'; } // Items found so walk the tree if ( !empty( $posts ) ) { add_filter( 'list_pages', 'bbp_reply_attributes_meta_box_discussion_reply_title', 999, 2 ); unset( $r['walker']); $retval .= walk_page_dropdown_tree( $posts, 0, $r ); remove_filter( 'list_pages', 'bbp_reply_attributes_meta_box_discussion_reply_title', 999, 2 ); } // Close the selecet tag if ( empty( $r['options_only'] ) ) { $retval .= '</select>'; } return apply_filters( 'bbp_get_dropdown', $retval, $r ); }
Changelog
Version | Description |
---|---|
bbPress (r2746) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.