/**
  * Save meta box data.
  * @param int $post_id
  */
 public static function save($post_id)
 {
     // Add/Replace data to array
     $food_item_price = rp_clean($_POST['food_item_price']);
     $chef_item_badge = isset($_POST['chef_badge_item']) ? 'yes' : 'no';
     // Save
     update_post_meta($post_id, 'food_item_price', $food_item_price);
     update_post_meta($post_id, 'chef_badge_item', $chef_item_badge);
 }
 /**
  * Save meta box data.
  * @param int $post_id
  */
 public static function save($post_id)
 {
     // Add/Replace data to array
     $layout_type = rp_clean($_POST['layout_type']);
     $category_icon = isset($_POST['_category_icon']) ? 'yes' : 'no';
     $featured_image = isset($_POST['_featured_image']) ? 'yes' : 'no';
     $food_grouping = isset($_POST['food_grouping']) ? array_map('rp_clean', $_POST['food_grouping']) : array();
     // Save
     update_post_meta($post_id, 'layout_type', $layout_type);
     update_post_meta($post_id, '_category_icon', $category_icon);
     update_post_meta($post_id, '_featured_image', $featured_image);
     update_post_meta($post_id, 'food_grouping', $food_grouping);
     do_action('restaurantpress_group_options_save', $post_id);
 }
 /**
  * Save admin fields.
  *
  * Loops though the restaurantpress options array and outputs each field.
  *
  * @param  array $options Options array to output
  * @return bool
  */
 public static function save_fields($options)
 {
     if (empty($_POST)) {
         return false;
     }
     // Options to update will be stored here and saved later.
     $update_options = array();
     // Loop options and get values to save.
     foreach ($options as $option) {
         if (!isset($option['id']) || !isset($option['type'])) {
             continue;
         }
         // Get posted value.
         if (strstr($option['id'], '[')) {
             parse_str($option['id'], $option_name_array);
             $option_name = current(array_keys($option_name_array));
             $setting_name = key($option_name_array[$option_name]);
             $raw_value = isset($_POST[$option_name][$setting_name]) ? wp_unslash($_POST[$option_name][$setting_name]) : null;
         } else {
             $option_name = $option['id'];
             $setting_name = '';
             $raw_value = isset($_POST[$option['id']]) ? wp_unslash($_POST[$option['id']]) : null;
         }
         // Format the value based on option type.
         switch ($option['type']) {
             case 'checkbox':
                 $value = is_null($raw_value) ? 'no' : 'yes';
                 break;
             case 'textarea':
                 $value = wp_kses_post(trim($raw_value));
                 break;
             case 'multiselect':
                 $value = array_filter(array_map('rp_clean', (array) $raw_value));
                 break;
             case 'image_width':
                 $value = array();
                 if (isset($raw_value['width'])) {
                     $value['width'] = rp_clean($raw_value['width']);
                     $value['height'] = rp_clean($raw_value['height']);
                     $value['crop'] = isset($raw_value['crop']) ? 1 : 0;
                 } else {
                     $value['width'] = $option['default']['width'];
                     $value['height'] = $option['default']['height'];
                     $value['crop'] = $option['default']['crop'];
                 }
                 break;
             default:
                 $value = rp_clean($raw_value);
                 break;
         }
         /**
          * Sanitize the value of an option.
          */
         $value = apply_filters('restaurantpress_admin_settings_sanitize_option', $value, $option, $raw_value);
         /**
          * Sanitize the value of an option by option name.
          */
         $value = apply_filters("restaurantpress_admin_settings_sanitize_option_{$option_name}", $value, $option, $raw_value);
         if (is_null($value)) {
             continue;
         }
         // Check if option is an array and handle that differently to single values.
         if ($option_name && $setting_name) {
             if (!isset($update_options[$option_name])) {
                 $update_options[$option_name] = get_option($option_name, array());
             }
             if (!is_array($update_options[$option_name])) {
                 $update_options[$option_name] = array();
             }
             $update_options[$option_name][$setting_name] = $value;
         } else {
             $update_options[$option_name] = $value;
         }
     }
     // Save all options in our array.
     foreach ($update_options as $name => $value) {
         update_option($name, $value);
     }
     return true;
 }