Function Reference: geodir_update_options
Summary
Update options
Description
Updates the options on the geodirectory settings pages. Returns true if saved.
Package
GeoDirectory
Parameters
- $options
- (array) (required) The option array.
- Default: None
- $dummy
- (bool) (required) Is this dummy settings? Default: false.
- Default: None
Return Values
- (bool)
- Returns true if saved.
Change Log
Since: 1.0.0
Source File
geodir_update_options() is located in geodirectory-admin/admin_functions.php [Line: 457]
Source Code
function geodir_update_options($options, $dummy = false) { if ((!isset($_POST) || !$_POST) && !$dummy) return false; foreach ($options as $value) { if ($dummy && isset($value['std'])) $_POST[$value['id']] = $value['std']; if (isset($value['type']) && $value['type'] == 'checkbox') : if (isset($value['id']) && isset($_POST[$value['id']])) { update_option($value['id'], $_POST[$value['id']]); } else { update_option($value['id'], 0); } elseif (isset($value['type']) && $value['type'] == 'image_width') : if (isset($value['id']) && isset($_POST[$value['id'] . '_width'])) { update_option($value['id'] . '_width', $_POST[$value['id'] . '_width']); update_option($value['id'] . '_height', $_POST[$value['id'] . '_height']); if (isset($_POST[$value['id'] . '_crop'])) : update_option($value['id'] . '_crop', 1); else : update_option($value['id'] . '_crop', 0); endif; } else { update_option($value['id'] . '_width', $value['std']); update_option($value['id'] . '_height', $value['std']); update_option($value['id'] . '_crop', 1); } elseif (isset($value['type']) && $value['type'] == 'map') : $post_types = array(); $categories = array(); if (!empty($_POST['home_map_post_types'])) : foreach ($_POST['home_map_post_types'] as $post_type) : $post_types[] = $post_type; endforeach; endif; update_option('geodir_exclude_post_type_on_map', $post_types); if (!empty($_POST['post_category'])) : foreach ($_POST['post_category'] as $texonomy => $cat_arr) : $categories[$texonomy] = array(); foreach ($cat_arr as $category) : $categories[$texonomy][] = $category; endforeach; $categories[$texonomy] = !empty($categories[$texonomy]) ? array_unique($categories[$texonomy]) : array(); endforeach; endif; update_option('geodir_exclude_cat_on_map', $categories); update_option('geodir_exclude_cat_on_map_upgrade', 1); elseif (isset($value['type']) && $value['type'] == 'map_default_settings') : if (!empty($_POST['geodir_default_map_language'])): update_option('geodir_default_map_language', $_POST['geodir_default_map_language']); endif; if (!empty($_POST['geodir_default_map_search_pt'])): update_option('geodir_default_map_search_pt', $_POST['geodir_default_map_search_pt']); endif; elseif (isset($value['type']) && $value['type'] == 'file') : if (isset($_POST[$value['id'] . '_remove']) && $_POST[$value['id'] . '_remove']) {// if remove is set then remove the file if (get_option($value['id'])) { $image_name_arr = explode('/', get_option($value['id'])); $noimg_name = end($image_name_arr); $img_path = $uploads['path'] . '/' . $noimg_name; if (file_exists($img_path)) unlink($img_path); } update_option($value['id'], ''); } $uploadedfile = isset($_FILES[$value['id']]) ? $_FILES[$value['id']] : ''; $filename = isset($_FILES[$value['id']]['name']) ? $_FILES[$value['id']]['name'] : ''; if (!empty($filename)): $ext = pathinfo($filename, PATHINFO_EXTENSION); $uplaods = array(); foreach ($uploadedfile as $key => $uplaod): if ($key == 'name'): $uplaods[$key] = $filename; else : $uplaods[$key] = $uplaod; endif; endforeach; $uploads = wp_upload_dir(); if (get_option($value['id'])) { $image_name_arr = explode('/', get_option($value['id'])); $noimg_name = end($image_name_arr); $img_path = $uploads['path'] . '/' . $noimg_name; if (file_exists($img_path)) unlink($img_path); } $upload_overrides = array('test_form' => false); $movefile = wp_handle_upload($uplaods, $upload_overrides); update_option($value['id'], $movefile['url']); endif; if (!get_option($value['id']) && isset($value['value'])): update_option($value['id'], $value['value']); endif; else : // same menu setting per theme. if (isset($value['id']) && $value['id'] == 'geodir_theme_location_nav' && isset($_POST[$value['id']])) { $theme = wp_get_theme(); update_option('geodir_theme_location_nav_' . $theme->name, $_POST[$value['id']]); } if (isset($value['id']) && isset($_POST[$value['id']])) { update_option($value['id'], $_POST[$value['id']]); } else { delete_option($value['id']); } endif; } if ($dummy) $_POST = array(); return true; }