Exemplo n.º 1
0
function est_edit_profilefield()
{
    $error = false;
    $customdata = get_option('est_profilefields');
    $_POST['options'] = array_filter($_POST['options']);
    foreach ($_POST['options'] as $key => $option) {
        if (is_array($option)) {
            if (empty($option['name']) or $option['value'] === '') {
                unset($_POST['options'][$key]);
            }
        }
    }
    $option_types = array('dropdown', 'checkbox', 'radio');
    if (empty($_POST['name'])) {
        $error = true;
    }
    if (in_array($_POST['type'], $option_types) and empty($_POST['options'])) {
        $error = true;
    }
    foreach ($customdata as $customitem) {
        if ($customitem['name'] == $_POST['name'] and $customitem['key'] != bsh_make_custom_key($_POST['name'])) {
            $error = true;
        }
    }
    if ($error == true) {
        $redirect = admin_url('admin.php?page=est_custom_fields_add');
        $redirect = $redirect . '&est_error=edit&key=' . $_POST['original_key'];
    } else {
        global $wpdb;
        $redirect = admin_url('admin.php?page=est_profile_fields_add');
        $redirect = $redirect . '&est_success=edit';
        $key = bsh_make_custom_key($_POST['name']);
        $new_data = array('name' => $_POST['name'], 'key' => $key, 'type' => $_POST['type'], 'format' => $_POST['format']);
        if (!empty($_POST['prefix'])) {
            $new_data['prefix'] = $_POST['prefix'];
        }
        if (!empty($_POST['suffix'])) {
            $new_data['suffix'] = $_POST['suffix'];
        }
        if (!empty($_POST['options'])) {
            $new_data['options'] = $_POST['options'];
        }
        $data = get_option('est_profilefields');
        foreach ($data as $key => $item) {
            if ($item['key'] == $_POST['original_key']) {
                unset($data[$key]);
            }
        }
        $wpdb->update($wpdb->postmeta, array('meta_key' => $new_data['key']), array('meta_key' => $_POST['original_key']), array('%s'), array('%s'));
        $data[$new_data['key']] = $new_data;
        update_option('est_profilefields', $data);
    }
    header('Location: ' . $redirect);
    die;
}
 function save_options()
 {
     $post_id = $this->get_post_id();
     if (!empty($_GET['action']) and $_GET['action']) {
         return;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || defined('DOING_AJAX') && DOING_AJAX) {
         return;
     }
     if (!empty($_POST['post_type']) and 'page' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return;
         }
     } else {
         if (!empty($post_id) and !current_user_can('edit_post', $post_id)) {
             return;
         }
     }
     $postmeta = array();
     if (!empty($_POST['_est_meta_latitude']) and !empty($_POST['_est_meta_longitude'])) {
         $_POST['_est_lat'] = $_POST['_est_meta_latitude'];
         $_POST['_est_lng'] = $_POST['_est_meta_longitude'];
         $_POST['_est_geocode'] = $_POST['_est_meta_latitude'] . ',' . $_POST['_est_meta_longitude'];
     } elseif (get_post_type($post_id) == 'property') {
         $geolocation = est_get_geolocation($_POST);
         if (!empty($geolocation)) {
             $_POST['_est_lat'] = $geolocation['lat'];
             $_POST['_est_lng'] = $geolocation['lng'];
             $_POST['_est_geocode'] = $geolocation['lat'] . ',' . $geolocation['lng'];
         }
     }
     if (!empty($_POST['_est_initial_location'])) {
         $geolocation = est_get_geolocation($_POST['_est_initial_location'], false);
         $_POST['_est_initial_location_geocode'] = array($geolocation['lat'], $geolocation['lng']);
     }
     foreach ($_POST as $key => $value) {
         if (substr_count($key, '_' . THEMEPREFIX . '_')) {
             if (!is_array($value)) {
                 $value = stripslashes($value);
                 if (is_serialized($value)) {
                     $value = unserialize($value);
                 }
                 if (!is_array($value)) {
                     $value = $value;
                 }
             }
             if (is_array($value) and count($value) == 1 and current($value) == 'none') {
                 delete_post_meta($post_id, $key);
             } else {
                 if (is_array($value)) {
                     $nonekey = array_search('none', $value);
                     if ($nonekey !== false) {
                         unset($value[$nonekey]);
                     }
                 }
                 if ($key == '_est_property_custom') {
                     if (is_array($value)) {
                         $details = array();
                         foreach ($value as $custom) {
                             $custom_key = bsh_make_custom_key($custom['name']);
                             $custom_value = $custom['value'];
                             update_post_meta($post_id, $custom_key, $custom_value);
                             $details[] = $custom['name'];
                         }
                         update_post_meta($post_id, '_' . THEMEPREFIX . '_property_custom', $details);
                     }
                 } else {
                     if (substr_count($key, '_est_meta') and is_array($value)) {
                         delete_post_meta($post_id, $key);
                         foreach ($value as $item) {
                             add_post_meta($post_id, $key, $item);
                         }
                     } else {
                         update_post_meta($post_id, $key, $value);
                     }
                 }
             }
         }
     }
     delete_post_meta($post_id, '_est_agent');
     if (!empty($_POST['_est_agent'])) {
         array_filter($_POST['_est_agent']);
     }
     if (!empty($_POST['_est_agent'])) {
         foreach ($_POST['_est_agent'] as $agent_id) {
             if (!empty($agent_id)) {
                 add_post_meta($post_id, '_est_agent', $agent_id);
             }
         }
     } else {
         add_post_meta($post_id, '_est_agent', $_POST['post_author']);
     }
     if (empty($_POST['_est_single_field_address'])) {
         delete_post_meta($post_id, '_est_single_field_address');
     }
 }
Exemplo n.º 3
0
function get_all_custom_details()
{
    global $wpdb;
    $detail_list = array();
    $details = $wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_est_property_custom' ");
    foreach ($details as $key => $value) {
        $post_detail = unserialize($value);
        $detail_list = array_merge($detail_list, $post_detail);
    }
    $detail_list = array_unique($detail_list);
    $customdata = get_option('est_customdata');
    $details = array();
    foreach ($detail_list as $detail) {
        $key = bsh_make_custom_key($detail);
        if (!in_array($key, array_keys($customdata))) {
            $details[$detail] = $key;
        }
    }
    return $details;
}