Function Reference: geodir_get_location_seo_settings
Summary
Handles location SEO settings form data.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Package
GeoDirectory_Location_Manager
Change Log
Since: 1.0.0
Source File
geodir_get_location_seo_settings() is located in geodir_location_manager/geodir_location_functions.php [Line: 668]
Source Code
function geodir_get_location_seo_settings()
{
global $wpdb;
if(isset($_REQUEST['wpnonce']) && current_user_can( 'manage_options' ) && isset($_REQUEST['location_slug'])) {
if ( !wp_verify_nonce( $_REQUEST['wpnonce'], 'geodir_set_location_seo'.$_REQUEST['location_slug'] ) ) {
echo 'FAIL';
exit;
}
$field = isset($_REQUEST['field']) && ($_REQUEST['field']=='geodir_meta_keyword' || $_REQUEST['field']=='geodir_meta_description') ? $_REQUEST['field'] : '';
$seo_value = isset($_REQUEST['field_val']) ? trim($_REQUEST['field_val']) : '';
if ($field=='' || $seo_value=='') {
echo 'FAIL';
exit;
}
$seo_field = $_REQUEST['field']=='geodir_meta_keyword' ? 'seo_title' : 'seo_desc';
$location_type = isset($_REQUEST['location_type']) ? $_REQUEST['location_type'] : '';
$country_slug = isset($_REQUEST['country_slug']) ? $_REQUEST['country_slug'] : '';
$region_slug = isset($_REQUEST['region_slug']) ? $_REQUEST['region_slug'] : '';
$location_slug = isset($_REQUEST['location_slug']) ? $_REQUEST['location_slug'] : '';
if ($seo_field=='seo_title') {
$seo_value = substr($seo_value, 0, 140);
} else {
$seo_value = substr($seo_value, 0, 100000);
}
$seo_info = geodir_location_seo_by_slug($location_slug, $location_type, $country_slug, $region_slug);
$date_now = date('Y-m-d H:i:s');
switch($location_type) {
case 'country': {
if (!empty($seo_info)) {
$sql = $wpdb->prepare("UPDATE ".LOCATION_SEO_TABLE." SET ".$seo_field."=%s, date_updated=%s WHERE seo_id=%d", array($seo_value, $date_now, $seo_info->seo_id));
} else {
$sql = $wpdb->prepare("INSERT INTO ".LOCATION_SEO_TABLE." SET location_type=%s, country_slug=%s, ".$seo_field."=%s, date_created=%s", array($location_type, $location_slug, $seo_value, $date_now));
}
if ($wpdb->query($sql)) {
echo 'OK';
exit;
}
}
break;
case 'region': {
if (!empty($seo_info)) {
$sql = $wpdb->prepare("UPDATE ".LOCATION_SEO_TABLE." SET country_slug=%s, ".$seo_field."=%s, date_updated=%s WHERE seo_id=%d", array($country_slug, $seo_value, $date_now, $seo_info->seo_id));
} else {
$sql = $wpdb->prepare("INSERT INTO ".LOCATION_SEO_TABLE." SET location_type=%s, country_slug=%s, region_slug=%s, ".$seo_field."=%s, date_created=%s", array($location_type, $country_slug, $location_slug, $seo_value, $date_now));
}
if ($wpdb->query($sql)) {
echo 'OK';
exit;
}
}
break;
case 'city': {
if (!empty($seo_info)) {
$sql = $wpdb->prepare("UPDATE ".LOCATION_SEO_TABLE." SET country_slug=%s, region_slug=%s, ".$seo_field."=%s, date_updated=%s WHERE seo_id=%d", array($country_slug, $region_slug, $seo_value, $date_now, $seo_info->seo_id));
} else {
$sql = $wpdb->prepare("INSERT INTO ".LOCATION_SEO_TABLE." SET location_type=%s, country_slug=%s, region_slug=%s, city_slug=%s, ".$seo_field."=%s, date_created=%s", array($location_type, $country_slug, $region_slug, $location_slug, $seo_value, $date_now));
}
if ($wpdb->query($sql)) {
$info = geodir_city_info_by_slug($location_slug, $country_slug, $region_slug);
if (!empty($info)) {
$location_field = $seo_field=='seo_title' ? 'city_meta' : 'city_desc';
$sql = $wpdb->prepare("UPDATE ".POST_LOCATION_TABLE." SET ".$location_field."=%s WHERE location_id=%d", array($seo_value, $info->location_id));
$wpdb->query($sql);
}
echo 'OK';
exit;
}
}
break;
}
}
$msg = urlencode( __('Location SEO updated successfully.',GEODIRLOCATION_TEXTDOMAIN) );
$location = admin_url()."admin.php?page=geodirectory&tab=managelocation_fields&subtab=geodir_location_seo&location_success=".$msg;
wp_redirect($location);
exit;
}