Function Reference: geodir_location_activation_script
Summary
Function to install all location manager related data and options.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
Package
GeoDirectory_Location_Manager
Change Log
Since: 1.0.0
Source File
geodir_location_activation_script() is located in geodir_location_manager/geodir_location_hooks_actions.php [Line: 62]
Source Code
function geodir_location_activation_script() { global $wpdb,$plugin_prefix; /** * Include any functions needed for upgrades. * * @since 1.3.6 */ require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $is_set_default_location = geodir_get_default_location(); $wpdb->hide_errors(); // rename tables if we need to if($wpdb->query("SHOW TABLES LIKE 'geodir_post_locations'")>0){$wpdb->query("RENAME TABLE geodir_post_locations TO ".$wpdb->prefix."geodir_post_locations");} if($wpdb->query("SHOW TABLES LIKE 'geodir_post_neighbourhood'")>0){$wpdb->query("RENAME TABLE geodir_post_neighbourhood TO ".$wpdb->prefix."geodir_post_neighbourhood");} if($wpdb->query("SHOW TABLES LIKE 'geodir_countries'")>0){$wpdb->query("RENAME TABLE geodir_countries TO ".$wpdb->prefix."geodir_countries");} if($wpdb->query("SHOW TABLES LIKE 'geodir_location_seo'")>0){$wpdb->query("RENAME TABLE geodir_location_seo TO ".$wpdb->prefix."geodir_location_seo");} $collate = ''; if($wpdb->has_cap( 'collation' )) { if(!empty($wpdb->charset)) $collate = "DEFAULT CHARACTER SET $wpdb->charset"; if(!empty($wpdb->collate)) $collate .= " COLLATE $wpdb->collate"; } if($wpdb->get_var("SHOW TABLES LIKE '".POST_LOCATION_TABLE."'") != POST_LOCATION_TABLE) { $location_table = "CREATE TABLE IF NOT EXISTS ".POST_LOCATION_TABLE." ( `location_id` int(11) NOT NULL AUTO_INCREMENT, `country` varchar(254) NOT NULL, `region` varchar(254) NOT NULL, `city` varchar(254) NOT NULL, `country_slug` varchar(254) NOT NULL, `region_slug` varchar(254) NOT NULL, `city_slug` varchar(254) NOT NULL, `city_latitude` varchar(254) NOT NULL, `city_longitude` varchar(254) NOT NULL, `is_default` ENUM( '0', '1' ) NOT NULL DEFAULT '0', `city_meta` VARCHAR( 254 ) NOT NULL, `city_desc` TEXT NOT NULL, PRIMARY KEY (`location_id`)) $collate "; if ( $wpdb->query( "SHOW TABLES LIKE 'geodir_post_locations'" ) > 0 ) { $wpdb->query( "RENAME TABLE geodir_post_locations TO " . $wpdb->prefix . "geodir_post_locations" ); } else { dbDelta( $location_table ); } } $location_result = (array)geodir_get_default_location(); // this function is there in core plugin location_functions.php file. $post_types = geodir_get_posttypes(); // Fuction in core geodirectory plugin $location_info = geodir_add_new_location_via_adon($location_result); geodir_location_set_default($location_info->location_id); if(!empty($post_types)){ foreach($post_types as $post_type){ $table = $plugin_prefix.$post_type.'_detail'; $wpdb->query( $wpdb->prepare( "UPDATE ".$table." SET post_location_id=%d WHERE post_location_id=0", array($location_info->location_id) ) ); } } if($wpdb->get_var("SHOW TABLES LIKE '".POST_NEIGHBOURHOOD_TABLE."'") != POST_NEIGHBOURHOOD_TABLE) { $neighbourhood_table = "CREATE TABLE IF NOT EXISTS ".POST_NEIGHBOURHOOD_TABLE." ( `hood_id` int(11) NOT NULL AUTO_INCREMENT, `hood_location_id` int(11) NOT NULL, `hood_name` varchar(254) NOT NULL, `hood_latitude` varchar(254) NOT NULL, `hood_longitude` varchar(254) NOT NULL, `hood_slug` varchar(254) NOT NULL, PRIMARY KEY (`hood_id`)) $collate "; if ( $wpdb->query( "SHOW TABLES LIKE 'geodir_post_neighbourhood'" ) > 0 ) { $wpdb->query( "RENAME TABLE geodir_post_neighbourhood TO " . $wpdb->prefix . "geodir_post_neighbourhood" ); } else { dbDelta( $neighbourhood_table ); } } $address_extra_info = $wpdb->get_results("select id, extra_fields from ".GEODIR_CUSTOM_FIELDS_TABLE." where field_type = 'address'"); if(!empty($address_extra_info)){ foreach($address_extra_info as $extra){ $fields = array(); if($extra->extra_fields != ''){ $fields = unserialize($extra->extra_fields); if(!isset($fields['show_city'])){ $fields['show_city'] = 1;} if(!isset($fields['city_lable'])){ $fields['city_lable'] = __('City', GEODIRLOCATION_TEXTDOMAIN);} if(!isset($fields['show_region'])){ $fields['show_region'] = 1;} if(!isset($fields['region_lable'])){ $fields['region_lable'] = __('Region', GEODIRLOCATION_TEXTDOMAIN);} if(!isset($fields['show_country'])){ $fields['show_country'] = 1;} if(!isset($fields['country_lable'])){ $fields['country_lable'] = __('Country', GEODIRLOCATION_TEXTDOMAIN);} $wpdb->query( $wpdb->prepare( "UPDATE ".GEODIR_CUSTOM_FIELDS_TABLE." SET extra_fields=%s WHERE id=%d", array(serialize($fields),$extra->id) ) ); } } } //$post_types = geodir_get_posttypes(); if(!empty($post_types)){ foreach($post_types as $post_type){ $detail_table = $plugin_prefix.$post_type.'_detail'; $meta_field_add = "VARCHAR( 30 ) NULL"; geodir_add_column_if_not_exist( $detail_table, "post_neighbourhood", $meta_field_add ); } } // location seo table if($wpdb->get_var("SHOW TABLES LIKE '".LOCATION_SEO_TABLE."'") != LOCATION_SEO_TABLE) { $location_table = "CREATE TABLE IF NOT EXISTS ".LOCATION_SEO_TABLE." ( `seo_id` int(11) NOT NULL AUTO_INCREMENT, `location_type` varchar(255) NOT NULL, `country_slug` varchar(254) NOT NULL, `region_slug` varchar(254) NOT NULL, `city_slug` varchar(254) NOT NULL, `seo_title` varchar(254) NOT NULL, `seo_desc` text NOT NULL, `date_created` datetime NOT NULL, `date_updated` datetime NOT NULL, PRIMARY KEY (`seo_id`) ) $collate "; if ( $wpdb->query( "SHOW TABLES LIKE 'geodir_location_seo'" ) > 0 ) { $wpdb->query( "RENAME TABLE geodir_location_seo TO " . $wpdb->prefix . "geodir_location_seo" ); } else { dbDelta( $location_table ); } } // location term count table if($wpdb->get_var("SHOW TABLES LIKE '".GEODIR_TERM_META."'") != GEODIR_TERM_META) { $term_meta_table = "CREATE TABLE IF NOT EXISTS ".GEODIR_TERM_META." ( id int NOT NULL AUTO_INCREMENT, location_type varchar( 100 ) NULL DEFAULT NULL, location_name varchar( 100 ) NULL DEFAULT NULL, term_count varchar( 5000 ) NULL DEFAULT NULL, review_count varchar( 5000 ) NULL DEFAULT NULL, PRIMARY KEY (id) ) $collate "; dbDelta( $term_meta_table ); } }