false
);
if ( ! isset( $field['options']['args'] ) )
$field['options']['args'] = $default_args;
else
$field['options']['args'] = wp_parse_args( $field['options']['args'], $default_args );
// Show field as checkbox list by default
if ( ! isset( $field['options']['type'] ) )
$field['options']['type'] = 'checkbox_list';
// If field is shown as checkbox list, add multiple value
if ( in_array( $field['options']['type'], array( 'checkbox_list', 'checkbox_tree', 'select_tree' ) ) )
{
$field['multiple'] = true;
$field['field_name'] = "{$field['id']}[]";
}
if ( in_array( $field['options']['type'], array( 'checkbox_tree', 'select_tree' ) ) )
{
if ( isset( $field['options']['args']['parent'] ) )
{
$field['options']['parent'] = $field['options']['args']['parent'];
unset( $field['options']['args']['parent'] );
}
else
{
$field['options']['parent'] = 0;
}
}
return $field;
}
/**
* Get field HTML
*
* @param $html
* @param $field
* @param $meta
*
* @return string
*/
static function html( $html, $meta, $field )
{
$options = $field['options'];
$terms = get_terms( $options['taxonomy'], $options['args'] );
$html = '';
// Checkbox LIST
if ( 'checkbox_list' === $options['type'] )
{
$html = array();
foreach ( $terms as $term )
{
$checked = checked( in_array( $term->slug, $meta ), true, false );
$html[] = "";
}
$html = implode( '
', $html );
}
// Checkbox TREE
elseif ( 'checkbox_tree' === $options['type'] )
{
$elements = self::process_terms( $terms );
$html .= self::walk_checkbox_tree( $meta, $field, $elements, $field['options']['parent'], true );
}
// Select Tree
elseif ( 'select_tree' == $options['type'] )
{
$elements = self::process_terms( $terms );
$html .= self::walk_select_tree( $meta, $field, $elements, $field['options']['parent'], '', true );
}
// Select
else
{
$multiple = $field['multiple'] ? " multiple='multiple' style='height: auto;'" : "'";
$html .= "";
}
return $html;
}
/**
* Walker for displaying checkboxes in treeformat
*
* @param $meta
* @param $field
* @param $elements
* @param int $parent
* @param bool $active
*
* @return string
*/
static function walk_checkbox_tree( $meta, $field, $elements, $parent = 0, $active = false )
{
if(!isset($elements[$parent]))
return;
$terms = $elements[$parent];
$hidden = ( !$active ? 'hidden' : '' );
$html = "