/** * AJAX geocode */ public static function ajaxGeocode() { // ID $post_id = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT); // Latitude $latitude = filter_input(INPUT_POST, Pronamic_Google_Maps_Post::META_KEY_LATITUDE, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); update_post_meta($post_id, Pronamic_Google_Maps_Post::META_KEY_LATITUDE, $latitude); // Longitude $longitude = filter_input(INPUT_POST, Pronamic_Google_Maps_Post::META_KEY_LONGITUDE, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); update_post_meta($post_id, Pronamic_Google_Maps_Post::META_KEY_LONGITUDE, $longitude); // Status $status = filter_input(INPUT_POST, Pronamic_Google_Maps_Post::META_KEY_GEOCODE_STATUS, FILTER_SANITIZE_STRING); update_post_meta($post_id, Pronamic_Google_Maps_Post::META_KEY_GEOCODE_STATUS, $status); // Result $result = new stdClass(); $result->success = true; // Next post $query = new WP_Query(); $query->query(Pronamic_Google_Maps_Admin::getGeocodeQueryArgs()); $result->foundPosts = $query->found_posts; while ($query->have_posts()) { $query->the_post(); $pgm = pronamic_get_google_maps_meta(); $result->nextPost = new stdClass(); $result->nextPost->ID = get_the_ID(); $result->nextPost->title = get_the_title(); $result->nextPost->address = $pgm->address; $result->nextPost->latitude = $pgm->latitude; $result->nextPost->longitude = $pgm->longitude; } $response = json_encode($result); header('Content-Type: application/json'); exit($response); /* Queries to empty latitude, longitude and geocode status meta UPDATE wp_postmeta SET meta_value = '' WHERE meta_key IN ('_pronamic_google_maps_latitude', '_pronamic_google_maps_longitude'); UPDATE wp_postmeta SET meta_value = '' WHERE meta_key = '_pronamic_google_maps_geocode_status'; */ }
<?php $pgm = pronamic_get_google_maps_meta(); wp_nonce_field('save-post', Pronamic_Google_Maps_Maps::NONCE_NAME); ?> <div id="pgm"> <input id="pgm-map-type-field" name="<?php echo Pronamic_Google_Maps_Post::META_KEY_MAP_TYPE; ?> " value="<?php echo esc_attr($pgm->mapType); ?> " type="hidden" /> <input id="pgm-zoom-field" name="<?php echo Pronamic_Google_Maps_Post::META_KEY_ZOOM; ?> " value="<?php echo esc_attr($pgm->zoom); ?> " type="hidden" /> <table class="form-table"> <tr> <th scope="row"> <label for="pgm-active-field"><?php _e('Active', 'pronamic_google_maps'); ?> </label> </th> <td> <input id="pgm-active-field" name="<?php