How to add Single Opt-In to WP Autoresponder

WP Autoresponder (v5.2.8) comes with a double opt-in mechanism only, which has a few disadvantages. I run an SaaS business and I need to enter new subscribers to the software automatically. The subscribers’ email addresses are confirmed within the main application and don’t need to be verified twice.

Fortunately, it is quite easy and straight forward to add the single opt-in functionality to WP Autoresponder with a few lines of code. The idea is to do the signup of a new subscriber and the confirmation process in a single step.

optin.php is the file that processes the signup of a new subscriber and sends out the confirmation email. Beginning in line 40, the script processes a bunch of form fields. I added a new form field called single_optin that will be sent along with the rest of our form (or POST-request).

In line 49, right below the declaration of $commentfield I added the following:

...
$commentfield = $_POST['comment'];
$single_optin = (int)wpr_sanitize(
    $_POST['single_optin']);

Then, the script does a few things to validate the request. The next interesting piece of code is in line 362. $p is the base64-encoded confirmation code for that subscriber.

The whole process for subscriber confirmation happens in confirm.php and conveniently enough, we can simply include it into the optin.php script.

If you have a look at line 4 in confirm.php you’ll notice that the whole script requires basically only one parameter – the confirmation string that is generated in optin.php and declared in $p.

So, in optin.php right below the declaration of $p I added the following snippet in line 364:

$p = trim(base64_encode($theqstring),"=");
// modification: added single-optin
if ($single_optin > 0) {
    $_GET['wpr-confirm'] = $p;
    include "confirm.php";
    exit;
}

The code is simple. If we received a parameter single_optin with value = 1 along with our POST-request, we simply set the confirmation code as a $_GET-parameter, include the confirmation process, and exit the script before the confirmation request email is sent to the subscriber.

In confirm.php I added the following piece of code at line 41:

if ($single_optin > 0) { 
    do_action("_wpr_autoresponder_process");
    die('1');
} else {
    sendConfirmedEmail($id);
}

If $single_optin is set, we schedule the _wpr_autoresponder_process wp-cronjob and die. The call of die() is optional. I use it, because I run the whole subscription via cURL from my main application and do not need a confirmation page. However, feel free to remove die() and show the user the page that tells him that his email address was confirmed successfully.

Don’t forget to pass the parameter single_optin=1 along with your POST-request or add a hidden field to your signup form like that:

<input type="hidden" name="single_optin" value="1" />

Get the modified files and copy both into your wp-responder-email-autoresponder-and-newsletter-plugin/ folder:
wp-autoresponder-single-optin-5.2.8

Comments

  1. Eleonora says:

    Really, really thank you for this tutorial.
    That’s exactly what I was looking for…you made me save hours of coding :)

    • I’m glad I could help you. By the way, I stopped using WP Autoresponder, because I wanted to make a series of autoresponders that get triggered one after another but somehow I never really figured when the next email is scheduled. The behavior of WP Autoresponder is a bit odd.

      Anyways, if you just want the basic functionality (newsletter & one autoresponder), WP Autoresponder should be fine.

  2. Vincent says:

    I love WP Responder – BUT, it seems to have problems with delivering the entire series of messages.

    What’s great about it is the messages really do go right to the inbox and NOT the spam box.
    Unfortunately, it was never single opt-in and again, the message series – don’t all get delivered.

    I’ve spoken to Raj about this but still no clear cut answers.

  3. Xander says:

    Hi there, i can’t get the single opt-in to work on the WP autoresponder after the latest update. Do you have a new solution for it? Many thanks!

Speak Your Mind

*