Advertisement
elforesto

WordPress: Add Geo My WP to Postie

Jun 20th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <?php
  2. /**********************************************************
  3.  * This function extends Geo My WP to work with posts     *
  4.  * submitted via the Postie plugin. Those posts bypass    *
  5.  * the addition of the needed DB entries for geolocation  *
  6.  * searches. This adds them back in.                      *
  7.  *                                                        *
  8.  * REQUIREMENTS:                                          *
  9.  * - Geo My WP 2.0 Beta 5+                                *
  10.  * - Postie 1.5.14+                                       *
  11.  **********************************************************/
  12.  
  13. // Make sure we have the needed plugin.
  14. // if(!function_exists('gmw_pt_update_location'))
  15.  
  16. function add_post_location($post) {
  17.     DebugEcho("Adding post location...");
  18.  
  19.     DebugEcho("Loading GMW functions...");
  20.     include_once("plugins/geo-my-wp/functions.php");
  21.     DebugEcho("GMW functions loaded!");
  22.  
  23.  
  24.     // Initialize variables.
  25.     $id = $post['ID'];
  26.     DebugEcho("Updating Post ID " . $id);
  27.  
  28.     $author_id = $post['post_author'];
  29.     DebugEcho("Post author ID: " . $author_id);
  30.  
  31.     // Assumes an xprofile field of Street Address
  32.     $street_address = xprofile_get_field_data("Street Address", $author_id);
  33.     DebugEcho("Street Address: " . $street_address);
  34.  
  35.     // Assumes an xprofile field of City
  36.     $city = xprofile_get_field_data("City", $author_id);
  37.     DebugEcho("City: " . $city);
  38.  
  39.     // Assumes an xprofile field of State
  40.     $state = xprofile_get_field_data("State", $author_id);
  41.     DebugEcho("State: " . $state);
  42.  
  43.     // Assumes an xprofile field of Zip Code
  44.     $zipcode = xprofile_get_field_data("ZIP Code", $author_id);
  45.     DebugEcho("ZIP Code: " . $zipcode);
  46.  
  47.     $email = $post['email_author'];
  48.     DebugEcho("Author email address: " . $email);
  49.  
  50.     // Set the phone number. In this case, we want only the set phone numbers.
  51.     $home_phone = xprofile_get_field_data("Home Phone", $author_id);
  52.     $cell_phone = xprofile_get_field_data("Cell Phone", $author_id);
  53.     $phone = '';
  54.  
  55.     if($home_phone != '' && $cell_phone == '')
  56.         $phone = $home_phone;
  57.     if($home_phone == '' && $cell_phone != '')
  58.         $phone = $cell_phone;
  59.     if($home_phone != '' && $cell_phone != '')
  60.         $phone = $home_phone + " / " + $cell_phone;
  61.     DebugEcho("Phone: " . $phone);
  62.  
  63.     // Build an array for the update function.
  64.     $options = array($id, 'post', 'published', $street_address, false, $city, $state, $zipcode, false, $phone, false, $email, false);
  65.  
  66.     DebugEcho("Running post update function...");
  67.  
  68.     // Run the update function.
  69.     gmw_pt_update_location($options);
  70.     DebugEcho("Done adding post location!");
  71.    
  72.     // As per Postie requirements, always return the $post object, even if it didn't change.
  73.     return $post;
  74. }
  75.  
  76. add_filter("postie_post_after", "add_post_location");
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement