Make consent checkbox and form note configurable

Add independent admin controls for the consent checkbox and explanatory note. Keep both enabled by default so existing installations retain their current behavior.

Render the optional elements conditionally and require consent in server validation only when the checkbox is enabled. Bump the plugin and stable release version to 1.3.4, document the controls, and cover enabled/disabled rendering, validation, and invalid settings in the integration suite.

Validation: PHP syntax and NL/EN integration checks passed on Hephaestus, with mail intercepted during tests. Staged whitespace checks passed. No changes to antispam behavior or other website configurations.
This commit is contained in:
parkel committed 2026-11-09 23:41:55 +01:00
1 parent 0cad18c757
commit e1df255b0b
7 files changed
+25 -7

No files matched your search

+11
View File
@@ -4,6 +4,17 @@ function hgcf_assert($ok,$label){if(!$ok)WP_CLI::error($label);WP_CLI::log('PASS
$legacy=array_replace(hgcf_defaults(),['recipient'=>'recipient@example.com','sender_email'=>'forms@example.com','sender_name'=>'Example Practice','site_name'=>'Example practice','contact_name'=>'Taylor','enable_requests'=>true,'show_phone'=>true,'opening_time'=>'10:00','closing_time'=>'18:00','services'=>['consultation'=>['Kennismaking','Introduction']],'title_nl'=>'Vraag aan {contact_name}']);
$config=$legacy;$override=function()use(&$config){return $config;};add_filter('pre_option_hgcf_settings',$override);
$languages=['nl'=>'Nederlands','en'=>'English'];$language_override=function()use(&$languages){return $languages;};add_filter('hgcf_languages',$language_override);
hgcf_assert(hgcf_defaults()['show_consent']===true&&hgcf_defaults()['show_note']===true,'existing sites keep consent and note defaults');
$config['show_consent']=false;$config['show_note']=false;
$withoutConsent=['name'=>'Test Visitor','email'=>'visitor@example.com','message'=>'A useful question','mode'=>'question'];
hgcf_assert(!is_wp_error(hgcf_validate($withoutConsent)),'consent disabled allows missing field');
foreach(['nl','en'] as $language){$rendered=hgcf_render(['lang'=>$language]);hgcf_assert(!str_contains($rendered,'name="mlhc_consent"')&&!str_contains($rendered,hgcf_local_setting('note',$language)),'disabled consent and note absent in '.$language);}
$config['show_consent']=true;$config['show_note']=true;
hgcf_assert(is_wp_error(hgcf_validate($withoutConsent)),'enabled consent still enforced');
$rendered=hgcf_render(['lang'=>'nl']);hgcf_assert(str_contains($rendered,'name="mlhc_consent"')&&str_contains($rendered,hgcf_local_setting('note','nl')),'enabled consent and note retained');
$toggleClean=hgcf_sanitize_settings(['show_consent'=>'0','show_note'=>'0']);hgcf_assert(!$toggleClean['show_consent']&&!$toggleClean['show_note'],'display toggles save as booleans');
$toggleClean=hgcf_sanitize_settings(['show_consent'=>['bad'],'show_note'=>'bad']);hgcf_assert($toggleClean['show_consent']&&$toggleClean['show_note'],'invalid display toggles preserve values');
$config=$legacy;
$normalized=hgcf_settings();hgcf_assert(count($normalized['workflows'])===2&&$normalized['workflows']['request']['services']['consultation']['en']==='Introduction','legacy question/request and translated services preserved');
hgcf_assert($normalized['sender_email']==='forms@example.com'&&$normalized['recipient']==='recipient@example.com','sender and recipient preserved during migration');
$config=$normalized;