function cp_dropdown_categories_prices($args = '') { $defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0); $defaults['selected'] = is_category() ? get_query_var('cat') : 0; $r = wp_parse_args($args, $defaults); $r['include_last_update_time'] = $r['show_last_update']; extract($r); $tab_index_attribute = ''; if ((int) $tab_index > 0) { $tab_index_attribute = " tabindex=\"{$tab_index}\""; } $categories = get_categories($r); $name = esc_attr($name); $class = esc_attr($class); $id = $id ? esc_attr($id) : $name; $output = ''; if (!empty($categories)) { $output = "<select name='{$name}' id='{$id}' class='{$class}' {$tab_index_attribute}>\n"; if ($show_option_all) { $show_option_all = apply_filters('list_cats', $show_option_all); $selected = '0' === strval($r['selected']) ? " selected='selected'" : ''; $output .= "\t<option value='0'{$selected}>{$show_option_all}</option>\n"; } if ($show_option_none) { $show_option_none = apply_filters('list_cats', $show_option_none); $selected = '-1' === strval($r['selected']) ? " selected='selected'" : ''; $output .= "\t<option value='-1'{$selected}>{$show_option_none}</option>\n"; } if ($hierarchical) { $depth = $r['depth']; } else { $depth = -1; } // Flat. $output .= cp_category_dropdown_tree($categories, $depth, $r); $output .= "</select>\n"; } $output = apply_filters('wp_dropdown_cats', $output); if ($echo) { echo $output; } return $output; }
function cp_dropdown_categories_prices($args = '') { $defaults = array('show_option_all' => '', 'show_option_none' => __('Select one', APP_TD), 'orderby' => 'name', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 0, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 1, 'name' => 'cat', 'id' => 'ad_cat_id', 'class' => 'dropdownlist', 'depth' => 1, 'tab_index' => 0, 'taxonomy' => APP_TAX_CAT); $defaults['selected'] = is_category() ? get_query_var('cat') : 0; // auto select the parent category if available if (empty($defaults['selected']) && !empty($_GET['action']) && 'change' == $_GET['action']) { $checkout = appthemes_get_checkout(); $listing_id = $checkout ? $checkout->get_data('listing_id') : false; if ($listing_id) { $listing = get_post($listing_id); $categories = wp_get_post_terms($listing->ID, APP_TAX_CAT); $defaults['selected'] = !empty($categories) ? $categories[0]->parent ? $categories[0]->parent : $categories[0]->term_id : 0; } } $r = wp_parse_args($args, $defaults); $r['include_last_update_time'] = $r['show_last_update']; extract($r); $tab_index_attribute = ''; if ((int) $tab_index > 0) { $tab_index_attribute = " tabindex=\"{$tab_index}\""; } // TODO: remove dirty fix, consider to use 2 parameters array: one for // get_categories() another for cp_category_dropdown_tree() unset($r['name']); $categories = get_categories($r); $name = esc_attr($name); $r['name'] = $name; $class = esc_attr($class); $id = $id ? esc_attr($id) : $name; $output = ''; if (!empty($categories)) { $output = "<select name='{$name}' id='{$id}' class='{$class}' {$tab_index_attribute}>\n"; if ($show_option_all) { $show_option_all = apply_filters('list_cats', $show_option_all); $selected = '0' === strval($r['selected']) ? " selected='selected'" : ''; $output .= "\t<option value='0'{$selected}>{$show_option_all}</option>\n"; } if ($show_option_none) { $show_option_none = apply_filters('list_cats', $show_option_none); $selected = '-1' === strval($r['selected']) ? " selected='selected'" : ''; $output .= "\t<option value='-1'{$selected}>{$show_option_none}</option>\n"; } if ($hierarchical) { $depth = $r['depth']; // Walk the full depth. } else { $depth = -1; // Flat. } $output .= cp_category_dropdown_tree($categories, $depth, $r); $output .= "</select>\n"; } $output = apply_filters('wp_dropdown_cats', $output); if ($echo) { echo $output; } else { return $output; } }