diff --git a/classes/class-pbs-check-dma-settings.php b/classes/class-pbs-check-dma-settings.php
index 3b199e3..f0a557c 100644
--- a/classes/class-pbs-check-dma-settings.php
+++ b/classes/class-pbs-check-dma-settings.php
@@ -62,7 +62,8 @@ public function register_settings() {
add_settings_field( 'jwplayer_uri', 'JW Player URI', array( $this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'jwplayer_uri', 'class' => 'regular-text', 'label' => 'Full URI to the JW Player javascript, unique to your JWPlayer.com account. Leave blank to use video.js', 'default' => '') );
- add_settings_field('ip_zip_override', 'Override zipcode for IPs', array( $this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'ip_zip_override', 'class' => 'regular-text', 'type' => 'textarea', 'default' => '', 'label' => 'Add JSON formated pairs of IP -> zipcodes if you want a specific IP address to appear to be in a zipcode eg
[
{"127.0.0.1":"00001"},
{"127.0.0.2":"00002"}
]
NO TRAILING COMMA ON LAST PAIR, thats invalid JSON
Be kind and don\'t delete pairs from other people.'));
+ add_settings_field('ip_zip_override_array', 'Override zipcode for IPs', array( $this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'ip_zip_override_array', 'class' => 'regular-text', 'type' => 'array', 'options' => array('count_source' => 'ip_zip_count', 'ip' => array('label' => 'IP Num', 'class' => 'medium-text'), 'zip' => array('label' => '5-digit zipcode', 'class' => 'medium-text'), 'note' => array('label' => 'Note', 'class' => 'regular-text')), 'label' => 'For debugging issues outside your physical DMA. Enter a specific IP number and the zipcode you want to appear to be there. Put a note describing who its for, and delete when done testing.
WARNING: if you\'re in an office or home network, this will probably apply to ALL devices in that network making requests to this server, as they will appear to the server to have the same IP number.'));
+ add_settings_field( 'ip_zip_count', 'IP-Zip Count', array($this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'ip_zip_count', 'type' => 'text', 'default' => 1, 'label' => 'Increase from 1 if you need to have more IP zip overrides active. If you have more than 1 active and reduce back to 1, please save this page twice to remove any old data', 'class' => 'small-text') );
}
@@ -73,7 +74,7 @@ public function settings_field( $args ) {
$settingname = esc_attr( $args['setting'] );
$setting = get_option($settingname);
$field = esc_attr( $args['field'] );
- $label = esc_attr( $args['label'] );
+ $label = !empty($args['label']) ? trim($args['label']) : '';
$class = esc_attr( $args['class'] );
$type = ($args['type'] ? esc_attr( $args['type'] ) : 'text' );
$options = (is_array($args['options']) ? $args['options'] : array('true', 'false') );
diff --git a/classes/class-pbs-check-dma.php b/classes/class-pbs-check-dma.php
index 19fd228..359b7cd 100644
--- a/classes/class-pbs-check-dma.php
+++ b/classes/class-pbs-check-dma.php
@@ -115,23 +115,20 @@ public function manually_override_zipcode_from_ip($client_ip) {
// in which case it returns the zipcode
$return = false;
$defaults = get_option($this->token);
- if (!empty(trim($defaults['ip_zip_override']))) {
- $ip_zip_override = str_replace("\n", "", $defaults['ip_zip_override']);
- $ip_zip_override = str_replace("\r", "", $ip_zip_override);
- if (json_decode($ip_zip_override)){
- $json_ary = json_decode($ip_zip_override, true);
- foreach ($json_ary as $pair) {
- foreach ($pair as $ip => $zip) {
- if (!filter_var($ip, FILTER_VALIDATE_IP)){
- continue;
- }
- if ($client_ip == $ip) {
- if (is_string($zip) && 1 === preg_match("/^[0-9]{5}$/", $zip)) {
- $return = $zip;
- break;
- }
- }
- }
+ if (empty($defaults['ip_zip_override_array'])) {
+ return false;
+ }
+ $raw_pairs = $defaults['ip_zip_override_array'];
+ foreach ($raw_pairs as $pair) {
+ $this_ip = trim($pair['ip']);
+ if (!filter_var($this_ip, FILTER_VALIDATE_IP)){
+ continue;
+ }
+ if ($client_ip == $this_ip) {
+ $this_zip = trim($pair['zip']);
+ if (is_string($this_zip) && 1 === preg_match("/^[0-9]{5}$/", $this_zip)) {
+ $return = $this_zip;
+ break;
}
}
}