/**
  * Save admin fields.
  *
  * Loops though the propertyhive options array and outputs each field.
  *
  * @access public
  * @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'])) {
             continue;
         }
         $type = isset($value['type']) ? sanitize_title($value['type']) : '';
         // Get the option name
         $option_value = null;
         switch ($type) {
             // Standard types
             case "checkbox":
                 if (isset($_POST[$value['id']])) {
                     $option_value = 'yes';
                 } else {
                     $option_value = 'no';
                 }
                 break;
             case "textarea":
                 if (isset($_POST[$value['id']])) {
                     $option_value = wp_kses_post(trim(stripslashes($_POST[$value['id']])));
                 } else {
                     $option_value = '';
                 }
                 break;
             case "text":
             case 'email':
             case 'number':
             case "select":
             case "color":
             case 'password':
             case "single_select_page":
             case "single_select_country":
             case 'radio':
                 if (isset($_POST[$value['id']])) {
                     $option_value = sanitize_text_field(stripslashes($_POST[$value['id']]));
                 } else {
                     $option_value = '';
                 }
                 break;
                 // Special types
             // Special types
             case "multiselect":
             case "multi_select_countries":
                 // Get countries array
                 if (isset($_POST[$value['id']])) {
                     $selected_countries = array_map('ph_clean', array_map('stripslashes', (array) $_POST[$value['id']]));
                 } else {
                     $selected_countries = array();
                 }
                 $option_value = $selected_countries;
                 break;
             case "image_width":
                 if (isset($_POST[$value['id']]['width'])) {
                     $update_options[$value['id']]['width'] = ph_clean(stripslashes($_POST[$value['id']]['width']));
                     $update_options[$value['id']]['height'] = ph_clean(stripslashes($_POST[$value['id']]['height']));
                     if (isset($_POST[$value['id']]['crop'])) {
                         $update_options[$value['id']]['crop'] = 1;
                     } else {
                         $update_options[$value['id']]['crop'] = 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;
                 // Custom handling
             // Custom handling
             default:
                 do_action('propertyhive_update_option_' . $type, $value);
                 break;
         }
         if (!is_null($option_value)) {
             // Check if option is an array
             if (strstr($value['id'], '[')) {
                 parse_str($value['id'], $option_array);
                 // Option name is first key
                 $option_name = current(array_keys($option_array));
                 // 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();
                 }
                 // Set keys and value
                 $key = key($option_array[$option_name]);
                 $update_options[$option_name][$key] = $option_value;
                 // Single value
             } else {
                 $update_options[$value['id']] = $option_value;
             }
         }
         // Custom handling
         do_action('propertyhive_update_option', $value);
     }
     // Now save the options
     foreach ($update_options as $name => $value) {
         update_option($name, $value);
     }
     return true;
 }
 /**
  * Search by ID, address and reference number
  *
  * @param string $where
  * @return string
  */
 public function property_search($where)
 {
     global $pagenow, $wpdb, $wp;
     if ('edit.php' != $pagenow || !is_search() || !isset($wp->query_vars['s']) || 'property' != $wp->query_vars['post_type']) {
         return $where;
     }
     if (trim($wp->query_vars['s']) == '') {
         return $where;
     }
     $search_ids = array();
     $terms = explode(',', $wp->query_vars['s']);
     foreach ($terms as $term) {
         if (is_numeric($term)) {
             $search_ids[] = $term;
         }
         // Attempt to get an ID by searching for address and reference number
         $query = $wpdb->prepare("SELECT \n\t\t\t\t\tID \n\t\t\t\tFROM \n\t\t\t\t\t{$wpdb->posts} \n\t\t\t\tINNER JOIN {$wpdb->postmeta} AS mt1 ON {$wpdb->posts}.ID = mt1.post_id\n\t\t\t\tWHERE \n\t\t\t\t\t(\n\t\t\t\t\t\t(mt1.meta_key='_address_name_number' AND mt1.meta_value LIKE %s)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(mt1.meta_key='_address_street' AND mt1.meta_value LIKE %s)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(mt1.meta_key='_address_2' AND mt1.meta_value LIKE %s)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(mt1.meta_key='_address_3' AND mt1.meta_value LIKE %s)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(mt1.meta_key='_address_4' AND mt1.meta_value LIKE %s)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(mt1.meta_key='_address_postcode' AND mt1.meta_value LIKE %s)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(mt1.meta_key='_reference_number' AND mt1.meta_value = %s)\n\t\t\t\t\t)\n\t\t\t\tAND \n\t\t\t\t\tpost_type='property'\n\t\t\t\tGROUP BY ID\n\t\t\t\t", '%' . $wpdb->esc_like(ph_clean($term)) . '%', '%' . $wpdb->esc_like(ph_clean($term)) . '%', '%' . $wpdb->esc_like(ph_clean($term)) . '%', '%' . $wpdb->esc_like(ph_clean($term)) . '%', '%' . $wpdb->esc_like(ph_clean($term)) . '%', '%' . $wpdb->esc_like(ph_clean($term)) . '%', '' . $wpdb->esc_like(ph_clean($term)) . '');
         $search_posts = $wpdb->get_results($query);
         $search_posts = wp_list_pluck($search_posts, 'ID');
         if (sizeof($search_posts) > 0) {
             $search_ids = array_merge($search_ids, $search_posts);
         }
     }
     $search_ids = array_filter(array_unique(array_map('absint', $search_ids)));
     if (sizeof($search_ids) > 0) {
         $where = str_replace('AND (((', "AND ( ({$wpdb->posts}.ID IN (" . implode(',', $search_ids) . ")) OR ((", $where);
     }
     return $where;
 }
 /**
  * Output the property sorting options.
  *
  * @access public
  * @subpackage  Loop
  * @return void
  */
 function propertyhive_catalog_ordering()
 {
     $orderby = isset($_GET['orderby']) ? ph_clean($_GET['orderby']) : apply_filters('propertyhive_default_catalog_orderby', get_option('propertyhive_default_catalog_orderby'));
     ph_get_template('search/orderby.php', array('orderby' => $orderby));
 }