Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**********************************************************
- * This function extends Geo My WP to work with posts *
- * submitted via the Postie plugin. Those posts bypass *
- * the addition of the needed meta fields for geolocation *
- * searches. This adds them back in. *
- **********************************************************/
- function add_post_location($post) {
- while(!is_plugin_active("geo-my-wp/geo-my-wp.php")) {
- usleep(100);
- }
- // Initialize variables.
- $id = $post->ID;
- $author_id = $post->post_author;
- $street_address = xprofile_get_field_data("Street Address", $author_id); // Assumes an xprofile field of Street Address
- $city = xprofile_get_field_data("City", $author_id); // Assumes an xprofile field of City
- $state = xprofile_get_field_data("State", $author_id); // Assumes an xprofile field of State
- $zipcode = xprofile_get_field_data("ZIP Code", $author_id); // Assumes an xprofile field of Zip Code
- // Build and set the full address to search.
- $address = '';
- if($street_address != '')
- $address .= $street_address + ", "; // Only add the street address if it has been set. It's an optional field in my setup.
- $address .= $city . ", " . $state . " " . $zipcode;
- // Obtain geocoding data from Google via Geo My WP function.
- $coords = gmwConvertToCoords($address);
- // Set the post coordinates.
- add_post_meta($id, "_wppl_lat", $coords['lat']);
- add_post_meta($id, "_wppl_long", $coords['long']);
- // Set the individual fields for street address, city, state, and ZIP code.
- add_post_meta($id, "_wppl_street", $coords['street']);
- add_post_meta($id, "_wppl_city", $coords['city']);
- add_post_meta($id, "_wppl_state", $coords['state_short']);
- add_post_meta($id, "_wppl_state_long", $coords['state_long']);
- add_post_meta($id, "_wppl_zipcode", $coords['zipcode']);
- add_post_meta($id, "_wppl_country", $coords['country_short']);
- add_post_meta($id, "_wppl_country_long", $coords['country_long']);
- // Heck, set the formatted address while we're at it.
- add_post_meta($id, "_wppl_formatted_address", $coords['formatted_address']);
- // Set the map icon to the default.
- add_post_meta($id, "_wppl_map_icon", "_default.png");
- // Add the email address.
- add_post_meta($id, "_wppl_email", xprofile_get_field_data("Email", $author_id));
- // Add the phone numbers. Only uses the ones that have been filled out.
- $home_phone = xprofile_get_field_data("Home Phone", $author_id);
- $cell_phone = xprofile_get_field_data("Cell Phone", $author_id);
- $phone = '';
- if($home_phone != '' && $cell_phone == '')
- $phone = $home_phone;
- if($home_phone == '' && $cell_phone != '')
- $phone = $cell_phone;
- if($home_phone != '' && $cell_phone != '')
- $phone = $home_phone + " / " + $cell_phone;
- add_post_meta($id, "_wppl_phone", $phone);
- return $post;
- }
- add_filter("postie_post", "add_post_location");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement