Make WordPress Core


Ignore:
Timestamp:
05/19/2017 05:48:01 AM (8 years ago)
Author:
azaozz
Message:

Dashboard: Improve the handling of locations determined by geolocating the IP address and by entering a city name. Fix couple of edge cases, and some names.

Props iandunn coreymckrill.
Fixes #40702.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r40651 r40790  
    313313    $events_client  = new WP_Community_Events( $user_id, $saved_location );
    314314    $events         = $events_client->get_events( $search, $timezone );
     315    $ip_changed     = false;
    315316
    316317    if ( is_wp_error( $events ) ) {
     
    319320        ) );
    320321    } else {
    321         if ( isset( $events['location'] ) ) {
    322             // Store the location network-wide, so the user doesn't have to set it on each site.
     322        if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) {
     323            $ip_changed = true;
     324        } elseif ( isset( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) && $saved_location['ip'] !== $events['location']['ip'] ) {
     325            $ip_changed = true;
     326        }
     327
     328        /*
     329         * The location should only be updated when it changes. The API doesn't always return
     330         * a full location; sometimes it's missing the description or country. The location
     331         * that was saved during the initial request is known to be good and complete, though.
     332         * It should be left in tact until the user explicitly changes it (either by manually
     333         * searching for a new location, or by changing their IP address).
     334         *
     335         * If the location were updated with an incomplete response from the API, then it could
     336         * break assumptions that the UI makes (e.g., that there will always be a description
     337         * that corresponds to a latitude/longitude location).
     338         *
     339         * The location is stored network-wide, so that the user doesn't have to set it on each site.
     340         */
     341        if ( $ip_changed || $search ) {
    323342            update_user_option( $user_id, 'community-events-location', $events['location'], true );
    324343        }
Note: See TracChangeset for help on using the changeset viewer.