From d63c97bc06780cb6e573c55f84dfe5836dd716a2 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Wed, 18 Aug 2021 19:01:05 +0100 Subject: [PATCH] Add setting to disable email verification on unsubscribe --- CRM/Admin/Form/Preferences/Mailing.php | 3 ++- CRM/Mailing/Form/Unsubscribe.php | 10 ++++++---- settings/Mailing.setting.php | 14 ++++++++++++++ templates/CRM/Mailing/Form/Unsubscribe.tpl | 10 +++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CRM/Admin/Form/Preferences/Mailing.php b/CRM/Admin/Form/Preferences/Mailing.php index b2f4a975dc32..b56d4649450c 100644 --- a/CRM/Admin/Form/Preferences/Mailing.php +++ b/CRM/Admin/Form/Preferences/Mailing.php @@ -16,13 +16,14 @@ */ /** - * This class generates form components for the maling component preferences. + * This class generates form components for the mailing component preferences. */ class CRM_Admin_Form_Preferences_Mailing extends CRM_Admin_Form_Preferences { protected $_settings = [ 'profile_double_optin' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'profile_add_to_group_double_optin' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, + 'civimail_unsubscribe_verify_email' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'civimail_workflow' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'civimail_multiple_bulk_emails' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, diff --git a/CRM/Mailing/Form/Unsubscribe.php b/CRM/Mailing/Form/Unsubscribe.php index c63263ba0b9e..81b69c37f22e 100644 --- a/CRM/Mailing/Form/Unsubscribe.php +++ b/CRM/Mailing/Form/Unsubscribe.php @@ -74,8 +74,10 @@ public function buildQuickForm() { CRM_Utils_System::addHTMLHead(''); CRM_Utils_System::setTitle(ts('Unsubscribe Confirmation')); - $this->add('text', 'email_confirm', ts('Verify email address to unsubscribe:')); - $this->addRule('email_confirm', ts('Email address is required to unsubscribe.'), 'required'); + if (\Civi::settings()->get('civimail_unsubscribe_verify_email')) { + $this->add('text', 'email_confirm', ts('Verify email address to unsubscribe:')); + $this->addRule('email_confirm', ts('Email address is required to unsubscribe.'), 'required'); + } $buttons = [ [ @@ -95,8 +97,6 @@ public function buildQuickForm() { public function postProcess() { $values = $this->exportValues(); - // check if EmailTyped matches Email address - $result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE); $job_id = $this->_job_id; $queue_id = $this->_queue_id; $hash = $this->_hash; @@ -106,6 +106,8 @@ public function postProcess() { $session = CRM_Core_Session::singleton(); $session->pushUserContext($confirmURL); + // check if EmailTyped matches Email address + $result = \Civi::settings()->get('civimail_unsubscribe_verify_email') ? CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE) : TRUE; if ($result == TRUE) { // Email address verified $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash); diff --git a/settings/Mailing.setting.php b/settings/Mailing.setting.php index bfcc3580741d..a3bb64de853b 100644 --- a/settings/Mailing.setting.php +++ b/settings/Mailing.setting.php @@ -388,4 +388,18 @@ 'description' => ts('The frequency that CiviMail updates its sent mail database.'), 'help_text' => NULL, ], + 'civimail_unsubscribe_verify_email' => [ + 'group_name' => 'Mailing Preferences', + 'group' => 'mailing', + 'name' => 'civimail_unsubscribe_verify_email', + 'type' => 'Boolean', + 'html_type' => 'checkbox', + 'default' => TRUE, + 'add' => '5.42', + 'title' => ts('Disable email verification when unsubscribing'), + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Don\'t require the user to re-enter their email address to unsubscribe from mailings.'), + 'help_text' => NULL, + ], ]; diff --git a/templates/CRM/Mailing/Form/Unsubscribe.tpl b/templates/CRM/Mailing/Form/Unsubscribe.tpl index 6a1f97e792ae..8402636966aa 100644 --- a/templates/CRM/Mailing/Form/Unsubscribe.tpl +++ b/templates/CRM/Mailing/Form/Unsubscribe.tpl @@ -24,7 +24,14 @@

{ts}You are requesting to unsubscribe this email address:{/ts}

{$email_masked}

-

{ts}If this is not your email address, there is no need to do anything. You have not been added to any mailing lists. If this is your email address and you wish to unsubscribe please enter your email address below for verification purposes:{/ts}

+

{ts}If this is not your email address, there is no need to do anything. You have not been added to any mailing lists.{/ts} + {if empty($form.email_confirm)} + {ts}If this is your email address and you wish to unsubscribe please click the Unsubscribe button to confirm.{/ts} + {else} + {ts}If this is your email address and you wish to unsubscribe please enter your email address below for verification purposes:{/ts} + {/if} +

+ {if !empty($form.email_confirm)} @@ -33,6 +40,7 @@
+ {/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}