From 6ca06336ea6b6d4109a999b4b3626ee83c212622 Mon Sep 17 00:00:00 2001 From: rivanuff Date: Mon, 2 Mar 2026 15:11:35 +0100 Subject: [PATCH 1/2] fix: implement upstream lookup logic for sites on php 7.4 --- phpstan-bootstrap.php | 2 +- plugin.php | 4 +- src/BAG/GravityForms/BAGAddress/BAGLookup.php | 53 ++++++++++--------- tests/Unit/bootstrap.php | 2 +- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php index 041c8f4..ce87fe8 100644 --- a/phpstan-bootstrap.php +++ b/phpstan-bootstrap.php @@ -4,4 +4,4 @@ define('GF_BAG_FILE', 'plugin.php'); define('GF_BAG_SLUG', 'owc-gravityforms-bag-address'); define('GF_BAG_ROOT_PATH', './'); -define('GF_BAG_VERSION', '1.1.3'); +define('GF_BAG_VERSION', '1.1.6'); diff --git a/plugin.php b/plugin.php index 9c753a1..3ffd6b4 100644 --- a/plugin.php +++ b/plugin.php @@ -5,7 +5,7 @@ * Description: Add a BAG address field to GravityForms. * Author: Yard | Digital Agency * Author URI: https://www.yard.nl - * Version: 1.1.5 + * Version: 1.1.6 * License: GPL3.0 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt * Text Domain: owc-gravityforms-bag-address @@ -23,7 +23,7 @@ define('GF_BAG_SLUG', 'owc-gravityforms-bag-address'); define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG); define('GF_BAG_ROOT_PATH', __DIR__); -define('GF_BAG_VERSION', '1.1.5'); +define('GF_BAG_VERSION', '1.1.6'); /** * Manual loaded file: the autoloader. diff --git a/src/BAG/GravityForms/BAGAddress/BAGLookup.php b/src/BAG/GravityForms/BAGAddress/BAGLookup.php index 5e6c1c5..1e7d952 100644 --- a/src/BAG/GravityForms/BAGAddress/BAGLookup.php +++ b/src/BAG/GravityForms/BAGAddress/BAGLookup.php @@ -111,34 +111,35 @@ public static function make(): self * @return string */ private function parseURLvariables(): string - { - $params = [ - 'postcode' => $this->zip, - 'type' => 'adres' - ]; - - if (empty($this->homeNumberAddition)) { - $params = array_merge($params, [ - 'huis_nlt' => $this->homeNumber, - ]); - } else { - $params = array_merge($params, [ - 'huisnummer' => $this->homeNumber, - 'huisletter' => $this->homeNumberAddition, - ]); - } + { + $arg_and = ['type:adres']; + $arg_or = []; - $filteredParameters = array_filter( - $params, - function ($item) { - return !empty($item); - } - ); + if (!empty($this->zip)) { + $arg_and[] = "postcode:{$this->zip}"; + } - $query = http_build_query($filteredParameters, null, '%20and%20'); - $query = str_replace('=', ':', $query); - return sprintf('%s%s', $this->url, $query); - } + if (!empty($this->homeNumber)) { + $arg_and[] = "huisnummer:{$this->homeNumber}"; + } + + if (!empty($this->homeNumberAddition)) { + $addition = strtoupper($this->homeNumberAddition); + + $arg_or[] = [ + "huisnummertoevoeging:{$addition}", + "huisletter:{$addition}", + ]; + } + + $arg_or = array_map(function ($group) { + return '( ' . implode(' or ', $group) . ' )'; + }, $arg_or); + + $query = implode(' and ', array_merge($arg_and, $arg_or)); + + return $this->url . urlencode($query); + } /** * Actually execute the remote request. diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 4b61444..76c2f39 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -24,7 +24,7 @@ define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG); define('GF_BAG_DIR', basename(__DIR__)); define('GF_BAG_ROOT_PATH', __DIR__); -define('GF_BAG_VERSION', '1.1.3'); +define('GF_BAG_VERSION', '1.1.6'); /** * Bootstrap WordPress Mock. From 8a1a4d7b6e23afb3f3aa2e442ddc98a7c057ff45 Mon Sep 17 00:00:00 2001 From: rivanuff Date: Fri, 20 Mar 2026 13:54:15 +0100 Subject: [PATCH 2/2] fix: return result with no addition if not provided --- phpstan-bootstrap.php | 2 +- plugin.php | 4 +-- src/BAG/GravityForms/BAGAddress/BAGLookup.php | 26 +++++++++++++++++++ tests/Unit/bootstrap.php | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php index ce87fe8..678bca9 100644 --- a/phpstan-bootstrap.php +++ b/phpstan-bootstrap.php @@ -4,4 +4,4 @@ define('GF_BAG_FILE', 'plugin.php'); define('GF_BAG_SLUG', 'owc-gravityforms-bag-address'); define('GF_BAG_ROOT_PATH', './'); -define('GF_BAG_VERSION', '1.1.6'); +define('GF_BAG_VERSION', '1.1.7'); diff --git a/plugin.php b/plugin.php index 3ffd6b4..65ff651 100644 --- a/plugin.php +++ b/plugin.php @@ -5,7 +5,7 @@ * Description: Add a BAG address field to GravityForms. * Author: Yard | Digital Agency * Author URI: https://www.yard.nl - * Version: 1.1.6 + * Version: 1.1.7 * License: GPL3.0 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt * Text Domain: owc-gravityforms-bag-address @@ -23,7 +23,7 @@ define('GF_BAG_SLUG', 'owc-gravityforms-bag-address'); define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG); define('GF_BAG_ROOT_PATH', __DIR__); -define('GF_BAG_VERSION', '1.1.6'); +define('GF_BAG_VERSION', '1.1.7'); /** * Manual loaded file: the autoloader. diff --git a/src/BAG/GravityForms/BAGAddress/BAGLookup.php b/src/BAG/GravityForms/BAGAddress/BAGLookup.php index 1e7d952..1fb0f97 100644 --- a/src/BAG/GravityForms/BAGAddress/BAGLookup.php +++ b/src/BAG/GravityForms/BAGAddress/BAGLookup.php @@ -87,6 +87,32 @@ protected function processResponse($response): string ]); } + // If no addition was provided, try to find the result without any addition + if ($this->homeNumberAddition === '') { + $exactMatch = null; + + foreach ($response->docs as $doc) { + if (!isset($doc->huisnummertoevoeging) && !isset($doc->huisletter)) { + $exactMatch = $doc; + break; + } + } + + if ($exactMatch !== null) { + $address = new BAGEntity($exactMatch); + return \wp_send_json_success([ + 'message' => __('1 result found', config('core.text_domain')), + 'results' => [ + 'street' => $address->straatnaam, + 'houseNumber' => $address->huisnummer, + 'city' => $address->woonplaatsnaam, + 'zip' => $address->postcode, + 'displayname' => $address->weergavenaam + ] + ]); + } + } + return wp_send_json_error( [ 'message' => __('Found too many results. Try to make the address more specific. For example with a house number addition', config('core.text_domain')), diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 76c2f39..cee177a 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -24,7 +24,7 @@ define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG); define('GF_BAG_DIR', basename(__DIR__)); define('GF_BAG_ROOT_PATH', __DIR__); -define('GF_BAG_VERSION', '1.1.6'); +define('GF_BAG_VERSION', '1.1.7'); /** * Bootstrap WordPress Mock.