/**
  * Save admin fields.
  *
  * Loops though the recipe hero options array and outputs each field.
  *
  * @param array $options Opens array to output
  * @return bool
  */
 public static function save_fields($options)
 {
     if (empty($_POST)) {
         return false;
     }
     // Options to update will be stored here
     $update_options = array();
     // Loop options and get values to save
     foreach ($options as $value) {
         if (!isset($value['id']) || !isset($value['type'])) {
             continue;
         }
         // Get posted value
         if (strstr($value['id'], '[')) {
             parse_str($value['id'], $option_name_array);
             $option_name = current(array_keys($option_name_array));
             $setting_name = key($option_name_array[$option_name]);
             $option_value = isset($_POST[$option_name][$setting_name]) ? stripslashes_deep($_POST[$option_name][$setting_name]) : null;
         } else {
             $option_name = $value['id'];
             $setting_name = '';
             $option_value = isset($_POST[$value['id']]) ? stripslashes_deep($_POST[$value['id']]) : null;
         }
         // Format value
         switch (sanitize_title($value['type'])) {
             case 'checkbox':
                 $option_value = is_null($option_value) ? 'no' : 'yes';
                 break;
             case 'textarea':
                 $option_value = wp_kses_post(trim($option_value));
                 break;
             case 'text':
             case 'email':
             case 'number':
             case 'select':
             case 'color':
             case 'password':
             case 'radio':
                 $option_value = rh_clean($option_value);
                 break;
             case 'multiselect':
                 $option_value = array_filter(array_map('rh_clean', (array) $option_value));
                 break;
             case 'image_width':
                 if (isset($option_value['width'])) {
                     $update_options[$value['id']]['width'] = rh_clean($option_value['width']);
                     $update_options[$value['id']]['height'] = rh_clean($option_value['height']);
                     $update_options[$value['id']]['crop'] = isset($option_value['crop']) ? 1 : 0;
                 } else {
                     $update_options[$value['id']]['width'] = $value['default']['width'];
                     $update_options[$value['id']]['height'] = $value['default']['height'];
                     $update_options[$value['id']]['crop'] = $value['default']['crop'];
                 }
                 break;
             default:
                 do_action('recipe_hero_update_option_' . sanitize_title($value['type']), $value);
                 break;
         }
         if (!is_null($option_value)) {
             // Check if option is an array
             if ($option_name && $setting_name) {
                 // Get old option value
                 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] = $option_value;
                 // Single value
             } else {
                 $update_options[$option_name] = $option_value;
             }
         }
         // Custom handling
         do_action('recipe_hero_update_option', $value);
     }
     // Now save the options
     foreach ($update_options as $name => $value) {
         update_option($name, $value);
     }
     return true;
 }
 /**
  * Save meta box data
  */
 public static function gallery_save($post_id, $post)
 {
     if (isset($_POST['recipe_image_gallery'])) {
         $attachment_ids = array_filter(explode(',', rh_clean($_POST['recipe_image_gallery'])));
         update_post_meta($post_id, '_recipe_image_gallery', implode(',', $attachment_ids));
     }
 }
 /**
  * Save the settings
  */
 public function settings_save()
 {
     if (!is_admin()) {
         return;
     }
     // We need to save the options ourselves; settings api does not trigger save for the permalinks page
     if (isset($_POST['permalink_structure']) || isset($_POST['cuisine_base']) || isset($_POST['course_base']) && isset($_POST['recipe_permalink'])) {
         // Cat and tag bases
         $recipe_hero_recipe_cuisine_slug = rh_clean($_POST['recipe_hero_recipe_cuisine_slug']);
         $recipe_hero_recipe_course_slug = rh_clean($_POST['recipe_hero_recipe_course_slug']);
         $permalinks = get_option('recipe_hero_permalinks');
         if (!$permalinks) {
             $permalinks = array();
         }
         $permalinks['cuisine_base'] = untrailingslashit($recipe_hero_recipe_cuisine_slug);
         $permalinks['course_base'] = untrailingslashit($recipe_hero_recipe_course_slug);
         // Recipe base
         $recipe_permalink = rh_clean($_POST['recipe_permalink']);
         if ($recipe_permalink == 'custom') {
             // Get permalink without slashes
             $recipe_permalink = trim(rh_clean($_POST['recipe_permalink_structure']), '/');
             // Prepending slash
             $recipe_permalink = '/' . $recipe_permalink;
         } elseif (empty($recipe_permalink)) {
             $recipe_permalink = false;
         }
         $permalinks['recipe_base'] = untrailingslashit($recipe_permalink);
         // Shop base may require verbose page rules if nesting pages
         $recipe_page_id = rh_get_page_id('recipes');
         $recipes_permalink = $recipe_page_id > 0 && get_post($recipe_page_id) ? get_page_uri($recipe_page_id) : _x('shop', 'default-slug', 'recipe-hero');
         if ($recipe_page_id && trim($permalinks['recipe_base'], '/') === $recipes_permalink) {
             $permalinks['use_verbose_page_rules'] = true;
         }
         update_option('recipe_hero_permalinks', $permalinks);
     }
 }
 /**
  * Validate Select Field.
  *
  * Make sure the data is escaped correctly, etc.
  *
  * @param mixed $key
  * @since 1.0.0
  * @return string
  */
 public function validate_select_field($key)
 {
     $value = $this->get_option($key);
     if (isset($_POST[$this->plugin_id . $this->id . '_' . $key])) {
         $value = rh_clean(stripslashes($_POST[$this->plugin_id . $this->id . '_' . $key]));
     }
     return $value;
 }
Example #5
0
 /**
  * Returns an array of arguments for ordering recipes based on the selected values
  *
  * @access public
  * @return array
  */
 public function get_catalog_ordering_args($orderby = '', $order = '')
 {
     global $wpdb;
     // Get ordering from query string unless defined
     if (!$orderby) {
         $orderby_value = isset($_GET['orderby']) ? rh_clean($_GET['orderby']) : apply_filters('recipe_hero_recipe_order', get_option('recipe_hero_recipe_order'));
         // Get order + orderby args from string
         $orderby_value = explode('-', $orderby_value);
         $orderby = esc_attr($orderby_value[0]);
         $order = !empty($orderby_value[1]) ? $orderby_value[1] : $order;
     }
     $orderby = strtolower($orderby);
     $order = strtoupper($order);
     $args = array();
     // default - menu_order
     $args['orderby'] = 'menu_order title';
     $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC';
     $args['meta_key'] = '';
     switch ($orderby) {
         case 'rand':
             $args['orderby'] = 'rand';
             break;
         case 'date':
             $args['orderby'] = 'date';
             $args['order'] = $order == 'ASC' ? 'ASC' : 'DESC';
             break;
         case 'title':
             $args['orderby'] = 'title';
             $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC';
             break;
     }
     return apply_filters('recipe_hero_get_recipe_ordering_args', $args);
 }