function buddyforms_afe_create_new_form_builder_form_element($form_fields, $form_slug, $field_type, $field_id)
{
    global $post;
    $buddyform = get_post_meta($post->ID, '_buddyforms_options', true);
    switch ($field_type) {
        case 'tax-afe':
            $taxonomies = buddyforms_taxonomies($buddyform);
            $taxonomy = false;
            if (isset($buddyform['form_fields'][$field_id]['taxonomy'])) {
                $taxonomy = $buddyform['form_fields'][$field_id]['taxonomy'];
            }
            $form_fields['general']['taxonomy'] = new Element_Select('<b>' . __('Taxonomy', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][taxonomy]", $taxonomies, array('value' => $taxonomy, 'class' => 'bf_tax_select', 'id' => $field_id));
            break;
    }
    return $form_fields;
}
function buddyforms_woocommerce_create_new_form_builder_form_element($form_fields, $form_slug, $field_type, $field_id)
{
    global $post;
    if ($post->post_type != 'buddyforms') {
        return;
    }
    $buddyform = get_post_meta($post->ID, '_buddyforms_options', true);
    //    if($buddyform['post_type'] != 'product')
    //        return;
    $field_id = (string) $field_id;
    switch ($field_type) {
        case 'woocommerce':
            unset($form_fields);
            $form_fields['General']['name'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][name]", 'WooCommerce');
            $form_fields['General']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", '_woocommerce');
            $form_fields['General']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            $product_type_options = apply_filters('product_type_options', array('virtual' => array('id' => '_virtual', 'wrapper_class' => 'show_if_simple', 'label' => __('Virtual', 'woocommerce'), 'description' => '<b>' . __('Virtual products are intangible and aren\'t shipped.', 'woocommerce') . '</b>', 'default' => 'no'), 'downloadable' => array('id' => '_downloadable', 'wrapper_class' => 'show_if_simple', 'label' => __('Downloadable', 'woocommerce'), 'description' => __('Downloadable products give access to a file upon purchase.', 'woocommerce'), 'default' => 'no')));
            $product_type_hidden = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_type_hidden'])) {
                $product_type_hidden = $buddyform['form_fields'][$field_id]['product_type_hidden'];
            }
            $data = $field_id . '_product_type_default ';
            $data .= $field_id . '_hr1 ';
            foreach ($product_type_options as $key => $option) {
                $data .= $field_id . '_' . $key . ' ';
            }
            $element = new Element_Checkbox('Product Type Hidden', "buddyforms_options[form_fields][" . $field_id . "][product_type_hidden]", array('hidden' => '<b>' . __('Make the Product Type a Hidden Field', 'buddyforms') . '</b>'), array('id' => 'product_type_hidden', 'class' => 'bf_hidden_checkbox', 'value' => $product_type_hidden));
            $element->setAttribute('bf_hidden_checkbox', $data);
            $form_fields['General']['product_type_hidden'] = $element;
            $product_type_hidden_checked = isset($buddyform['form_fields'][$field_id]['product_type_hidden']) ? '' : 'hidden';
            //$form_fields['General']['product_type_default_div_start'] = new Element_HTML('<div ' . $product_type_hidden_checked . ' class="product_type_hidden_'.$field_id.'-0">',array('id' => 'sad1', 'class' =>'dsad2'));
            $product_type_default = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_type_default'])) {
                $product_type_default = $buddyform['form_fields'][$field_id]['product_type_default'];
            }
            $product_type = apply_filters('default_product_type', 'simple');
            $product_type_selector = apply_filters('product_type_selector', array('simple' => __('Simple product', 'woocommerce'), 'grouped' => __('Grouped product', 'woocommerce'), 'external' => __('External/Affiliate product', 'woocommerce'), 'variable' => __('Variable product', 'woocommerce')), $product_type);
            $type_box = '<label for="product-type"><p>Default Product Type</p><select id="product-type" name="buddyforms_options[form_fields][' . $field_id . '][product_type_default]"><optgroup label="' . __('Product Type', 'woocommerce') . '">';
            foreach ($product_type_selector as $value => $label) {
                $type_box .= '<option value="' . esc_attr($value) . '" ' . selected($product_type_default, $value, false) . '>' . esc_html($label) . '</option>';
            }
            $type_box .= '</optgroup></select></label>';
            $element = new Element_HTML($type_box);
            if ($product_type_hidden_checked == 'hidden') {
                $element->setAttribute('class', 'hidden');
            }
            $form_fields['General']['product_type_default'] = $element;
            foreach ($product_type_options as $key => $option) {
                $product_type_option_value = isset($buddyform['form_fields'][$field_id]['product_type_options'][esc_attr($option["id"])]) ? $buddyform['form_fields'][$field_id]['product_type_options'][esc_attr($option["id"])] : '';
                $element = new Element_Checkbox($option['description'], "buddyforms_options[form_fields][" . $field_id . "][product_type_options][" . esc_attr($option['id']) . "]", array($option['id'] => esc_html($option['label'])), array('id' => esc_attr($option['id']), 'value' => $product_type_option_value));
                if ($product_type_hidden_checked == 'hidden') {
                    $element->setAttribute('class', 'hidden');
                }
                $form_fields['General'][$key] = $element;
            }
            $form_fields['General']['hr1'] = new Element_HTML('<hr>');
            //$form_fields['General']['product_type_default_div_end'] = new Element_HTML('</div>');
            $product_sku = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_sku'])) {
                $product_sku = $buddyform['form_fields'][$field_id]['product_sku'];
            }
            $form_fields['General']['product_sku'] = new Element_Select('<b>' . __('SKU Field', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_sku]", array('none' => 'None', 'hidden' => __('Hide', 'buddyforms'), "required" => __('Required', 'buddyforms')), array('inline' => 1, 'id' => 'product_sku_' . $field_id, 'value' => $product_sku));
            $product_regular_price = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_regular_price'])) {
                $product_regular_price = $buddyform['form_fields'][$field_id]['product_regular_price'];
            }
            $form_fields['General']['product_regular_price'] = new Element_Checkbox('<b>' . __('Regular Price', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_regular_price]", array("required" => __('Required', 'buddyforms')), array('inline' => 1, 'id' => 'product_regular_price_' . $field_id, 'value' => $product_regular_price));
            $product_sales_price = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_sales_price'])) {
                $product_sales_price = $buddyform['form_fields'][$field_id]['product_sales_price'];
            }
            $form_fields['General']['product_sales_price'] = new Element_Select('<b>' . __('Sales Price', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_sales_price]", array('hidden' => __('Hide', 'buddyforms'), "required" => __('Required', 'buddyforms')), array('inline' => 1, 'id' => 'product_sales_price_' . $field_id, 'value' => $product_sales_price));
            $product_sales_price_dates = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_sales_price_dates'])) {
                $product_sales_price_dates = $buddyform['form_fields'][$field_id]['product_sales_price_dates'];
            }
            $form_fields['General']['product_sales_price_dates'] = new Element_Select('<b>' . __('Sales Price Date', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_sales_price_dates]", array('hidden' => __('Hide', 'buddyforms'), "required" => __('Required', 'buddyforms')), array('inline' => 1, 'id' => 'product_sales_price_dates_' . $field_id, 'value' => $product_sales_price_dates));
            //unset($form_fields);
            //$form_fields['Inventory']['name']		= new Element_Hidden("buddyforms_options[form_fields][".$field_id."][name]", 'Inventory');
            //$form_fields['general']['slug']		= new Element_Hidden("buddyforms_options[form_fields][".$field_id."][slug]", '_inventory');
            //$form_fields['general']['type']		= new Element_Hidden("buddyforms_options[form_fields][".$field_id."][type]", $field_type);
            $product_manage_stock = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_manage_stock'])) {
                $product_manage_stock = $buddyform['form_fields'][$field_id]['product_manage_stock'];
            }
            // Inventory
            // $product_manage_stock_checked = isset($buddyform['form_fields'][$field_id]['product_manage_stock']) && in_array('manage', $buddyform['form_fields'][$field_id]['product_manage_stock']) ? 'style="display: none;"' : '';
            // $form_fields['general']['product_manage_stock_div_start'] = new Element_HTML('<div ' . $product_manage_stock_checked . ' class="product_manage_stock_'.$field_id.'-0">');
            $product_manage_stock_checked = isset($buddyform['form_fields'][$field_id]['product_manage_stock']) ? '' : 'hidden';
            $data = $field_id . '_product_type_hidden ';
            $data .= $field_id . '_product_manage_stock_hide ';
            $data .= $field_id . '_product_manage_stock_qty_options ';
            $data .= $field_id . '_product_manage_stock_qty ';
            $data .= $field_id . '_product_allow_backorders_options ';
            $data .= $field_id . '_product_allow_backorders ';
            //$data .= $field_id .'_product_stock_status_options ';
            //$data .= $field_id .'_product_stock_status ';
            //$data .= $field_id .'_product_sold_individually_options ';
            //$data .= $field_id .'_product_sold_individually ';
            $element = new Element_Checkbox('<b>' . __('Manage Stock', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_manage_stock]", array('manage' => '<b>' . __('Disable stock management at product level', 'buddyforms') . '</b>'), array('id' => 'product_manage_stock_' . $field_id, 'class' => 'bf_hidden_checkbox', 'value' => $product_manage_stock));
            $element->setAttribute('bf_hidden_checkbox', $data);
            $form_fields['Inventory']['product_manage_stock'] = $element;
            // Stock Qty
            $product_manage_stock_qty_options = isset($buddyform['form_fields'][$field_id]['product_manage_stock_qty_options']) ? $buddyform['form_fields'][$field_id]['product_manage_stock_qty_options'] : 'false';
            $element = new Element_Checkbox('<b>' . __('Stock Qty', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_manage_stock_qty_options]", array('default' => '<b>' . __('Hide', 'buddyforms') . '</b>'), array('id' => 'product_manage_stock_qty_options_' . $field_id, 'class' => 'bf_hidden_checkbox ' . $product_manage_stock_checked, 'value' => $product_manage_stock_qty_options));
            $data = $field_id . '_product_manage_stock_qty ';
            $element->setAttribute('bf_hidden_checkbox', $data);
            $form_fields['Inventory']['product_manage_stock_qty_options'] = $element;
            // Stock Qty hidden value
            $product_manage_stock_qty_checked = $product_manage_stock_qty_options == 'false' ? 'hidden' : '';
            $product_manage_stock_qty = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_manage_stock_qty'])) {
                $product_manage_stock_qty = $buddyform['form_fields'][$field_id]['product_manage_stock_qty'];
            }
            $form_fields['Inventory']['product_manage_stock_qty'] = new Element_Number('<b>' . __('Enter a number: ', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_manage_stock_qty]", array('id' => 'product_manage_stock_qty_' . $field_id, 'class' => $product_manage_stock_checked . ' ' . $product_manage_stock_qty_checked, 'value' => $product_manage_stock_qty));
            // Backorders
            $product_allow_backorders_options = isset($buddyform['form_fields'][$field_id]['product_allow_backorders_options']) ? $buddyform['form_fields'][$field_id]['product_allow_backorders_options'] : 'false';
            $element = new Element_Checkbox('<b>' . __('Allow Backorders?', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_allow_backorders_options]", array('hidden' => '<b>' . __('Hide', 'buddyforms') . '</b>'), array('id' => $field_id . '_product_allow_backorders_options', 'class' => 'bf_hidden_checkbox ' . $product_manage_stock_checked, 'value' => $product_allow_backorders_options));
            $data = $field_id . '_product_allow_backorders ';
            $element->setAttribute('bf_hidden_checkbox', $data);
            $form_fields['Inventory']['product_allow_backorders_options'] = $element;
            // Backorders value
            $product_allow_backorders_checked = $product_allow_backorders_options == 'false' ? 'hidden' : '';
            $product_allow_backorders = isset($buddyform['form_fields'][$field_id]['product_allow_backorders']) ? $buddyform['form_fields'][$field_id]['product_allow_backorders'] : 'false';
            $form_fields['Inventory']['product_allow_backorders'] = new Element_Select('<p>' . __('Select hidden value: ', 'buddyforms') . '</p>', "buddyforms_options[form_fields][" . $field_id . "][product_allow_backorders]", array('no' => '<b>' . __('Do not allow', 'buddyforms') . '</b>', 'notify' => '<b>' . __('Allow, but notify customer', 'buddyforms') . '</b>', 'yes' => '<b>' . __('Allow', 'buddyforms') . '</b>'), array('id' => $field_id . '_product_allow_backorders', 'class' => $product_allow_backorders_checked, 'value' => $product_allow_backorders));
            // Stock Status
            $product_stock_status_options = isset($buddyform['form_fields'][$field_id]['product_stock_status_options']) ? $buddyform['form_fields'][$field_id]['product_stock_status_options'] : 'false';
            $element = new Element_Checkbox('<b>' . __('Stock Status', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_stock_status_options]", array('hidden' => '<b>' . __('Hide', 'buddyforms') . '</b>'), array('id' => $field_id . '_product_stock_status_options', 'class' => 'bf_hidden_checkbox', 'value' => $product_stock_status_options));
            $data = $field_id . '_product_stock_status';
            $element->setAttribute('bf_hidden_checkbox', $data);
            $form_fields['Inventory']['product_stock_status_options'] = $element;
            // Stock Status Hidden Value
            $product_stock_status_checked = $product_stock_status_options == 'false' ? 'hidden' : '';
            $product_stock_status = isset($buddyform['form_fields'][$field_id]['product_stock_status']) ? $buddyform['form_fields'][$field_id]['product_stock_status'] : 'false';
            $form_fields['Inventory']['product_stock_status'] = new Element_Select('<p>' . __('Select hidden value: ', 'buddyforms') . '</p>', "buddyforms_options[form_fields][" . $field_id . "][product_stock_status]", array('instock' => '<b>' . __('In stock', 'buddyforms') . '</b>', 'outofstock' => '<b>' . __('Out of stock', 'buddyforms') . '</b>'), array('id' => $field_id . '_product_stock_status', 'class' => $product_stock_status_checked, 'value' => $product_stock_status));
            // Sold Individually
            $product_sold_individually_options = isset($buddyform['form_fields'][$field_id]['product_sold_individually_options']) ? $buddyform['form_fields'][$field_id]['product_sold_individually_options'] : 'false';
            $element = new Element_Checkbox('<b>' . __('Sold Individually', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_sold_individually_options]", array('hidden' => '<b>' . __('Hide', 'buddyforms') . '</b>'), array('id' => $field_id . '_product_sold_individually_options', 'class' => 'bf_hidden_checkbox', 'value' => $product_sold_individually_options));
            $data = $field_id . '_product_sold_individually';
            $element->setAttribute('bf_hidden_checkbox', $data);
            $form_fields['Inventory']['product_sold_individually_options'] = $element;
            // Sold Individually Hidden Value
            $product_sold_individually_checked = $product_sold_individually_options == 'false' ? 'hidden' : '';
            $product_sold_individually = isset($buddyform['form_fields'][$field_id]['product_sold_individually']) ? $buddyform['form_fields'][$field_id]['product_sold_individually'] : 'false';
            $form_fields['Inventory']['product_sold_individually'] = new Element_Select('<p>' . __('Select hidden value: ', 'buddyforms') . '</p>', "buddyforms_options[form_fields][" . $field_id . "][product_sold_individually]", array('yes' => '<b>' . __('Yes', 'buddyforms') . '</b>', 'no' => '<b>' . __('No', 'buddyforms') . '</b>'), array('id' => $field_id . '_product_sold_individually', 'class' => $product_sold_individually_checked, 'value' => $product_sold_individually));
            // Shipping
            $form_fields['Shipping']['product_shipping_enabled_html'] = new Element_HTML('<p>' . __('If you want to tur off Shipping you need to set the Product Type to Virtual, Grouped or External. In the General Tab.
             This will automatically hide the shipping fields.', 'buddyforms') . '</p>');
            //            $product_shipping_enabled = 'false';
            //            if(isset($buddyform['form_fields'][$field_id]['product_shipping_enabled']))
            //                $product_shipping_enabled = $buddyform['form_fields'][$field_id]['product_shipping_enabled'];
            //            $form_fields['Shipping']['product_shipping_enabled']		= new Element_Checkbox( '<b>'.__('Enable Shipping', 'buddyforms').'</b>',"buddyforms_options[form_fields][".$field_id."][product_shipping_enabled]",array('enabled' =>  __('Enable', 'buddyforms')),array('id' => 'product_shipping_enabled'.$field_id , 'value' => $product_shipping_enabled));
            // Linked-Products
            $product_up_sales = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_up_sales'])) {
                $product_up_sales = $buddyform['form_fields'][$field_id]['product_up_sales'];
            }
            $form_fields['Linked-Products']['product_up_sales'] = new Element_Checkbox('<b>' . __('Up-Sales', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_up_sales]", array('hidden' => __('Hide Up-Sales', 'buddyforms')), array('id' => 'product_up_sales_' . $field_id, 'value' => $product_up_sales));
            $product_cross_sales = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_cross_sales'])) {
                $product_cross_sales = $buddyform['form_fields'][$field_id]['product_cross_sales'];
            }
            $form_fields['Linked-Products']['product_cross_sales'] = new Element_Checkbox('<b>' . __('Cross Sales', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_cross_sales]", array('hidden' => __('Hide Cross Sales', 'buddyforms')), array('id' => 'product_cross_sales_' . $field_id, 'value' => $product_cross_sales));
            $product_grouping = 'false';
            if (isset($buddyform['form_fields'][$field_id]['product_grouping'])) {
                $product_grouping = $buddyform['form_fields'][$field_id]['product_grouping'];
            }
            $form_fields['Linked-Products']['product_grouping'] = new Element_Checkbox('<b>' . __('Grouping', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][product_cross_sales]", array('hidden' => __('Hide Grouping', 'buddyforms')), array('id' => 'product_grouping' . $field_id, 'value' => $product_grouping));
            break;
        case 'attributes':
            unset($form_fields);
            $form_fields['Attributes']['name'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][name]", 'Attribute');
            $form_fields['Attributes']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", '_attribute');
            $form_fields['Attributes']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            $taxonomies = buddyforms_taxonomies($buddyform);
            $bf_wc_attributes_tax = array();
            foreach ($taxonomies as $key => $taxonomie) {
                if (substr($taxonomie, 0, 3) == 'pa_') {
                    $bf_wc_attributes_tax[$taxonomie] = $taxonomie;
                }
            }
            $bf_wc_attributes_pa = false;
            if (isset($buddyform['form_fields'][$field_id]['_bf_wc_attributes_pa'])) {
                $bf_wc_attributes_pa = $buddyform['form_fields'][$field_id]['_bf_wc_attributes_pa'];
            }
            $form_fields['Attributes']['_bf_wc_attributes_pa'] = new Element_Checkbox('<b>' . __('Attribute Taxonomies', 'buddyforms') . '</b><p><smal>Select the Attribute Taxonomies you want to include. These are the attributes you have created under Product/Attributes</smal></p>', "buddyforms_options[form_fields][" . $field_id . "][_bf_wc_attributes_pa]", $bf_wc_attributes_tax, array('value' => $bf_wc_attributes_pa));
            $attr_new_custom_field = 'false';
            if (isset($buddyform['form_fields'][$field_id]['attr_new_custom_field'])) {
                $attr_new_custom_field = $buddyform['form_fields'][$field_id]['attr_new_custom_field'];
            }
            $form_fields['Attributes']['attr_new_custom_field'] = new Element_Checkbox('<b>' . __('Custom Attribute', 'buddyforms') . '</b> <p><smal>This is the same as the Custom Attributes in the Product edit Screen</smal></p>', "buddyforms_options[form_fields][" . $field_id . "][attr_new_custom_field]", array('attr_new' => '<b>' . __('User can create new custom fields ', 'buddyforms') . '</b>'), array('value' => $attr_new_custom_field));
            break;
        case 'product-gallery':
            unset($form_fields);
            $form_fields['Gallery']['name'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][name]", 'Gallery');
            $form_fields['Gallery']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", '_gallery');
            $form_fields['Gallery']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            $description = isset($buddyform['form_fields'][$field_id]['description']) ? stripslashes($buddyform['form_fields'][$field_id]['description']) : '';
            $form_fields['Gallery']['description'] = new Element_Textbox('<b>' . __('Description', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][description]", array('value' => $description));
            $required = isset($buddyform['form_fields'][$field_id]['required']) ? $buddyform['form_fields'][$field_id]['required'] : 'false';
            $form_fields['Gallery']['required'] = new Element_Checkbox('<b>' . __('Required', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][required]", array('required' => '<b>' . __('Make this field a required field', 'buddyforms') . '</b>'), array('value' => $required, 'id' => "buddyforms_options[form_fields][" . $field_id . "][required]"));
            break;
    }
    return $form_fields;
}
/**
 * View form fields
 *
 * @package BuddyForms
 * @since 0.1-beta
 */
function buddyforms_display_form_element($args)
{
    global $post;
    if (!$post && isset($_POST['post_id']) && $_POST['post_id'] != 0) {
        $post = get_post($_POST['post_id']);
    }
    $buddyform = get_post_meta($post->ID, '_buddyforms_options', true);
    if (isset($_POST['fieldtype'])) {
        $field_type = $_POST['fieldtype'];
    }
    if (isset($_POST['unique'])) {
        $field_unique = $_POST['unique'];
    }
    $form_slug = $post->post_name;
    if (isset($field_unique) && $field_unique == 'unique') {
        if (isset($buddyform['form_fields'])) {
            foreach ($buddyform['form_fields'] as $key => $form_field) {
                if ($form_field['type'] == $field_type) {
                    return 'unique';
                }
            }
        }
    }
    if (is_array($args)) {
        extract($args);
    }
    if (!isset($field_id)) {
        $field_id = $mod5 = substr(md5(time() * rand()), 0, 10);
    }
    $customfield = isset($buddyform['form_fields'][$field_id]) ? $buddyform['form_fields'][$field_id] : array();
    $form_fields = array();
    $required = isset($customfield['required']) ? $customfield['required'] : 'false';
    $form_fields['validation']['required'] = new Element_Checkbox('<b>' . __('Required', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][required]", array('required' => '<b>' . __('Make this field a required field', 'buddyforms') . '</b>'), array('value' => $required, 'id' => "buddyforms_options[form_fields][" . $field_id . "][required]"));
    $name = isset($customfield['name']) ? stripcslashes($customfield['name']) : '';
    $form_fields['general']['name'] = new Element_Textbox('<b>' . __('Name', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][name]", array('class' => "use_as_slug", 'data' => $field_id, 'value' => $name, 'required' => 1));
    $field_slug = isset($customfield['slug']) ? sanitize_title($customfield['slug']) : $name;
    $form_fields['general']['slug'] = new Element_Textbox('<b>' . __('Slug', 'buddyforms') . '</b> <small>(optional)</small>', "buddyforms_options[form_fields][" . $field_id . "][slug]", array('shortDesc' => __('_name will create a hidden post meta field', 'buddyforms'), 'value' => $field_slug, 'required' => 1, 'class' => 'slug' . $field_id));
    $description = isset($customfield['description']) ? stripslashes($customfield['description']) : '';
    $form_fields['general']['description'] = new Element_Textbox('<b>' . __('Description', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][description]", array('value' => $description));
    $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
    $validation_error_message = isset($customfield['validation_error_message']) ? stripcslashes($customfield['validation_error_message']) : __('This field is required.', 'buddyforms');
    $form_fields['validation']['validation_error_message'] = new Element_Textbox('<b>' . __('Validation Error Message', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_error_message]", array('value' => $validation_error_message));
    $custom_class = isset($customfield['custom_class']) ? stripcslashes($customfield['custom_class']) : '';
    $form_fields['advanced']['custom_class'] = new Element_Textbox('<b>' . __('Add custom class to the form element', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][custom_class]", array('value' => $custom_class));
    switch (sanitize_title($field_type)) {
        case 'text':
            $validation_minlength = isset($customfield['avalidation_minlengtha']) ? stripcslashes($customfield['validation_minlength']) : 0;
            $form_fields['validation']['validation_minlength'] = new Element_Number('<b>' . __('Validation Min Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_minlength]", array('value' => $validation_minlength));
            $validation_maxlength = isset($customfield['validation_maxlength']) ? stripcslashes($customfield['validation_maxlength']) : 0;
            $form_fields['validation']['validation_maxlength'] = new Element_Number('<b>' . __('Validation Max Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_maxlength]", array('value' => $validation_maxlength));
            break;
        case 'textarea':
            $validation_minlength = isset($customfield['validation_minlength']) ? stripcslashes($customfield['validation_minlength']) : 0;
            $form_fields['validation']['validation_minlength'] = new Element_Number('<b>' . __('Validation Min Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_minlength]", array('value' => $validation_minlength));
            $validation_maxlength = isset($customfield['validation_maxlength']) ? stripcslashes($customfield['validation_maxlength']) : 0;
            $form_fields['validation']['validation_maxlength'] = new Element_Number('<b>' . __('Validation Max Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_maxlength]", array('value' => $validation_maxlength));
            break;
        case 'number':
            $validation_min = isset($customfield['validation_min']) ? stripcslashes($customfield['validation_min']) : 0;
            $form_fields['validation']['validation_min'] = new Element_Number('<b>' . __('Validation Min Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_min]", array('value' => $validation_min));
            $validation_max = isset($customfield['validation_max']) ? stripcslashes($customfield['validation_max']) : 0;
            $form_fields['validation']['validation_max'] = new Element_Number('<b>' . __('Validation Max Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_max]", array('value' => $validation_max));
            break;
        case 'dropdown':
            $multiple = isset($customfield['multiple']) ? $customfield['multiple'] : 'false';
            $form_fields['general']['multiple'] = new Element_Checkbox('<b>' . __('Multiple Selection', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][multiple]", array('multiple' => '<b>' . __('Multiple', 'buddyforms') . '</b>'), array('value' => $multiple));
            $field_args = array('field_id' => $field_id, 'buddyform' => $buddyform);
            $form_fields['general']['select_options'] = new Element_HTML(buddyforms_form_element_multiple($form_fields, $field_args));
            break;
        case 'radiobutton':
            $field_args = array('field_id' => $field_id, 'buddyform' => $buddyform);
            $form_fields['general']['select_options'] = new Element_HTML(buddyforms_form_element_multiple($form_fields, $field_args));
            break;
        case 'checkbox':
            $field_args = array('field_id' => $field_id, 'buddyform' => $buddyform);
            $form_fields['general']['select_options'] = new Element_HTML(buddyforms_form_element_multiple($form_fields, $field_args));
            break;
        case 'taxonomy':
            $taxonomies = buddyforms_taxonomies($buddyform);
            $taxonomy = isset($customfield['taxonomy']) ? $customfield['taxonomy'] : false;
            $form_fields['general']['taxonomy'] = new Element_Select('<b>' . __('Taxonomy', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][taxonomy]", $taxonomies, array('value' => $taxonomy, 'class' => 'bf_tax_select', 'id' => $field_id));
            $taxonomy_default = isset($customfield['taxonomy_default']) ? $customfield['taxonomy_default'] : 'false';
            $taxonomy_order = isset($customfield['taxonomy_order']) ? $customfield['taxonomy_order'] : 'false';
            if ($taxonomy) {
                $wp_dropdown_categories_args = array('hide_empty' => 0, 'child_of' => 0, 'echo' => FALSE, 'selected' => false, 'hierarchical' => 1, 'id' => 'taxonomy_default_' . $field_id, 'name' => "buddyforms_options[form_fields][" . $field_id . "][taxonomy_default][]", 'class' => 'postform bf-select2 tax_default', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => $taxonomy, 'hide_if_empty' => FALSE, 'orderby' => 'SLUG', 'order' => $taxonomy_order);
                $dropdown = wp_dropdown_categories($wp_dropdown_categories_args);
                $dropdown = str_replace('id=', 'multiple="multiple" id=', $dropdown);
                if (is_array($taxonomy_default)) {
                    foreach ($taxonomy_default as $key => $post_term) {
                        $dropdown = str_replace(' value="' . $post_term . '"', ' value="' . $post_term . '" selected="selected"', $dropdown);
                    }
                } else {
                    $dropdown = str_replace(' value="' . $taxonomy_default . '"', ' value="' . $taxonomy_default . '" selected="selected"', $dropdown);
                }
                $dropdown = '</tr><tr>
                            <th scope="row">
                                <label for="form_title"><b>Taxonomy Default</b></label>
                            </th>
                            <td>
                                ' . $dropdown . '
                                <p class="description">You can select a default category</p>
                            </td></tr>';
                $form_fields['general']['taxonomy_default'] = new Element_HTML($dropdown);
            } else {
                $form_fields['general']['taxonomy_default'] = new Element_Select('<b>' . __('Taxonomy Default', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][taxonomy_default]", array(), array('class' => 'bf-select2', 'multiple' => 1, 'value' => '', 'id' => 'taxonomy_default_' . $field_id));
            }
            $form_fields['general']['taxonomy_order'] = new Element_Select('<b>' . __('Taxonomy Order', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][taxonomy_order]", array('ASC', 'DESC'), array('value' => $taxonomy_order));
            $multiple = isset($customfield['multiple']) ? $customfield['multiple'] : 'false';
            $form_fields['general']['multiple'] = new Element_Checkbox('<b>' . __('Multiple Selection', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][multiple]", array('multiple' => '<b>' . __('Multiple', 'buddyforms') . '</b>'), array('value' => $multiple));
            $show_option_none = isset($customfield['show_option_none']) ? $customfield['show_option_none'] : 'false';
            $form_fields['general']['show_option_none'] = new Element_Checkbox('<b>' . __('Display Select an Option', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][show_option_none]", array('show_select_option' => '<b>' . __("Show 'Select an Option'", 'buddyforms') . '</b>'), array('value' => $show_option_none));
            $creat_new_tax = isset($customfield['creat_new_tax']) ? $customfield['creat_new_tax'] : 'false';
            $form_fields['general']['creat_new_tax'] = new Element_Checkbox('<b>' . __('New Taxonomy Item', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][creat_new_tax]", array('user_can_create_new' => '<b>' . __('User can create new', 'buddyforms') . '</b>'), array('value' => $creat_new_tax));
            $hidden = isset($customfield['hidden']) ? $customfield['hidden'] : false;
            $form_fields['advanced']['hidden'] = new Element_Checkbox('<b>' . __('Hidden', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][hidden]", array('hidden' => '<b>' . __('Make this field Hidden', 'buddyforms') . '</b>'), array('value' => $hidden));
            break;
        case 'hidden':
            unset($form_fields);
            $form_fields['general']['name'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][name]", $field_slug);
            $form_fields['general']['slug'] = new Element_Textbox('<b>' . __('Slug', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][slug]", array('required' => true, 'value' => $field_slug, 'required' => 1));
            $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            $value = isset($customfield['value']) ? $customfield['value'] : '';
            $form_fields['general']['value'] = new Element_Textbox('<b>' . __('Value:', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][value]", array('value' => $value));
            break;
        case 'comments':
            unset($form_fields);
            $required = isset($customfield['required']) ? $customfield['required'] : 'false';
            $form_fields['general']['required'] = new Element_Checkbox('<b>' . __('Required', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][required]", array('required' => '<b>' . __('Required', 'buddyforms') . '</b>'), array('value' => $required, 'id' => "buddyforms_options[form_fields][" . $field_id . "][required]"));
            $name = isset($customfield['name']) ? stripcslashes($customfield['name']) : 'Comments';
            $form_fields['general']['name'] = new Element_Textbox('<b>' . __('Name', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][name]", array('value' => $name, 'required' => 1));
            $form_fields['general']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", 'comments');
            $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            $form_fields['general']['html'] = new Element_HTML(__("There are no settings needed so far. You can change the global comment settings in the form control section. If the 'comments' element is added to the form, the user has the possibility to overwrite the global settings and open/close 'comments' for their own post.", 'buddyforms'));
            break;
        case 'title':
            unset($form_fields['general']['required']);
            $name = isset($customfield['name']) ? stripcslashes($customfield['name']) : 'Title';
            $form_fields['general']['name'] = new Element_Textbox('<b>' . __('Name', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][name]", array('value' => $name, 'required' => 1));
            $form_fields['general']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", 'editpost_title');
            $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            $hidden = isset($customfield['hidden']) ? $customfield['hidden'] : false;
            $form_fields['advanced']['hidden'] = new Element_Checkbox('<b>' . __('Hidden?', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][hidden]", array('hidden' => '<b>' . __('Make this field Hidden', 'buddyforms') . '</b>'), array('value' => $hidden));
            $validation_minlength = isset($customfield['validation_minlength']) ? stripcslashes($customfield['validation_minlength']) : 0;
            $form_fields['validation']['validation_minlength'] = new Element_Number('<b>' . __('Validation Min Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_minlength]", array('value' => $validation_minlength));
            $validation_maxlength = isset($customfield['validation_maxlength']) ? stripcslashes($customfield['validation_maxlength']) : '';
            $form_fields['validation']['validation_maxlength'] = new Element_Number('<b>' . __('Validation Max Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_maxlength]", array('value' => $validation_maxlength));
            break;
        case 'content':
            $name = isset($customfield['name']) ? stripcslashes($customfield['name']) : 'Content';
            $form_fields['general']['name'] = new Element_Textbox('<b>' . __('Name', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][name]", array('value' => $name, 'required' => 1));
            $post_content_options = isset($customfield['post_content_options']) ? $customfield['post_content_options'] : 'false';
            $post_content_options_array = array('media_buttons' => 'media_buttons', 'tinymce' => 'tinymce', 'quicktags' => 'quicktags');
            $form_fields['advanced']['content_opt_a'] = new Element_Checkbox('<b>' . __('Turn off wp editor features', 'buddyforms') . '</b><br><br>', "buddyforms_options[form_fields][" . $field_id . "][post_content_options]", $post_content_options_array, array('value' => $post_content_options));
            $form_fields['general']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", 'editpost_content');
            $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            $hidden = isset($customfield['hidden']) ? $customfield['hidden'] : false;
            $form_fields['advanced']['hidden'] = new Element_Checkbox('<b>' . __('Hidden?', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][hidden]", array('hidden' => '<b>' . __('Make this field Hidden', 'buddyforms') . '</b>'), array('value' => $hidden));
            $validation_minlength = isset($customfield['validation_minlength']) ? stripcslashes($customfield['validation_minlength']) : 0;
            $form_fields['validation']['validation_minlength'] = new Element_Number('<b>' . __('Validation Min Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_minlength]", array('value' => $validation_minlength));
            $validation_maxlength = isset($customfield['validation_maxlength']) ? stripcslashes($customfield['validation_maxlength']) : 0;
            $form_fields['validation']['validation_maxlength'] = new Element_Number('<b>' . __('Validation Max Length', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_maxlength]", array('value' => $validation_maxlength));
            break;
        case 'status':
            unset($form_fields);
            $required = isset($customfield['required']) ? $customfield['required'] : 'false';
            $form_fields['general']['required'] = new Element_Checkbox('<b>' . __('Required', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][required]", array('required' => '<b>' . __('Required', 'buddyforms') . '</b>'), array('value' => $required, 'id' => "buddyforms_options[form_fields][" . $field_id . "][required]"));
            $name = isset($customfield['name']) ? stripcslashes($customfield['name']) : 'Status';
            $form_fields['general']['name'] = new Element_Textbox('<b>' . __('Name', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][name]", array('value' => $name, 'required' => 1));
            $form_fields['general']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", 'post_status');
            $post_status = isset($customfield['post_status']) ? $customfield['post_status'] : 'post_status';
            $form_fields['general']['post_status'] = new Element_Checkbox('<b>' . __('Select the post status you want to make available in the frontend form', 'buddyforms') . '</b><br><br>', "buddyforms_options[form_fields][" . $field_id . "][post_status]", bf_get_post_status_array(), array('value' => $post_status, 'id' => "buddyforms_options[form_fields][" . $field_id . "][post_status]", 'shortDesc' => __("You can change the global post status settings in the form control section. If the 'status' element is added to the form, the user has the possibility to overwrite the global settings and change the 'status' for their own post.", 'buddyforms')));
            $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            break;
        case 'featured-image':
        case 'featuredimage':
            unset($form_fields);
            $required = isset($customfield['required']) ? $customfield['required'] : 'false';
            $form_fields['general']['required'] = new Element_Checkbox('<b>' . __('Required', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][required]", array('required' => '<b>' . __('Required', 'buddyforms') . '</b>'), array('value' => $required, 'id' => "buddyforms_options[form_fields][" . $field_id . "][required]"));
            $name = isset($customfield['name']) ? stripcslashes($customfield['name']) : 'FeaturedImage';
            $form_fields['general']['name'] = new Element_Textbox('<b>' . __('Name', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][name]", array('value' => $name, 'required' => 1));
            $form_fields['general']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", 'featured_image');
            $description = isset($customfield['description']) ? stripcslashes($customfield['description']) : '';
            $form_fields['general']['description'] = new Element_Textbox('<b>' . __('Description:', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][description]", array('value' => $description));
            $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            break;
        case 'file':
            $validation_multiple = isset($customfield['validation_multiple']) ? $customfield['validation_multiple'] : 0;
            $form_fields['advanced']['validation_multiple'] = new Element_Checkbox('<b>' . __('Only one file or multiple?', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][validation_multiple]", array('multiple' => '<b>' . __('Allow multiple file upload', 'buddyforms') . '</b>'), array('value' => $validation_multiple));
            $allowed_mime_types = get_allowed_mime_types();
            $data_types = isset($customfield['data_types']) ? $customfield['data_types'] : '';
            $form_fields['advanced']['data_types'] = new Element_Checkbox('<b>' . __('Select allowed file Types', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][data_types]", $allowed_mime_types, array('value' => $data_types));
            break;
        case 'html':
            unset($form_fields);
            $html = isset($customfield['html']) ? stripcslashes($customfield['html']) : '';
            $form_fields['general']['description'] = new Element_Textarea('<b>' . __('HTML:', 'buddyforms') . '</b>', "buddyforms_options[form_fields][" . $field_id . "][html]", array('value' => $html));
            $form_fields['general']['name'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][name]", 'HTML');
            $form_fields['general']['slug'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][slug]", 'html');
            $form_fields['general']['type'] = new Element_Hidden("buddyforms_options[form_fields][" . $field_id . "][type]", $field_type);
            break;
        default:
            $form_fields = apply_filters('buddyforms_form_element_add_field', $form_fields, $form_slug, $field_type, $field_id);
            break;
    }
    $form_fields = apply_filters('buddyforms_formbuilder_fields_options', $form_fields, $field_type, $field_id);
    $form_fields = buddyforms_sort_array_by_Array($form_fields, array('general', 'validation', 'advanced'));
    ob_start();
    ?>
    <li id="field_<?php 
    echo $field_id;
    ?>
" class="bf_list_item <?php 
    echo $field_id;
    ?>
">
        <div class="accordion_fields">
            <div class="accordion-group postbox">
                <div class="accordion-heading-options">
                    <table class="wp-list-table widefat fixed posts">
                        <tbody>
                            <tr>
                                <td class="field_order ui-sortable-handle">
                                    <span class="circle">0</span>
                                </td>
                                <td class="field_label">
                                    <strong>
                                        <a class="bf_edit_field row-title accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion_text" href="#accordion_<?php 
    echo $field_type . '_' . $field_id;
    ?>
" title="Edit this Field" href="javascript:;"><?php 
    echo $name;
    ?>
</a>
                                    </strong>

                                </td>
                                <td class="field_name"><?php 
    echo $field_slug;
    ?>
</td>
                                <td class="field_type"><?php 
    echo $field_type;
    ?>
</td>
                                <td class="field_delete">
                                    <span><a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion_text" href="#accordion_<?php 
    echo $field_type . '_' . $field_id;
    ?>
" title="Edit this Field" href="javascript:;">Edit</a> | </span>
                                    <span><a class="bf_delete_field" id="<?php 
    echo $field_id;
    ?>
" title="Delete this Field" href="#">Delete</a></span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div id="accordion_<?php 
    echo $field_type . '_' . $field_id;
    ?>
" class="accordion-body collapse">
                    <div class="accordion-inner">
                        <div class="tabs-<?php 
    echo $field_type . '-' . $field_id;
    ?>
 tabbable tabs-left ">
                            <ul id="bf_field_group<?php 
    echo $field_type . '-' . $field_id;
    ?>
" class="nav nav-tabs nav-pills">
                                <?php 
    $i = 0;
    foreach ($form_fields as $key => $form_field) {
        $class_active = '';
        if ($i == 0) {
            $class_active = 'active';
        }
        ?>
<li class="<?php 
        echo $class_active;
        ?>
"><a href="#<?php 
        echo $key . '-' . $field_type . '-' . $field_id;
        ?>
" data-toggle="tab"><?php 
        echo str_replace('-', ' ', ucfirst($key));
        ?>
</a></li><?php 
        $i++;
    }
    ?>
                            </ul>
                            <div id="bf_field_group_content<?php 
    echo $field_type . '-' . $field_id;
    ?>
" class="tab-content">
                                <?php 
    $i = 0;
    foreach ($form_fields as $key => $form_field) {
        $class_active = '';
        if ($i == 0) {
            $class_active = 'active';
        }
        ?>
                                    <div class="tab-pane fade in <?php 
        echo $class_active;
        ?>
" id="<?php 
        echo $key . '-' . $field_type . '-' . $field_id;
        ?>
">
                                        <div class="buddyforms_accordion_general">
                                            <?php 
        buddyforms_display_field_group_table($form_field, $field_id);
        ?>
                                        </div>
                                    </div>
                                    <?php 
        $i++;
    }
    ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </li>
    <?php 
    $field_html = ob_get_contents();
    ob_end_clean();
    if (is_array($args)) {
        return $field_html;
    } else {
        echo $field_html;
        die;
    }
}