function publish_categories($args){
$taxonomies=get_taxonomies( array('public' => true) , 'names');
if (isset($args['allowed_taxonomies'])){
$allowed = explode(',',$args['allowed_taxonomies']);
} else {
$allowed = array('category','post_tag');
}
$taxonomies = array_intersect( $taxonomies, $allowed );
foreach ($taxonomies as $taxonomy ) {
$the_tax = get_taxonomy( $taxonomy );
$terms = get_terms( $taxonomy , array('hide_empty' => 0));
if ($terms) {
$array["optgroup_b_{$taxonomy}"] = $the_tax->labels->name;
foreach($terms as $term) {
$array["" . $term->slug . "#" . $taxonomy . ""] = $term->name;
}
$array["optgroup_e_{$taxonomy}"] = $the_tax->labels->name;
}
}
return $array;
}
/* set categories */
case 'post_categories':
$options = publish_categories($args);
$res .= "<select name='".$key.'-'.$i.'[]'."' multiple='multiple' class='chosen-select' data-custom-error='".__('Please choose a category at least','userpro')."' data-required='".$args['require_category']."' data-placeholder='".$placeholder."'>";
foreach($options as $k=>$v) {
if (strstr($k, 'optgroup_b')) {
$res .= "<optgroup label='$v'>";
} elseif (strstr($k, 'optgroup_e')) {
$res .= "</optgroup>";
} else {
$res .= "<option value='$k'>$v</option>";
}
}
$res .= "</select>";
break;