Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
tamw-wnet committed Jun 28, 2024
1 parent ddc00fe commit 14b7e67
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions classes/class-pbs-check-dma.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function use_custom_template($template) {
public function get_location_from_ip($client_ip) {
#possibly manually override the zipcode
$override_zipcode = $this->manually_override_zipcode_from_ip($client_ip);
error_log("override_zipcode is $override_zipcode");
$zip_url = 'https://services.pbs.org/zipcodes/ip/';
$combined_url = $zip_url . $client_ip . '.json';
$response = wp_remote_get($combined_url, array());
Expand All @@ -74,15 +73,13 @@ public function get_location_from_ip($client_ip) {
$parsed = json_decode($body, TRUE);
$item = !empty($parsed['$items'][0]) ? $parsed['$items'][0] : false;
if (!$item && !$override_zipcode) {
error_log("parse error");
return array('errors' => $response);
}
$zipcode = !empty($item['zipcode']) ? (string) $item['zipcode'] : '';
$zipcode = $override_zipcode ? $override_zipcode : $zipcode;
$state = '';
$county = '';
if (!$override_zipcode && (empty($item['$links']) || !is_array($item['$links']))) {
error_log("links error");
return array('errors' => $response);
}
if (is_array($item['$links'])) {
Expand All @@ -96,7 +93,6 @@ public function get_location_from_ip($client_ip) {
}
$country = !empty($zipcode) ? 'USA' : 'Outside of the US'; // the PBS endpoint returns a 404 for non-US IP addresses
$return = array('zipcode' => $zipcode, 'state' => $state, 'county' => $county, 'country' => $country);
error_log("location is " . json_encode($return));
return $return;
}
}
Expand Down

0 comments on commit 14b7e67

Please sign in to comment.