Changeset 1412
- Timestamp:
- 03/17/2015 11:58:47 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
r1233 r1412 105 105 // WordCamp post type only 106 106 if ( WCPT_POST_TYPE_ID == get_post_type() ) { 107 // If the venue address was changed, update it's coordinates 108 $new_address = $_POST[ wcpt_key_to_str( 'Physical Address', 'wcpt_' ) ]; 109 if ( $new_address != get_post_meta( $post_id, 'Physical Address', true ) ) { 110 if ( $coordinates = $this->geocode_address( $new_address ) ) { 111 update_post_meta( $post_id, '_venue_coordinates', $coordinates ); 112 } else { 113 delete_post_meta( $post_id, '_venue_coordinates' ); 114 } 115 } 116 107 117 // Post meta keys 108 118 $wcpt_meta_keys = WordCamp_Admin::meta_keys(); … … 142 152 } 143 153 } 154 } 155 156 /** 157 * Geocode the given address into a latitude and longitude pair. 158 * 159 * @param string $address 160 * 161 * @return mixed 162 * false if the geocode request failed 163 * array with latitude and longitude indexes if the request succeeded 164 */ 165 function geocode_address( $address ) { 166 if ( ! $address ) { 167 return false; 168 } 169 170 $coordinates = false; 171 $request_url = add_query_arg( 'address', urlencode( $address ), 'https://maps.googleapis.com/maps/api/geocode/json' ); 172 $geocode_response = json_decode( wp_remote_retrieve_body( wp_remote_get( $request_url ) ) ); 173 174 if ( ! empty( $geocode_response->results[0]->geometry->location->lat ) ) { 175 $coordinates = array( 176 'latitude' => $geocode_response->results[0]->geometry->location->lat, 177 'longitude' => $geocode_response->results[0]->geometry->location->lng 178 ); 179 } 180 181 return $coordinates; 144 182 } 145 183
Note: See TracChangeset
for help on using the changeset viewer.