Skip to content

Commit

Permalink
Add setting to disable email verification on unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Aug 18, 2021
1 parent f7ec1ba commit d63c97b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CRM/Admin/Form/Preferences/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions CRM/Mailing/Form/Unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ public function buildQuickForm() {
CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
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 = [
[
Expand All @@ -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;
Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions settings/Mailing.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];
10 changes: 9 additions & 1 deletion templates/CRM/Mailing/Form/Unsubscribe.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
<div class="crm-block crm-form-block crm-miscellaneous-form-block">
<p>{ts}You are requesting to unsubscribe this email address:{/ts}</p>
<h3>{$email_masked}</h3>
<p>{ts}If this is not your email address, there is no need to do anything. You have <i><b>not</b></i> been added to any mailing lists. If this is your email address and you <i><b>wish to unsubscribe</b></i> please enter your email address below for verification purposes:{/ts}</p>
<p>{ts}If this is not your email address, there is no need to do anything. You have <strong>not</strong> been added to any mailing lists.{/ts}
{if empty($form.email_confirm)}
{ts}If this is your email address and you <strong>wish to unsubscribe</strong> please click the <strong>Unsubscribe</strong> button to confirm.{/ts}
{else}
{ts}If this is your email address and you <strong>wish to unsubscribe</strong> please enter your email address below for verification purposes:{/ts}
{/if}
</p>
{if !empty($form.email_confirm)}
<table class="form-layout">
<tbody>
<tr>
Expand All @@ -33,6 +40,7 @@
</tr>
</tbody>
</table>
{/if}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
Expand Down

0 comments on commit d63c97b

Please sign in to comment.