/**
  * Save settings
  */
 public function save()
 {
     global $current_section;
     $settings = $this->get_settings();
     PH_Admin_Settings::save_fields($settings);
     if ($current_section) {
         do_action('propertyhive_update_options_' . $this->id . '_' . $current_section);
     }
 }
 /**
  * Save settings.
  */
 public function save()
 {
     PH_Admin_Settings::save_fields($this->get_settings());
     if (isset($_POST['propertyhive_auto_property_match']) && $_POST['propertyhive_auto_property_match'] == '1') {
         update_option('propertyhive_auto_property_match_enabled_date', date("Y-m-d H:i:s"), FALSE);
         wp_schedule_event(time(), 'hourly', 'propertyhive_auto_email_match');
         //  Skew it by 30 minutes to reduce conflict with email log processing
     } else {
         wp_clear_scheduled_hook('propertyhive_auto_email_match');
     }
 }
 /**
  * Include the settings page classes
  */
 public static function get_settings_pages()
 {
     if (empty(self::$settings)) {
         $settings = array();
         include_once 'settings/class-ph-settings-page.php';
         $settings[] = (include 'settings/class-ph-settings-general.php');
         $settings[] = (include 'settings/class-ph-settings-offices.php');
         $settings[] = (include 'settings/class-ph-settings-custom-fields.php');
         $settings[] = (include 'settings/class-ph-settings-emails.php');
         $settings[] = (include 'settings/class-ph-settings-licenses.php');
         $settings[] = (include 'settings/class-ph-settings-add-ons.php');
         self::$settings = apply_filters('propertyhive_get_settings_pages', $settings);
     }
     return self::$settings;
 }
 /**
  * Output the settings
  */
 public function output()
 {
     global $current_section;
     if ($current_section) {
         if (isset($_REQUEST['id'])) {
             $current_id = empty($_REQUEST['id']) ? '' : sanitize_title($_REQUEST['id']);
             switch ($current_section) {
                 case "availability":
                     $settings = $this->get_custom_fields_availability_setting();
                     break;
                 case "availability-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'availability', __('Availability', 'propertyhive'));
                     break;
                 case "property-type":
                     $settings = $this->get_custom_fields_property_type_setting();
                     break;
                 case "property-type-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'property_type', __('Property Type', 'propertyhive'));
                     break;
                 case "commercial-property-type":
                     $settings = $this->get_custom_fields_commercial_property_type_setting();
                     break;
                 case "commercial-property-type-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'commercial_property_type', __('Property Type', 'propertyhive'));
                     break;
                 case "location":
                     $settings = $this->get_custom_fields_location_setting();
                     break;
                 case "location-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'location', __('Location', 'propertyhive'));
                     break;
                 case "parking":
                     $settings = $this->get_custom_fields_parking_setting();
                     break;
                 case "parking-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'parking', __('Parking', 'propertyhive'));
                     break;
                 case "outside-space":
                     $settings = $this->get_custom_fields_outside_space_setting();
                     break;
                 case "outside-space-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'outside_space', __('Outside Space', 'propertyhive'));
                     break;
                 case "price-qualifier":
                     $settings = $this->get_custom_fields_price_qualifier_setting();
                     break;
                 case "price-qualifier-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'price_qualifier', __('Price Qualifier', 'propertyhive'));
                     break;
                 case "sale-by":
                     $settings = $this->get_custom_fields_sale_by_setting();
                     break;
                 case "sale-by-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'sale_by', __('Sale By', 'propertyhive'));
                     break;
                 case "tenure":
                     $settings = $this->get_custom_fields_tenure_setting();
                     break;
                 case "tenure-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'tenure', __('Tenure', 'propertyhive'));
                     break;
                 case "commercial-tenure":
                     $settings = $this->get_custom_fields_commercial_tenure_setting();
                     break;
                 case "commercial-tenure-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'commercial_tenure', __('Tenure', 'propertyhive'));
                     break;
                 case "furnished":
                     $settings = $this->get_custom_fields_furnished_setting();
                     break;
                 case "furnished-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'furnished', __('Furnished', 'propertyhive'));
                     break;
                 case "marketing-flag":
                     $settings = $this->get_custom_fields_marketing_flag_setting();
                     break;
                 case "marketing-flag-delete":
                     $settings = $this->get_custom_fields_delete($current_id, 'marketing_flag', __('Marketing Flag', 'propertyhive'));
                     break;
                 default:
                     echo 'UNKNOWN CUSTOM FIELD';
             }
             PH_Admin_Settings::output_fields($settings);
         } else {
             global $hide_save_button;
             $hide_save_button = true;
             // The main custom field screen listing them in a table
             $settings = $this->get_custom_fields_setting($current_section);
             PH_Admin_Settings::output_fields($settings);
         }
     } else {
         $settings = $this->get_settings();
         PH_Admin_Settings::output_fields($settings);
     }
 }
 /**
  * Save settings
  */
 public function save()
 {
     global $current_section, $post;
     if ($current_section == 'add') {
         // TODO: Validate (check for blank fields, and that office name doest exist already)
         // Insert office
         $office_post = array('post_title' => wp_strip_all_tags($_POST['office_name']), 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'office');
         // Insert the post into the database
         $office_post_id = wp_insert_post($office_post);
         // TODO: Check for errors returned from wp_insert_post()
         // TODO: Add meta information
         PH_Admin_Settings::add_message(__('Office added successfully', 'propertyhive') . ' ' . '<a href="' . admin_url('admin.php?page=ph-settings&tab=offices') . '">' . __('Return to offices', 'propertyhive') . '</a>');
     } elseif ($current_section == 'edit') {
         $current_id = empty($_REQUEST['id']) ? '' : sanitize_title($_REQUEST['id']);
         // TODO: Validate
         // TODO: Make sure this ID belongs to an office
         // TODO: Update slug?
         // Update office
         $office_post = array('ID' => $current_id, 'post_title' => wp_strip_all_tags($_POST['office_name']));
         wp_update_post($office_post);
         $office_post_id = $current_id;
         // TODO: Check for errors returned from wp_update_post()
         // TODO: Update meta information
         PH_Admin_Settings::add_message(__('Office details updated successfully', 'propertyhive') . ' ' . '<a href="' . admin_url('admin.php?page=ph-settings&tab=offices') . '">' . __('Return to offices', 'propertyhive') . '</a>');
     } elseif ($current_section == 'delete') {
         if (isset($_POST['confirm_removal']) && $_POST['confirm_removal'] == '1') {
             $current_id = empty($_REQUEST['id']) ? '' : sanitize_title($_REQUEST['id']);
             // Get number of properties assigned to this term
             $query_args = array('post_type' => 'property', 'nopaging' => true, 'post_status' => array('pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash'), 'meta_query' => array(array('key' => '_office_id', 'value' => $current_id, 'compare' => '=')));
             $property_query = new WP_Query($query_args);
             if ($property_query->have_posts()) {
                 if (!isset($_POST['reassign_to']) || isset($_POST['reassign_to']) && empty($_POST['reassign_to'])) {
                     die("Not assigning properties to new office. Please try again");
                 } else {
                     $post_type = get_post_type($_POST['reassign_to']);
                     if ($post_type != 'office') {
                         die("New office isn't of type office. It's of type: " . $post_type);
                     }
                 }
                 while ($property_query->have_posts()) {
                     $property_query->the_post();
                     update_post_meta($post->ID, '_office_id', $_POST['reassign_to']);
                     // TODO: Check for WP_ERROR
                 }
             }
             wp_delete_post($current_id);
             // TODO: Check for WP_ERROR
         }
     }
     if ($current_section != 'delete') {
         if ($current_section != 'add' && $current_section != 'edit') {
             // Set all offices as not primary
             // Prevents multiple offices being set as primary
             $args = array('post_type' => 'office', 'nopaging' => true, 'orderby' => 'title', 'order' => 'ASC');
             $office_query = new WP_Query($args);
             if ($office_query->have_posts()) {
                 while ($office_query->have_posts()) {
                     $office_query->the_post();
                     // Set selected office as primary
                     update_post_meta($post->ID, 'primary', '0');
                 }
             }
             wp_reset_postdata();
             // Set selected office as primary
             update_post_meta(wp_strip_all_tags($_POST['primary']), 'primary', '1');
         } else {
             update_post_meta($office_post_id, '_office_address_1', wp_strip_all_tags($_POST['_office_address_1']));
             update_post_meta($office_post_id, '_office_address_2', wp_strip_all_tags($_POST['_office_address_2']));
             update_post_meta($office_post_id, '_office_address_3', wp_strip_all_tags($_POST['_office_address_3']));
             update_post_meta($office_post_id, '_office_address_4', wp_strip_all_tags($_POST['_office_address_4']));
             update_post_meta($office_post_id, '_office_address_postcode', wp_strip_all_tags($_POST['_office_address_postcode']));
             update_post_meta($office_post_id, '_office_telephone_number_sales', isset($_POST['_office_telephone_number_sales']) ? wp_strip_all_tags($_POST['_office_telephone_number_sales']) : '');
             update_post_meta($office_post_id, '_office_email_address_sales', isset($_POST['_office_email_address_sales']) ? wp_strip_all_tags($_POST['_office_email_address_sales']) : '');
             update_post_meta($office_post_id, '_office_telephone_number_lettings', isset($_POST['_office_telephone_number_lettings']) ? wp_strip_all_tags($_POST['_office_telephone_number_lettings']) : '');
             update_post_meta($office_post_id, '_office_email_address_lettings', isset($_POST['_office_email_address_lettings']) ? wp_strip_all_tags($_POST['_office_email_address_lettings']) : '');
             update_post_meta($office_post_id, '_office_telephone_number_commercial', isset($_POST['_office_telephone_number_commercial']) ? wp_strip_all_tags($_POST['_office_telephone_number_commercial']) : '');
             update_post_meta($office_post_id, '_office_email_address_commercial', isset($_POST['_office_email_address_commercial']) ? wp_strip_all_tags($_POST['_office_email_address_commercial']) : '');
             update_post_meta($office_post_id, '_office_latitude', wp_strip_all_tags($_POST['_office_latitude']));
             update_post_meta($office_post_id, '_office_longitude', wp_strip_all_tags($_POST['_office_longitude']));
             do_action('propertyhive_save_office', $office_post_id);
         }
     }
 }
/**
 * Get a setting from the settings API.
 *
 * @param mixed $option
 * @return string
 */
function propertyhive_settings_get_option($option_name, $default = '')
{
    if (!class_exists('PH_Admin_Settings')) {
        include 'class-ph-admin-settings.php';
    }
    return PH_Admin_Settings::get_option($option_name, $default);
}
 /**
  * Save settings.
  */
 public function save()
 {
     PH_Admin_Settings::save_fields($this->get_settings());
     PH()->license->ph_check_licenses(true);
 }
 /**
  * Save settings
  */
 public function save()
 {
     global $current_section;
     if ($current_section != '') {
         switch ($current_section) {
             case 'international':
                 if (!isset($_POST['propertyhive_countries']) || isset($_POST['propertyhive_countries']) && empty($_POST['propertyhive_countries'])) {
                     // If we haven't selected which countries we operate in
                     update_option('propertyhive_countries', array($_POST['propertyhive_default_country']));
                 } else {
                     // We have default country and countries set
                     // Make sure default country is in list of countries selected
                     if (!in_array($_POST['propertyhive_default_country'], $_POST['propertyhive_countries'])) {
                         $_POST['propertyhive_default_country'] = $_POST['propertyhive_countries'][0];
                     }
                     update_option('propertyhive_default_country', $_POST['propertyhive_default_country']);
                     update_option('propertyhive_countries', $_POST['propertyhive_countries']);
                 }
                 do_action('propertyhive_update_currency_exchange_rates');
                 break;
             case 'map':
                 $settings = $this->get_general_map_setting();
                 PH_Admin_Settings::save_fields($settings);
                 break;
             default:
                 die("Unknown setting section");
         }
     } else {
         $settings = $this->get_settings();
         PH_Admin_Settings::save_fields($settings);
         flush_rewrite_rules();
     }
 }
 /**
  * Output the settings
  */
 public function output()
 {
     $settings = $this->get_settings();
     PH_Admin_Settings::output_fields($settings);
 }
 /**
  * Init the settings page
  */
 public function settings_page()
 {
     include_once 'class-ph-admin-settings.php';
     PH_Admin_Settings::output();
 }