/**
 * Output a radio input box.
 * @param array $field
 */
function restaurantpress_wp_radio($field)
{
    global $thepostid, $post;
    $thepostid = empty($thepostid) ? $post->ID : $thepostid;
    $field['class'] = isset($field['class']) ? $field['class'] : 'select short';
    $field['style'] = isset($field['style']) ? $field['style'] : '';
    $field['wrapper_class'] = isset($field['wrapper_class']) ? $field['wrapper_class'] : '';
    $field['value'] = isset($field['value']) ? $field['value'] : get_post_meta($thepostid, $field['id'], true);
    $field['name'] = isset($field['name']) ? $field['name'] : $field['id'];
    echo '<fieldset class="form-field ' . esc_attr($field['id']) . '_field ' . esc_attr($field['wrapper_class']) . '"><legend>' . wp_kses_post($field['label']) . '</legend><ul class="rp-radios">';
    foreach ($field['options'] as $key => $value) {
        echo '<li><label><input
				name="' . esc_attr($field['name']) . '"
				value="' . esc_attr($key) . '"
				type="radio"
				class="' . esc_attr($field['class']) . '"
				style="' . esc_attr($field['style']) . '"
				' . checked(esc_attr($field['value']), esc_attr($key), false) . '
				/> ' . esc_html($value) . '</label>
		</li>';
    }
    echo '</ul>';
    if (!empty($field['description'])) {
        if (isset($field['desc_tip']) && false !== $field['desc_tip']) {
            echo rp_help_tip($field['description']);
        } else {
            echo '<span class="description">' . wp_kses_post($field['description']) . '</span>';
        }
    }
    echo '</fieldset>';
}
    /**
     * Output the meta box.
     * @param WP_Post $post
     */
    public static function output($post)
    {
        global $post, $thepostid;
        wp_nonce_field('restaurantpress_save_data', 'restaurantpress_meta_nonce');
        $thepostid = $post->ID;
        ?>
		<style type="text/css">
			#edit-slug-box, #minor-publishing-actions { display:none }
		</style>
		<div id="group_options" class="panel-wrap group_data">
			<ul class="group_data_tabs rp-tabs">
				<?php 
        $group_data_tabs = apply_filters('restaurantpress_group_data_tabs', array('general' => array('label' => __('General', 'restaurantpress'), 'target' => 'general_group_data', 'class' => array('hide_if_grouped')), 'grouping' => array('label' => __('Grouping', 'restaurantpress'), 'target' => 'grouping_group_data', 'class' => 'grouping_group_data')));
        foreach ($group_data_tabs as $key => $tab) {
            ?>
<li class="<?php 
            echo $key;
            ?>
_options <?php 
            echo $key;
            ?>
_tab <?php 
            echo implode(' ', (array) $tab['class']);
            ?>
">
							<a href="#<?php 
            echo $tab['target'];
            ?>
"><?php 
            echo esc_html($tab['label']);
            ?>
</a>
						</li><?php 
        }
        do_action('restaurantpress_food_group_write_panel_tabs');
        ?>
			</ul>
			<div id="general_group_data" class="panel restaurantpress_options_panel hidden"><?php 
        echo '<div class="options_group">';
        // Layout Type
        restaurantpress_wp_select(array('id' => 'layout_type', 'label' => __('Layout Type', 'restaurantpress'), 'options' => array('one_column' => __('One Column', 'restaurantpress'), 'two_column' => __('Two Column', 'restaurantpress'), 'grid_image' => __('Grid Image', 'restaurantpress')), 'desc_tip' => 'true', 'description' => __('Define whether or not the entire layout should be column based, or just with the grid image.', 'restaurantpress')));
        echo '</div>';
        echo '<div class="options_group">';
        // Category Icon
        restaurantpress_wp_checkbox(array('id' => '_category_icon', 'wrapper_class' => 'show_to_all_layout', 'label' => __('Category Icon', 'restaurantpress'), 'description' => __('Show category image icon.', 'restaurantpress')));
        // Featured Image
        restaurantpress_wp_checkbox(array('id' => '_featured_image', 'wrapper_class' => 'hide_if_grid_image', 'label' => __('Featured Image', 'restaurantpress'), 'description' => __('Disable the featured image.', 'restaurantpress')));
        echo '</div>';
        do_action('restaurantpress_group_options_general');
        ?>
</div>
			<div id="grouping_group_data" class="panel restaurantpress_options_panel hidden"><?php 
        echo '<div class="options_group">';
        // Grouping Categories
        ?>
				<p class="form-field"><label for="food_grouping"><?php 
        _e('Grouping', 'restaurantpress');
        ?>
</label>
				<select id="food_grouping" name="food_grouping[]" style="width: 50%;" class="rp-enhanced-select" multiple="multiple" data-placeholder="<?php 
        esc_attr_e('Any category', 'restaurantpress');
        ?>
">
					<?php 
        $category_ids = (array) get_post_meta($post->ID, 'food_grouping', true);
        $categories = get_terms('food_menu_cat', 'orderby=name&hide_empty=0');
        if ($categories) {
            foreach ($categories as $cat) {
                echo '<option value="' . esc_attr($cat->term_id) . '"' . selected(in_array($cat->term_id, $category_ids), true, false) . '>' . esc_html($cat->name) . '</option>';
            }
        }
        ?>
				</select> <?php 
        echo rp_help_tip(__('A food must be in this category for the group to remain valid.', 'restaurantpress'));
        ?>
</p>
				<?php 
        echo '</div>';
        ?>
</div>
			<?php 
        do_action('restaurantpress_group_data_panels');
        ?>
			<div class="clear"></div>
		</div>
		<?php 
    }
 /**
  * Helper function to get the formated description and tip HTML for a
  * given form field. Plugins can call this when implementing their own custom
  * settings types.
  *
  * @param  array $value The form field value array
  * @return array The description and tip as a 2 element array
  */
 public static function get_field_description($value)
 {
     $description = '';
     $tooltip_html = '';
     if (true === $value['desc_tip']) {
         $tooltip_html = $value['desc'];
     } elseif (!empty($value['desc_tip'])) {
         $description = $value['desc'];
         $tooltip_html = $value['desc_tip'];
     } elseif (!empty($value['desc'])) {
         $description = $value['desc'];
     }
     if ($description && in_array($value['type'], array('textarea', 'radio'))) {
         $description = '<p style="margin-top:0">' . wp_kses_post($description) . '</p>';
     } elseif ($description && in_array($value['type'], array('checkbox'))) {
         $description = wp_kses_post($description);
     } elseif ($description) {
         $description = '<span class="description">' . wp_kses_post($description) . '</span>';
     }
     if ($tooltip_html && in_array($value['type'], array('checkbox'))) {
         $tooltip_html = '<p class="description">' . $tooltip_html . '</p>';
     } elseif ($tooltip_html) {
         $tooltip_html = rp_help_tip($tooltip_html);
     }
     return array('description' => $description, 'tooltip_html' => $tooltip_html);
 }