Function Reference: geodir_update_location_translate
Summary
Update location with translated string.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
Package
GeoDirectory_Location_Manager
Parameters
- ($country_slug) (required)
- Default: None
Return Values
- (bool)
Change Log
Since: 1.0.0
Actions
‘geodir_action_update_location_translate’ [Line: 2622]
Filters
‘geodir_filter_update_location_translate’ [Line: 2620]
Source File
geodir_update_location_translate() is located in geodir_location_manager/geodir_location_functions.php [Line: 2603]
Source Code
function geodir_update_location_translate( $country_slug ) {
global $wpdb, $plugin_prefix;
if( $country_slug == '' ) {
return false;
}
$country = get_post_country_by_slug( $country_slug );
if( $country == '' ) {
return false;
}
$geodir_posttypes = geodir_get_posttypes();
$country_translated = __( $country, GEODIRECTORY_TEXTDOMAIN );
$country_translated = trim( wp_unslash( $country_translated ) );
$country_slug_translated = sanitize_title( $country_translated );
$country_slug = apply_filters( 'geodir_filter_update_location_translate', $country_slug, $country, $country_translated, $country_slug_translated );
do_action( 'geodir_action_update_location_translate', $country_slug, $country, $country_translated, $country_slug_translated );
if( $country_slug == $country_slug_translated ) {
return false;
}
$sql = $wpdb->prepare( "SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE country_slug=%s", array( $country_slug ) );
$location_ids = $wpdb->get_col( $sql );
/* update in post locations table */
$update_locations = false;
//$sql = $wpdb->prepare( "UPDATE " . POST_LOCATION_TABLE . " SET country=%s, country_slug=%s WHERE country_slug=%s", array( $country_translated, $country_slug_translated, $country_slug ) );
$sql = $wpdb->prepare( "UPDATE " . POST_LOCATION_TABLE . " SET country_slug=%s WHERE country_slug=%s", array( $country_slug_translated, $country_slug ) );
$update_locations = $wpdb->query($sql);
/* update in post listings table */
$update_listings = false;
if( !empty( $location_ids ) ) {
$location_ids = implode( ",", $location_ids );
foreach( $geodir_posttypes as $geodir_posttype ) {
$table = $plugin_prefix . $geodir_posttype . '_detail';
$sql = "SELECT post_id, post_locations, post_location_id FROM " . $table . " WHERE post_location_id IN(" . $location_ids . ")";
$listings = $wpdb->get_results( $sql );
if( !empty( $listings ) ) {
foreach( $listings as $listing ) {
$post_id = $listing->post_id;
$location_id = $listing->post_location_id;
$post_locations = $listing->post_locations;
if( $post_locations != '' ) {
$post_locations_arr = explode( ",", $post_locations );
if( isset( $post_locations_arr[2] ) && trim($post_locations_arr[2]) != '[]' ) {
$post_locations_arr[2] = '[' . $country_slug_translated . ']';
$post_locations = implode( ",", $post_locations_arr );
} else {
$post_locations = '';
}
}
if( $post_locations == '' ) {
$location_info = geodir_get_location_by_id( '', $location_id );
if( !empty( $location_info ) && isset( $location_info->location_id ) ) {
$post_locations = '['. $location_info->city_slug .'],['. $location_info->region_slug .'],['. $country_slug_translated .']';
}
}
$sql = $wpdb->prepare( "UPDATE " . $table . " SET post_locations=%s, post_country=%s WHERE post_id=%d", array( $post_locations, $country_translated, $post_id ) );
$update_locations = $wpdb->query($sql);
}
}
}
$update_locations = true;
}
/* update in location seo table */
$update_location_seo = false;
$sql = $wpdb->prepare( "UPDATE " . LOCATION_SEO_TABLE . " SET country_slug=%s WHERE country_slug=%s", array( $country_slug_translated, $country_slug ) );
$update_location_seo = $wpdb->query($sql);
if( $update_locations || $update_listings || $update_location_seo ) {
return true;
}
return false;
}