<?php
/* Forked version of wp_dropdown_categories() */
function mfields_dropdown_taxonomy_terms( $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 );
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
}
$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 = ( !empty( $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 .= mfields_walk_taxonomy_dropdown_tree( $categories, $depth, $r );
$output .= "</select>\n";
}
$output = apply_filters( 'wp_dropdown_cats', $output );
if ( $echo )
echo $output;
return $output;
}
/* Forked version of walk_category_dropdown_tree() */
function mfields_walk_taxonomy_dropdown_tree() {
$args = func_get_args();
// the user's options are the third parameter
if ( empty( $args[2]['walker'] ) || !is_a( $args[2]['walker'], 'Walker' ) )
$walker = new mfields_walker_taxonomy_dropdown;
else
$walker = $args[2]['walker'];
return call_user_func_array( array( &$walker, 'walk' ), $args );
}
/* Forked version of Walker_CategoryDropdown */
class mfields_walker_taxonomy_dropdown extends Walker {
var $tree_type = 'category';
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
function start_el( &$output, $category, $depth, $args ) {
$pad = str_repeat( ' ', $depth * 3 );
$cat_name = apply_filters( 'list_cats', $category->name, $category );
if( $category->taxonomy === 'category' )
$value = esc_attr( $category->term_id );
else
$value = esc_attr( $category->slug );
$output .= "\t<option class=\"level-$depth\" value=\"" . $value . "\"";
if ( $category->taxonomy === 'category' ) {
if ( $category->term_id == $args['selected'] )
$output .= ' selected="selected"';
}
else {
if ( $category->slug == $args['selected'] )
$output .= ' selected="selected"';
}
$output .= '>';
$output .= $pad . $cat_name;
if ( $args['show_count'] )
$output .= ' ('. $category->count .')';
if ( $args['show_last_update'] ) {
$format = 'Y-m-d';
$output .= ' ' . gmdate( $format, $category->last_update_timestamp );
}
$output .= "</option>\n";
}
}
?>