diff --git src/wp-admin/includes/class-wp-community-events.php src/wp-admin/includes/class-wp-community-events.php
index d3c6f08699..49c2af8c8e 100644
|
|
|
class WP_Community_Events { |
| 143 | 143 | */ |
| 144 | 144 | protected function get_request_url( $search = '', $timezone = '' ) { |
| 145 | 145 | $api_url = 'https://api.wordpress.org/events/1.0/'; |
| 146 | | $args = array( 'number' => 5 ); // Get more than three in case some get trimmed out. |
| | 146 | $args = array( |
| | 147 | // Get more than three in case some get trimmed out. |
| | 148 | 'number' => 5, |
| | 149 | |
| | 150 | // Anonymize the IP to protect user privacy. |
| | 151 | 'ip' => $this->maybe_anonymize_ip_address( $this->get_unsafe_client_ip() ), |
| | 152 | ); |
| 147 | 153 | |
| 148 | 154 | /* |
| 149 | 155 | * Send the minimal set of necessary arguments, in order to increase the |
| … |
… |
class WP_Community_Events { |
| 161 | 167 | |
| 162 | 168 | if ( $search ) { |
| 163 | 169 | $args['location'] = $search; |
| 164 | | } else { |
| 165 | | /* |
| 166 | | * Protect the user's privacy by anonymizing their IP before sending |
| 167 | | * it to w.org, and only send it when necessary. |
| 168 | | * |
| 169 | | * The w.org API endpoint only uses the IP address when a location |
| 170 | | * query is not provided, so we can safely avoid sending it when |
| 171 | | * there is a query. |
| 172 | | */ |
| 173 | | $args['ip'] = $this->maybe_anonymize_ip_address( $this->get_unsafe_client_ip() ); |
| 174 | 170 | } |
| 175 | 171 | } |
| 176 | 172 | |
| … |
… |
class WP_Community_Events { |
| 275 | 271 | protected function get_events_transient_key( $location ) { |
| 276 | 272 | $key = false; |
| 277 | 273 | |
| 278 | | if ( isset( $location['latitude'], $location['longitude'] ) ) { |
| | 274 | if ( isset( $location['ip'] ) ) { |
| | 275 | /* |
| | 276 | * Use the IP that was sent in the API request, not the IP that the |
| | 277 | * the API responded with. If the sent IP was private, the API will |
| | 278 | * use the corresponding public IP for geolocation, and return that. |
| | 279 | * If that public IP were used when setting the transient, then the |
| | 280 | * transient would never be successfully retrieved, because |
| | 281 | * get_unsafe_client_ip() will always return the private IP instead. |
| | 282 | */ |
| | 283 | $key = 'community-events-' . md5( $this->maybe_anonymize_ip_address( $this->get_unsafe_client_ip() ) ); |
| | 284 | } else if ( isset( $location['latitude'], $location['longitude'] ) ) { |
| 279 | 285 | $key = 'community-events-' . md5( $location['latitude'] . $location['longitude'] ); |
| 280 | 286 | } |
| 281 | 287 | |
diff --git src/wp-admin/includes/dashboard.php src/wp-admin/includes/dashboard.php
index 0f0058127f..f23fbde49d 100644
|
|
|
function wp_print_community_events_templates() { |
| 1247 | 1247 | ); ?> |
| 1248 | 1248 | </script> |
| 1249 | 1249 | |
| | 1250 | <script id="tmpl-community-events-attend-event-near-generic" type="text/template"> |
| | 1251 | <?php _e( 'Attend an upcoming event near you.' ); ?> |
| | 1252 | </script> |
| | 1253 | |
| 1250 | 1254 | <script id="tmpl-community-events-could-not-locate" type="text/template"> |
| 1251 | 1255 | <?php printf( |
| 1252 | 1256 | $script_data['l10n']['could_not_locate_city'], |
| … |
… |
function wp_print_community_events_templates() { |
| 1286 | 1290 | </li> |
| 1287 | 1291 | </script> |
| 1288 | 1292 | |
| | 1293 | <script id="tmpl-community-events-no-upcoming-events-generic" type="text/template"> |
| | 1294 | <li class="event-none"> |
| | 1295 | <?php printf( |
| | 1296 | /* translators: meetup organization documentation URL. */ |
| | 1297 | __( 'There aren’t any events scheduled near you at the moment. Would you like to <a href="%s">organize one</a>?' ), |
| | 1298 | __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' ) |
| | 1299 | ); ?> |
| | 1300 | </li> |
| | 1301 | </script> |
| 1289 | 1302 | <?php |
| 1290 | 1303 | } |
| 1291 | 1304 | |
diff --git src/wp-admin/js/dashboard.js src/wp-admin/js/dashboard.js
index 6a9b5033d4..8d2994696c 100644
|
|
|
jQuery( function( $ ) { |
| 369 | 369 | * Determine which templates should be rendered and which elements |
| 370 | 370 | * should be displayed. |
| 371 | 371 | */ |
| 372 | | if ( templateParams.location ) { |
| | 372 | if ( templateParams.location.ip ) { |
| | 373 | /* |
| | 374 | * If the API determined the location by geolocating an IP, it will |
| | 375 | * provide events, but not a specific location. |
| | 376 | */ |
| | 377 | template = wp.template( 'community-events-attend-event-near-generic' ); |
| | 378 | $locationMessage.html( template( templateParams ) ); |
| | 379 | |
| | 380 | if ( templateParams.events.length ) { |
| | 381 | template = wp.template( 'community-events-event-list' ); |
| | 382 | $results.html( template( templateParams ) ); |
| | 383 | } else { |
| | 384 | template = wp.template( 'community-events-no-upcoming-events-generic' ); |
| | 385 | $results.html( template( templateParams ) ); |
| | 386 | } |
| | 387 | |
| | 388 | elementVisibility['#community-events-location-message'] = true; |
| | 389 | elementVisibility['.community-events-toggle-location'] = true; |
| | 390 | elementVisibility['.community-events-results'] = true; |
| | 391 | |
| | 392 | } else if ( templateParams.location.description ) { |
| 373 | 393 | template = wp.template( 'community-events-attend-event-near' ); |
| 374 | 394 | $locationMessage.html( template( templateParams ) ); |
| 375 | 395 | |