function save_data($post_id) { global $wpdb, $post; // Return if it's a post revision if (false !== wp_is_post_revision($post_id)) { return; } if (!isset($this->settings['post_types_settings']['post_types']) || empty($this->settings['post_types_settings']['post_types']) || !isset($_POST['post_type']) || !in_array($_POST['post_type'], $this->settings['post_types_settings']['post_types'])) { return; } // verify nonce // if (!isset($_POST['this->meta_boxes_nonce']) || !wp_verify_nonce($_POST['this->meta_boxes_nonce'], basename(__FILE__))) { return; } // check autosave // if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (!current_user_can('edit_post', $post_id)) { return; } // Check permissions // /* if ( isset( $_POST['post_type'] ) && in_array( $_POST['post_type'], $wppl_options['address_fields'] ) ) { if ( !current_user_can('edit_page', $post->ID) ) { return; } } else { if ( !current_user_can('edit_post', $post->ID) ) { return; } } */ foreach ($this->meta_boxes['fields'] as $field) { if ($field['id'] == '_wppl_days_hours') { if (isset($_POST[$field['id']])) { $old = get_post_meta($post->ID, $field['id'], true); $new = $_POST[$field['id']]; if ($new && $new != $old) { update_post_meta($post->ID, $field['id'], $new); } elseif ('' == $new && $old) { delete_post_meta($post->ID, $field['id'], $old); } } } } //do_action( 'gmw_pt_admin_update_location_post_meta', $post->ID, $_POST, $wppl_options ); //delete locaiton if there are no address or lat/long if (!isset($_POST['_wppl_formatted_address']) || empty($_POST['_wppl_formatted_address']) || !isset($_POST['_wppl_lat']) || empty($_POST['_wppl_lat'])) { $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "places_locator WHERE post_id=%d", $post->ID)); } else { $_POST['gmw_map_icon'] = isset($_POST['gmw_map_icon']) && !empty($_POST['gmw_map_icon']) ? $_POST['gmw_map_icon'] : '_default.png'; $_POST = apply_filters('gmw_pt_before_location_updated', $_POST, $post->ID); //location array $location = array('post_id' => $post->ID, 'feature' => 0, 'post_type' => $_POST['post_type'], 'post_title' => $_POST['post_title'], 'post_status' => $_POST['post_status'], 'street_number' => $_POST['_wppl_street_number'], 'street_name' => $_POST['_wppl_street_name'], 'street' => $_POST['_wppl_street'], 'apt' => $_POST['_wppl_apt'], 'city' => $_POST['_wppl_city'], 'state' => $_POST['_wppl_state'], 'state_long' => $_POST['_wppl_state_long'], 'zipcode' => $_POST['_wppl_zipcode'], 'country' => $_POST['_wppl_country'], 'country_long' => $_POST['_wppl_country_long'], 'address' => $_POST['_wppl_address'], 'formatted_address' => $_POST['_wppl_formatted_address'], 'phone' => $_POST['_wppl_phone'], 'fax' => $_POST['_wppl_fax'], 'email' => $_POST['_wppl_email'], 'website' => $_POST['_wppl_website'], 'lat' => $_POST['_wppl_lat'], 'long' => $_POST['_wppl_long'], 'map_icon' => $_POST['gmw_map_icon']); //update locaiton in database gmw_replace_pt_location_in_db($location); } do_action('gmw_pt_after_location_updated', $post->ID, $_POST); }
/** * Import data from WordPress Store Locator plugin * * @since 2.5 * @return void */ function gmw_store_locator_import() { //look for nonce if (empty($_POST['gmw_store_locator_import_nonce'])) { return; } //varify nonce if (!wp_verify_nonce($_POST['gmw_store_locator_import_nonce'], 'gmw_store_locator_import_nonce')) { return; } global $wpdb; //look for places_locator table $slTable = $wpdb->get_results("SHOW TABLES LIKE '{$wpdb->prefix}store_locator'", ARRAY_A); //abort if no table exist if (count($slTable) == 0) { wp_safe_redirect(admin_url('admin.php?page=gmw-tools&tab=import_export&gmw_notice=store_locator_import_failed_no_table&gmw_notice_status=error')); exit; } //array of states $state_list = array('AL' => "Alabama", 'AK' => "Alaska", 'AZ' => "Arizona", 'AR' => "Arkansas", 'CA' => "California", 'CO' => "Colorado", 'CT' => "Connecticut", 'DE' => "Delaware", 'DC' => "District Of Columbia", 'FL' => "Florida", 'GA' => "Georgia", 'HI' => "Hawaii", 'ID' => "Idaho", 'IL' => "Illinois", 'IN' => "Indiana", 'IA' => "Iowa", 'KS' => "Kansas", 'KY' => "Kentucky", 'LA' => "Louisiana", 'ME' => "Maine", 'MD' => "Maryland", 'MA' => "Massachusetts", 'MI' => "Michigan", 'MN' => "Minnesota", 'MS' => "Mississippi", 'MO' => "Missouri", 'MT' => "Montana", 'NE' => "Nebraska", 'NV' => "Nevada", 'NH' => "New Hampshire", 'NJ' => "New Jersey", 'NM' => "New Mexico", 'NY' => "New York", 'NC' => "North Carolina", 'ND' => "North Dakota", 'OH' => "Ohio", 'OK' => "Oklahoma", 'OR' => "Oregon", 'PA' => "Pennsylvania", 'RI' => "Rhode Island", 'SC' => "South Carolina", 'SD' => "South Dakota", 'TN' => "Tennessee", 'TX' => "Texas", 'UT' => "Utah", 'VT' => "Vermont", 'VA' => "Virginia", 'WA' => "Washington", 'WV' => "West Virginia", 'WI' => "Wisconsin", 'WY' => "Wyoming"); $post_type = isset($_POST['post_type']) ? $_POST['post_type'] : 'post'; //get location from store locator table in database $locations = $wpdb->get_results("\n\t\t\tSELECT\n\t\t\t`sl_store` as `post_title`,\n\t\t\t`sl_address` as `street`,\n\t\t\t`sl_address2` as `street2`,\n\t\t\t`sl_city` as `city`,\n\t\t\t`sl_state` as `state`,\n\t\t\t`sl_zip` as `zipcode`,\n\t\t\t`sl_country` as `country`,\n\t\t\t`sl_latitude` as `lat`,\n\t\t\t`sl_longitude` as `long`,\n\t\t\t`sl_phone` as `phone`,\n\t\t\t`sl_fax` as `fax`,\n\t\t\t`sl_email` as `email`,\n\t\t\t`sl_url` as `website`,\n\t\t\t`sl_tags` as `tags`,\n\t\t\t`sl_description` as `content`\n\t\t\tFROM {$wpdb->prefix}store_locator", ARRAY_A); foreach ($locations as $location) { // Create post object $new_post = apply_filters('gmw_store_locator_import_new_post_args', array('post_title' => $location['post_title'], 'post_content' => $location['content'], 'post_type' => $post_type, 'post_status' => 'publish', 'post_author' => 1)); //create new post $postID = wp_insert_post($new_post); $address = array(); //build complete adress field from address components foreach ($location as $key => $value) { if (in_array($key, array('street', 'street2', 'city', 'state', 'zipcode', 'country')) && isset($value) && $value != '' && $value != ' ') { $address[] = $value; } } $state = strtoupper($location['state']); $location['post_id'] = $postID; $location['post_status'] = 'publish'; $location['post_type'] = $post_type; $location['state_long'] = isset($state_list[$state]) && array_key_exists($state, $state_list) ? $state_list[$state] : ''; $location['country_long'] = ''; $location['address'] = implode(' ', $address); $location['formatted_address'] = $location['address']; $location['feature'] = 0; $location['apt'] = ''; $location['map_icon'] = 'deafult.png'; //update GEO my WP table in database gmw_replace_pt_location_in_db($location); } wp_safe_redirect(admin_url('admin.php?page=gmw-tools&tab=import_export&gmw_notice=store_locator_imported&gmw_notice_status=updated')); exit; }