/**
  * Add RP Image sizes to WP.
  */
 private function add_image_sizes()
 {
     $food_grid = rp_get_image_size('food_grid');
     $food_thumbnail = rp_get_image_size('food_thumbnail');
     add_image_size('food_grid', $food_grid['width'], $food_grid['height'], $food_grid['crop']);
     add_image_size('food_thumbnail', $food_thumbnail['width'], $food_thumbnail['height'], $food_thumbnail['crop']);
 }
    /**
     * Output admin fields.
     *
     * Loops though the restaurantpress options array and outputs each field.
     *
     * @param array $options Opens array to output
     */
    public static function output_fields($options)
    {
        foreach ($options as $value) {
            if (!isset($value['type'])) {
                continue;
            }
            if (!isset($value['id'])) {
                $value['id'] = '';
            }
            if (!isset($value['title'])) {
                $value['title'] = isset($value['name']) ? $value['name'] : '';
            }
            if (!isset($value['class'])) {
                $value['class'] = '';
            }
            if (!isset($value['css'])) {
                $value['css'] = '';
            }
            if (!isset($value['default'])) {
                $value['default'] = '';
            }
            if (!isset($value['desc'])) {
                $value['desc'] = '';
            }
            if (!isset($value['desc_tip'])) {
                $value['desc_tip'] = false;
            }
            if (!isset($value['placeholder'])) {
                $value['placeholder'] = '';
            }
            // Custom attribute handling
            $custom_attributes = array();
            if (!empty($value['custom_attributes']) && is_array($value['custom_attributes'])) {
                foreach ($value['custom_attributes'] as $attribute => $attribute_value) {
                    $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($attribute_value) . '"';
                }
            }
            // Description handling
            $field_description = self::get_field_description($value);
            extract($field_description);
            // Switch based on type
            switch ($value['type']) {
                // Section Titles
                case 'title':
                    if (!empty($value['title'])) {
                        echo '<h2>' . esc_html($value['title']) . '</h2>';
                    }
                    if (!empty($value['desc'])) {
                        echo wpautop(wptexturize(wp_kses_post($value['desc'])));
                    }
                    echo '<table class="form-table">' . "\n\n";
                    if (!empty($value['id'])) {
                        do_action('restaurantpress_settings_' . sanitize_title($value['id']));
                    }
                    break;
                    // Section Ends
                // Section Ends
                case 'sectionend':
                    if (!empty($value['id'])) {
                        do_action('restaurantpress_settings_' . sanitize_title($value['id']) . '_end');
                    }
                    echo '</table>';
                    if (!empty($value['id'])) {
                        do_action('restaurantpress_settings_' . sanitize_title($value['id']) . '_after');
                    }
                    break;
                    // Standard text inputs and subtypes like 'number'
                // Standard text inputs and subtypes like 'number'
                case 'text':
                case 'email':
                case 'number':
                case 'color':
                case 'password':
                    $type = $value['type'];
                    $option_value = self::get_option($value['id'], $value['default']);
                    if ($value['type'] == 'color') {
                        $type = 'text';
                        $value['class'] .= 'colorpick';
                        $description .= '<div id="colorPickerDiv_' . esc_attr($value['id']) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>';
                    }
                    ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo esc_html($value['title']);
                    ?>
</label>
							<?php 
                    echo $tooltip_html;
                    ?>
						</th>
						<td class="forminp forminp-<?php 
                    echo sanitize_title($value['type']);
                    ?>
">
							<?php 
                    if ('color' == $value['type']) {
                        echo '<span class="colorpickpreview" style="background: ' . esc_attr($option_value) . ';"></span>';
                    }
                    ?>
							<input
								name="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
								id="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
								type="<?php 
                    echo esc_attr($type);
                    ?>
"
								style="<?php 
                    echo esc_attr($value['css']);
                    ?>
"
								value="<?php 
                    echo esc_attr($option_value);
                    ?>
"
								class="<?php 
                    echo esc_attr($value['class']);
                    ?>
"
								placeholder="<?php 
                    echo esc_attr($value['placeholder']);
                    ?>
"
								<?php 
                    echo implode(' ', $custom_attributes);
                    ?>
								/> <?php 
                    echo $description;
                    ?>
						</td>
					</tr><?php 
                    break;
                    // Textarea
                // Textarea
                case 'textarea':
                    $option_value = self::get_option($value['id'], $value['default']);
                    ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo esc_html($value['title']);
                    ?>
</label>
							<?php 
                    echo $tooltip_html;
                    ?>
						</th>
						<td class="forminp forminp-<?php 
                    echo sanitize_title($value['type']);
                    ?>
">
							<?php 
                    echo $description;
                    ?>

							<textarea
								name="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
								id="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
								style="<?php 
                    echo esc_attr($value['css']);
                    ?>
"
								class="<?php 
                    echo esc_attr($value['class']);
                    ?>
"
								placeholder="<?php 
                    echo esc_attr($value['placeholder']);
                    ?>
"
								<?php 
                    echo implode(' ', $custom_attributes);
                    ?>
								><?php 
                    echo esc_textarea($option_value);
                    ?>
</textarea>
						</td>
					</tr><?php 
                    break;
                    // Select boxes
                // Select boxes
                case 'select':
                case 'multiselect':
                    $option_value = self::get_option($value['id'], $value['default']);
                    ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo esc_html($value['title']);
                    ?>
</label>
							<?php 
                    echo $tooltip_html;
                    ?>
						</th>
						<td class="forminp forminp-<?php 
                    echo sanitize_title($value['type']);
                    ?>
">
							<select
								name="<?php 
                    echo esc_attr($value['id']);
                    if ($value['type'] == 'multiselect') {
                        echo '[]';
                    }
                    ?>
"
								id="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
								style="<?php 
                    echo esc_attr($value['css']);
                    ?>
"
								class="<?php 
                    echo esc_attr($value['class']);
                    ?>
"
								<?php 
                    echo implode(' ', $custom_attributes);
                    ?>
								<?php 
                    echo 'multiselect' == $value['type'] ? 'multiple="multiple"' : '';
                    ?>
								>
								<?php 
                    foreach ($value['options'] as $key => $val) {
                        ?>
										<option value="<?php 
                        echo esc_attr($key);
                        ?>
" <?php 
                        if (is_array($option_value)) {
                            selected(in_array($key, $option_value), true);
                        } else {
                            selected($option_value, $key);
                        }
                        ?>
><?php 
                        echo $val;
                        ?>
</option>
										<?php 
                    }
                    ?>
							</select> <?php 
                    echo $description;
                    ?>
						</td>
					</tr><?php 
                    break;
                    // Radio inputs
                // Radio inputs
                case 'radio':
                    $option_value = self::get_option($value['id'], $value['default']);
                    ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo esc_html($value['title']);
                    ?>
</label>
							<?php 
                    echo $tooltip_html;
                    ?>
						</th>
						<td class="forminp forminp-<?php 
                    echo sanitize_title($value['type']);
                    ?>
">
							<fieldset>
								<?php 
                    echo $description;
                    ?>
								<ul>
								<?php 
                    foreach ($value['options'] as $key => $val) {
                        ?>
										<li>
											<label><input
												name="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
												value="<?php 
                        echo $key;
                        ?>
"
												type="radio"
												style="<?php 
                        echo esc_attr($value['css']);
                        ?>
"
												class="<?php 
                        echo esc_attr($value['class']);
                        ?>
"
												<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
												<?php 
                        checked($key, $option_value);
                        ?>
												/> <?php 
                        echo $val;
                        ?>
</label>
										</li>
										<?php 
                    }
                    ?>
								</ul>
							</fieldset>
						</td>
					</tr><?php 
                    break;
                    // Checkbox input
                // Checkbox input
                case 'checkbox':
                    $option_value = self::get_option($value['id'], $value['default']);
                    $visbility_class = array();
                    if (!isset($value['hide_if_checked'])) {
                        $value['hide_if_checked'] = false;
                    }
                    if (!isset($value['show_if_checked'])) {
                        $value['show_if_checked'] = false;
                    }
                    if ('yes' == $value['hide_if_checked'] || 'yes' == $value['show_if_checked']) {
                        $visbility_class[] = 'hidden_option';
                    }
                    if ('option' == $value['hide_if_checked']) {
                        $visbility_class[] = 'hide_options_if_checked';
                    }
                    if ('option' == $value['show_if_checked']) {
                        $visbility_class[] = 'show_options_if_checked';
                    }
                    if (!isset($value['checkboxgroup']) || 'start' == $value['checkboxgroup']) {
                        ?>
							<tr valign="top" class="<?php 
                        echo esc_attr(implode(' ', $visbility_class));
                        ?>
">
								<th scope="row" class="titledesc"><?php 
                        echo esc_html($value['title']);
                        ?>
</th>
								<td class="forminp forminp-checkbox">
									<fieldset>
						<?php 
                    } else {
                        ?>
							<fieldset class="<?php 
                        echo esc_attr(implode(' ', $visbility_class));
                        ?>
">
						<?php 
                    }
                    if (!empty($value['title'])) {
                        ?>
							<legend class="screen-reader-text"><span><?php 
                        echo esc_html($value['title']);
                        ?>
</span></legend>
						<?php 
                    }
                    ?>
						<label for="<?php 
                    echo $value['id'];
                    ?>
">
							<input
								name="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
								id="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
								type="checkbox"
								class="<?php 
                    echo esc_attr(isset($value['class']) ? $value['class'] : '');
                    ?>
"
								value="1"
								<?php 
                    checked($option_value, 'yes');
                    ?>
								<?php 
                    echo implode(' ', $custom_attributes);
                    ?>
							/> <?php 
                    echo $description;
                    ?>
						</label> <?php 
                    echo $tooltip_html;
                    ?>
					<?php 
                    if (!isset($value['checkboxgroup']) || 'end' == $value['checkboxgroup']) {
                        ?>
									</fieldset>
								</td>
							</tr>
						<?php 
                    } else {
                        ?>
							</fieldset>
						<?php 
                    }
                    break;
                    // Image width settings
                // Image width settings
                case 'image_width':
                    $image_size = str_replace('_image_size', '', $value['id']);
                    $size = rp_get_image_size($image_size);
                    $width = isset($size['width']) ? $size['width'] : $value['default']['width'];
                    $height = isset($size['height']) ? $size['height'] : $value['default']['height'];
                    $crop = isset($size['crop']) ? $size['crop'] : $value['default']['crop'];
                    $disabled_attr = '';
                    $disabled_message = '';
                    if (has_filter('restaurantpress_get_image_size_' . $image_size)) {
                        $disabled_attr = 'disabled="disabled"';
                        $disabled_message = "<p><small>" . __('The settings of this image size have been disabled because its values are being overwritten by a filter.', 'restaurantpress') . "</small></p>";
                    }
                    ?>
<tr valign="top">
						<th scope="row" class="titledesc"><?php 
                    echo esc_html($value['title']);
                    ?>
 <?php 
                    echo $tooltip_html;
                    echo $disabled_message;
                    ?>
</th>
						<td class="forminp image_width_settings">

							<input name="<?php 
                    echo esc_attr($value['id']);
                    ?>
[width]" <?php 
                    echo $disabled_attr;
                    ?>
 id="<?php 
                    echo esc_attr($value['id']);
                    ?>
-width" type="text" size="3" value="<?php 
                    echo $width;
                    ?>
" /> &times; <input name="<?php 
                    echo esc_attr($value['id']);
                    ?>
[height]" <?php 
                    echo $disabled_attr;
                    ?>
 id="<?php 
                    echo esc_attr($value['id']);
                    ?>
-height" type="text" size="3" value="<?php 
                    echo $height;
                    ?>
" />px

							<label><input name="<?php 
                    echo esc_attr($value['id']);
                    ?>
[crop]" <?php 
                    echo $disabled_attr;
                    ?>
 id="<?php 
                    echo esc_attr($value['id']);
                    ?>
-crop" type="checkbox" value="1" <?php 
                    checked(1, $crop);
                    ?>
 /> <?php 
                    _e('Hard Crop?', 'restaurantpress');
                    ?>
</label>

							</td>
					</tr><?php 
                    break;
                    // Default: run an action
                // Default: run an action
                default:
                    do_action('restaurantpress_admin_field_' . $value['type'], $value);
                    break;
            }
        }
    }
/**
 * Get the placeholder image.
 * @return string
 */
function rp_placeholder_img($size = 'food_thumbnail')
{
    $dimensions = rp_get_image_size($size);
    $thumb_size = $dimensions['width'] == 100 ? 'small' : 'large';
    return apply_filters('restaurantpress_placeholder_img', '<img src="' . rp_placeholder_img_src($thumb_size) . '" alt="' . esc_attr__('Placeholder', 'restaurantpress') . '" width="' . esc_attr($dimensions['width']) . '" class="restaurantpress-placeholder wp-post-image" height="' . esc_attr($dimensions['height']) . '" />', $size, $dimensions);
}