Making WordPress.org

Changeset 7749


Ignore:
Timestamp:
10/19/2018 06:35:44 PM (7 years ago)
Author:
iandunn
Message:

Official WordPress Events: Add required key to Geocoding API requests.

The key is now required, and without it requests will quickly receive an OVER_QUERY_LIMIT error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php

    r7311 r7749  
    476476
    477477        $response = $this->remote_get( sprintf(
    478             'https://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&sensor=false',
     478            'https://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&sensor=false&key=%s',
    479479            $latitude,
    480             $longitude
     480            $longitude,
     481            OFFICIAL_WP_EVENTS_GOOGLE_MAPS_API_KEY
    481482        ) );
    482 
    483         if ( ! is_wp_error( $response ) ) {
     483        $body = json_decode( wp_remote_retrieve_body( $response ) );
     484
     485        if ( ! is_wp_error( $response ) && isset( $body->results ) && empty( $body->error_message ) ) {
    484486            $this->log( 'geocode successful' );
    485 
    486             $body = json_decode( wp_remote_retrieve_body( $response ) );
    487487
    488488            if ( isset( $body->results[0]->address_components ) ) {
     
    492492        }
    493493        else {
    494             $this->log( 'geocode failed' );
     494            $this->log( 'geocode failed: ' . wp_json_encode( $response ) );
    495495        }
    496496
Note: See TracChangeset for help on using the changeset viewer.