Function Reference: geodir_add_new_location
Summary
Adds new location using location info.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Package
GeoDirectory
Parameters
- $location_info
- (array) (required) {
Array of location info arguments. @type string $city The city string. @type string $region The region string. @type string $country The country string. @type string $geo_lat The latitude string. @type string $geo_lng The longitude string. @type string|bool $is_default Is this the default location?. }.- Default: None
Return Values
- (string|bool)
- Location ID on success.
- False when Fail.
Change Log
Since: 1.0.0
1.6.16 Fix country translation.
Source File
geodir_add_new_location() is located in geodirectory-functions/location_functions.php [Line: 216]
Source Code
function geodir_add_new_location($location_info = array()) { global $wpdb; if (!empty($location_info)) { $location_city = ($location_info['city'] != '') ? $location_info['city'] : 'all'; $location_region = ($location_info['region'] != '') ? $location_info['region'] : 'all'; $location_country = ($location_info['country'] != '') ? geodir_get_normal_country($location_info['country']) : 'all'; $location_lat = ($location_info['geo_lat'] != '') ? $location_info['geo_lat'] : ''; $location_lng = ($location_info['geo_lng'] != '') ? $location_info['geo_lng'] : ''; $is_default = isset($location_info['is_default']) ? $location_info['is_default'] : ''; $country_slug = create_location_slug(__($location_country, 'geodirectory')); $region_slug = create_location_slug($location_region); $city_slug = create_location_slug($location_city); /** * Filter add new location data. * * @since 1.0.0 */ $geodir_location = (object)apply_filters('geodir_add_new_location', array('location_id' => 0, 'country' => $location_country, 'region' => $location_region, 'city' => $location_city, 'country_slug' => $country_slug, 'region_slug' => $region_slug, 'city_slug' => $city_slug, 'city_latitude' => $location_lat, 'city_longitude' => $location_lng, 'is_default' => $is_default )); /* // Not allowed to create country in DB : 2016-12-09 if ($geodir_location->country) { $get_country = $wpdb->get_var($wpdb->prepare("SELECT Country FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country=%s", array($geodir_location->country))); if (empty($get_country)) { $wpdb->query($wpdb->prepare("INSERT INTO " . GEODIR_COUNTRIES_TABLE . " (Country, Title) VALUES (%s,%s)", array($geodir_location->country, $geodir_location->country))); } } */ if ($geodir_location->is_default) update_option('geodir_default_location', $geodir_location); return $geodir_location->location_id; } else { return false; } }