WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/19/2017 05:48:01 AM (2 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-includes/script-loader.php

    r40776 r40790  
    10131013    require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' );
    10141014
    1015     $user_id       = get_current_user_id();
    1016     $user_location = get_user_option( 'community-events-location', $user_id );
    1017     $events_client = new WP_Community_Events( $user_id, $user_location );
     1015    $user_id            = get_current_user_id();
     1016    $saved_location     = get_user_option( 'community-events-location', $user_id );
     1017    $saved_ip_address   = isset( $saved_location['ip'] ) ? $saved_location['ip'] : false;
     1018    $current_ip_address = WP_Community_Events::get_unsafe_client_ip();
     1019
     1020    /*
     1021     * If the user's location is based on their IP address, then update their
     1022     * location when their IP address changes. This allows them to see events
     1023     * in their current city when travelling. Otherwise, they would always be
     1024     * shown events in the city where they were when they first loaded the
     1025     * Dashboard, which could have been months or years ago.
     1026     */
     1027    if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) {
     1028        $saved_location['ip'] = $current_ip_address;
     1029        update_user_option( $user_id, 'community-events-location', $saved_location, true );
     1030    }
     1031
     1032    $events_client = new WP_Community_Events( $user_id, $saved_location );
    10181033
    10191034    wp_localize_script( 'dashboard', 'communityEventsData', array(
     
    10241039            'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ),
    10251040            'error_occurred_please_try_again' => __( 'An error occurred. Please try again.' ),
     1041            'attend_event_near_generic' => __( 'Attend an upcoming event near you.' ),
    10261042
    10271043            /*
Note: See TracChangeset for help on using the changeset viewer.