From 40ebad03eec44ee2b56ade7983afa36e612e1edd Mon Sep 17 00:00:00 2001 From: rivanuff Date: Thu, 7 May 2026 14:15:00 +0200 Subject: [PATCH 1/5] feat: add option to show visitor ip on unauthorized visit --- languages/config-expander-nl_NL.mo | Bin 873 -> 1209 bytes languages/config-expander-nl_NL.po | 15 ++++++++++++++- languages/config-expander.pot | 17 +++++++++++++++-- src/ACF/ACFServiceProvider.php | 20 ++++++++++++++++++++ src/Protection/Protect.php | 24 ++++++++++++++++++++---- 5 files changed, 69 insertions(+), 7 deletions(-) diff --git a/languages/config-expander-nl_NL.mo b/languages/config-expander-nl_NL.mo index dc3118cb43a427b980840a5ac6216284e0003870..1da1450ab27360525ff03d084a136622671d211b 100644 GIT binary patch delta 587 zcmX|7%Sr=55FDdMM1<%eAb9A5f++4$@TNiVf%t$Z3W7{_+sSA$6K5s~c*zflD8Ya5 z;0Ks5@GK&D(zAbI?Z!Az)ND_8b=Cgld*hw2>5)f)GX~58Wncoh1=8~ZOaeWi0K5Ws zz$dT_9XvW zJtVX>5gpW6dQPhZg$wO`h{UOFI@&%UnIstU1etmN-y2&KWE>#R=%{O>eQ+{ZmpZ|w zLX&;Krgl{auHmtJIP~0I%&jbxEh`CQircIeJJ^?Gq;!-p*24rMXd}DlxsT2k2deOu zzPw^XEosnm!)Y8eP>UTynHX>V@L3{`XwyllP)Cryq+%0^9ouXp(Xvbf4f5gBQUibel=u&0ZHJU^#A|> delta 215 zcmdnV`I0T>o)F7a1|VPoVi_Q|0dasJ210@9J|H_5h#i3V4G^mWu`VM60}l`f1MvhP zKY@vX!3juz1kxrz+Ju>bVdC|RDv|l6>P4vvdHE#@i8(p><*6wOCHV?vnW^OpB^jB; z3I&Pjsguo_*06`@Iv1rTmP~%hq%!#-lf`5w<}0RNsR|jXNhJ#Dsi}EDZK=g2skynC hdFcxIxe6(%RjDA|nR$r{C8-KYso9xX*{OMY3;;nfHHQEI diff --git a/languages/config-expander-nl_NL.po b/languages/config-expander-nl_NL.po index 48bfe4c..ab30b2d 100644 --- a/languages/config-expander-nl_NL.po +++ b/languages/config-expander-nl_NL.po @@ -19,6 +19,19 @@ msgstr "De vereiste plugin voor de Config Expander package Advanced Cust msgid "This link does not work, go to our website: %s." msgstr "Deze link bestaat niet, ga naar onze website: %s." -#: src/Protection/Protect.php:80 +#: src/Protection/Protect.php:89 msgid "Viewing this page requires a login session. Please log in first." msgstr "Het bekijken van deze pagina vereist een login sessie. Graag eerst inloggen." + +#. translators: %s: visitor IP address +#: src/Protection/Protect.php:93 +msgid "Your IP address is %s. Please contact the administrator to request a whitelist." +msgstr "Jouw IP-adres is %s. Neem contact op met de beheerder om een whitelist aan te vragen." + +#: src/Protection/Protect.php:101 +msgid "Access Denied" +msgstr "Toegang geweigerd" + +#: src/Protection/Protect.php:105 +msgid "Go to login page" +msgstr "Ga naar de inlogpagina" diff --git a/languages/config-expander.pot b/languages/config-expander.pot index a8d32d7..f33d3cf 100644 --- a/languages/config-expander.pot +++ b/languages/config-expander.pot @@ -20,6 +20,19 @@ msgstr "" msgid "This link does not work, go to our website: %s." msgstr "" -#: src/Protection/Protect.php:80 -msgid "You're not allowed to view this page." +#: src/Protection/Protect.php:89 +msgid "Viewing this page requires a login session. Please log in first." +msgstr "" + +#. translators: %s: visitor IP address +#: src/Protection/Protect.php:93 +msgid "Your IP address is %s. Please contact the administrator to request a whitelist." +msgstr "" + +#: src/Protection/Protect.php:101 +msgid "Access Denied" +msgstr "" + +#: src/Protection/Protect.php:105 +msgid "Go to login page" msgstr "" diff --git a/src/ACF/ACFServiceProvider.php b/src/ACF/ACFServiceProvider.php index ee16a1d..bc2b7f3 100644 --- a/src/ACF/ACFServiceProvider.php +++ b/src/ACF/ACFServiceProvider.php @@ -134,6 +134,26 @@ public function addLocalFieldGroup(): void 'ajax' => 0, 'placeholder' => '', ], + [ + 'key' => 'field_666962be81793', + 'label' => 'Toon IP bij geweigerde toegang', + 'name' => 'show_ip_on_deny', + 'aria-label' => '', + 'type' => 'true_false', + 'instructions' => 'Toon het IP-adres van de bezoeker bij geweigerde toegang.', + 'required' => 0, + 'conditional_logic' => 0, + 'wrapper' => [ + 'width' => '', + 'class' => '', + 'id' => '', + ], + 'message' => '', + 'default_value' => 0, + 'ui' => 1, + 'ui_on_text' => 'Aan', + 'ui_off_text' => 'Uit', + ], [ 'key' => 'field_666845f07125a', 'label' => 'IP-adres whitelist', diff --git a/src/Protection/Protect.php b/src/Protection/Protect.php index 0a22983..02ccd0a 100644 --- a/src/Protection/Protect.php +++ b/src/Protection/Protect.php @@ -37,7 +37,7 @@ protected function authorizeAccess(string $type): void */ protected function setNoCacheHeader(): void { - header('Cache-Control: no-cache'); + nocache_headers(); } protected function checkIfVisitorHasAccess(string $type): bool @@ -86,9 +86,25 @@ protected function currentProtectionTypeMatchesWhitelist(string $type, Whitelist protected function denyAccess(): void { - header('HTTP/1.0 401 Unauthorized'); - echo __('Viewing this page requires a login session. Please log in first.', 'config-expander'); - exit; + $message = __('Viewing this page requires a login session. Please log in first.', 'config-expander'); + + if (function_exists('get_field') && (bool) get_field('show_ip_on_deny', 'options') && in_array(get_field('type_protection_website', 'options'), ['login', 'both'], true)) { + $message .= ' ' . sprintf( + /* translators: %s: visitor IP address */ + __('Your IP address is %s. Please contact the administrator to request a whitelist.', 'config-expander'), + esc_html($this->ipCurrentVisitor()) + ); + } + + wp_die( + $message, + __('Access Denied', 'config-expander'), + [ + 'response' => 401, + 'link_url' => wp_login_url(), + 'link_text' => __('Go to login page', 'config-expander'), + ] + ); } protected function ipCurrentVisitor(): string From 5bb334ca99fff96ae4added4b7d533c06c66b98d Mon Sep 17 00:00:00 2001 From: rivanuff Date: Thu, 7 May 2026 14:26:34 +0200 Subject: [PATCH 2/5] Update src/Protection/Protect.php Co-authored-by: Dik Takken --- src/Protection/Protect.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Protection/Protect.php b/src/Protection/Protect.php index 02ccd0a..89115c7 100644 --- a/src/Protection/Protect.php +++ b/src/Protection/Protect.php @@ -88,7 +88,10 @@ protected function denyAccess(): void { $message = __('Viewing this page requires a login session. Please log in first.', 'config-expander'); - if (function_exists('get_field') && (bool) get_field('show_ip_on_deny', 'options') && in_array(get_field('type_protection_website', 'options'), ['login', 'both'], true)) { + + $showIp = function_exists('get_field') && (bool) get_field('show_ip_on_deny', 'options'); + $loginProtected = function_exists('get_field') && in_array(get_field('type_protection_website', 'options'), ['login', 'both'], true); + if ($showIp && $loginProtected) { $message .= ' ' . sprintf( /* translators: %s: visitor IP address */ __('Your IP address is %s. Please contact the administrator to request a whitelist.', 'config-expander'), From dd941661305e4b1298585476987e39c830e8beed Mon Sep 17 00:00:00 2001 From: Yard workflows Date: Thu, 7 May 2026 12:27:03 +0000 Subject: [PATCH 3/5] style: apply php-cs-fixer changes --- src/Protection/Protect.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Protection/Protect.php b/src/Protection/Protect.php index 89115c7..1fa56f2 100644 --- a/src/Protection/Protect.php +++ b/src/Protection/Protect.php @@ -88,7 +88,6 @@ protected function denyAccess(): void { $message = __('Viewing this page requires a login session. Please log in first.', 'config-expander'); - $showIp = function_exists('get_field') && (bool) get_field('show_ip_on_deny', 'options'); $loginProtected = function_exists('get_field') && in_array(get_field('type_protection_website', 'options'), ['login', 'both'], true); if ($showIp && $loginProtected) { From b77e557ff4f19e71be983aadac866edd84b37d60 Mon Sep 17 00:00:00 2001 From: rivanuff Date: Thu, 7 May 2026 14:30:06 +0200 Subject: [PATCH 4/5] chore: readability --- languages/config-expander-nl_NL.po | 6 +++--- languages/config-expander.pot | 6 +++--- src/Protection/Protect.php | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/languages/config-expander-nl_NL.po b/languages/config-expander-nl_NL.po index ab30b2d..583456e 100644 --- a/languages/config-expander-nl_NL.po +++ b/languages/config-expander-nl_NL.po @@ -24,14 +24,14 @@ msgid "Viewing this page requires a login session. Please log in first." msgstr "Het bekijken van deze pagina vereist een login sessie. Graag eerst inloggen." #. translators: %s: visitor IP address -#: src/Protection/Protect.php:93 +#: src/Protection/Protect.php:97 msgid "Your IP address is %s. Please contact the administrator to request a whitelist." msgstr "Jouw IP-adres is %s. Neem contact op met de beheerder om een whitelist aan te vragen." -#: src/Protection/Protect.php:101 +#: src/Protection/Protect.php:104 msgid "Access Denied" msgstr "Toegang geweigerd" -#: src/Protection/Protect.php:105 +#: src/Protection/Protect.php:108 msgid "Go to login page" msgstr "Ga naar de inlogpagina" diff --git a/languages/config-expander.pot b/languages/config-expander.pot index f33d3cf..8579935 100644 --- a/languages/config-expander.pot +++ b/languages/config-expander.pot @@ -25,14 +25,14 @@ msgid "Viewing this page requires a login session. Please log in first." msgstr "" #. translators: %s: visitor IP address -#: src/Protection/Protect.php:93 +#: src/Protection/Protect.php:97 msgid "Your IP address is %s. Please contact the administrator to request a whitelist." msgstr "" -#: src/Protection/Protect.php:101 +#: src/Protection/Protect.php:104 msgid "Access Denied" msgstr "" -#: src/Protection/Protect.php:105 +#: src/Protection/Protect.php:108 msgid "Go to login page" msgstr "" diff --git a/src/Protection/Protect.php b/src/Protection/Protect.php index 1fa56f2..e8dc017 100644 --- a/src/Protection/Protect.php +++ b/src/Protection/Protect.php @@ -90,7 +90,8 @@ protected function denyAccess(): void $showIp = function_exists('get_field') && (bool) get_field('show_ip_on_deny', 'options'); $loginProtected = function_exists('get_field') && in_array(get_field('type_protection_website', 'options'), ['login', 'both'], true); - if ($showIp && $loginProtected) { + + if ($showIp && $loginProtected) { $message .= ' ' . sprintf( /* translators: %s: visitor IP address */ __('Your IP address is %s. Please contact the administrator to request a whitelist.', 'config-expander'), From ad1ae4f4ff00a1df82a07ff5bd5d0e87abb5e160 Mon Sep 17 00:00:00 2001 From: Yard workflows Date: Thu, 7 May 2026 12:30:36 +0000 Subject: [PATCH 5/5] style: apply php-cs-fixer changes --- src/Protection/Protect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protection/Protect.php b/src/Protection/Protect.php index e8dc017..4e63195 100644 --- a/src/Protection/Protect.php +++ b/src/Protection/Protect.php @@ -91,7 +91,7 @@ protected function denyAccess(): void $showIp = function_exists('get_field') && (bool) get_field('show_ip_on_deny', 'options'); $loginProtected = function_exists('get_field') && in_array(get_field('type_protection_website', 'options'), ['login', 'both'], true); - if ($showIp && $loginProtected) { + if ($showIp && $loginProtected) { $message .= ' ' . sprintf( /* translators: %s: visitor IP address */ __('Your IP address is %s. Please contact the administrator to request a whitelist.', 'config-expander'),