<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adam Capriola &#187; WordPress</title>
	<atom:link href="http://adamcap.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://adamcap.com</link>
	<description>The guy, behind the guy, behind the guy.</description>
	<lastBuildDate>Thu, 12 Apr 2012 00:32:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to Integrate AWeber and WordPress Registration &#8211; Without a Plugin!</title>
		<link>http://adamcap.com/2011/10/how-to-integrate-aweber-and-wordpress-registration-without-a-plugin/</link>
		<comments>http://adamcap.com/2011/10/how-to-integrate-aweber-and-wordpress-registration-without-a-plugin/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 17:35:21 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[aweber]]></category>

		<guid isPermaLink="false">http://adamcap.com/?p=1834</guid>
		<description><![CDATA[I thought I&#8217;d share how to do this since it&#8217;s something that ANYONE using WordPress could and probably should be doing if they&#8217;ve got any business savvy. Basically our goal here is to give users an option to join our e-mail list when they register for our website. Sounds simple enough, right? On the Prowl I [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d share how to do this since it&#8217;s something that ANYONE using WordPress could and probably should be doing if they&#8217;ve got any business savvy.</p>
<p>Basically our goal here is to give users an option to join our <a href="http://www.aweber.com/?334105">e-mail list</a> when they register for our website. Sounds simple enough, right?</p>
<div id="attachment_1839" class="wp-caption alignnone" style="width: 1267px"><a href="http://adamcap.com/wp-content/uploads/2011/10/registration-for-tcgscans.png"><img class="size-full wp-image-1839" title="registration for tcgscans" src="http://adamcap.com/wp-content/uploads/2011/10/registration-for-tcgscans.png" alt="" width="1257" height="695" /></a><p class="wp-caption-text">Beautiful.</p></div>
<h4>On the Prowl</h4>
<p>I initially tried searching for a simple plugin to &#8220;git er dun,&#8221; but only two legitimate-looking results came up: <a href="http://wordpress.org/extend/plugins/aweber-registration-integration/">AWeber Registration Integration (ARI)</a> and <a href="http://wordpress.org/extend/plugins/aweber-wordpress-plugin/">Aweber WordPress Plugin (AWP)</a></p>
<p>Neither plugin has been updated since 2009 (which makes them near-ancient at this point, technologically speaking), but I thought I&#8217;d give them both a whirl and see what would happen.</p>
<p>AWP wouldn&#8217;t even install, so that was an easy cross-off my long list of options. On to ARI!</p>
<p>ARI sort of worked. At times I was able to get it functioning, then other times it seemed to stop working. It also comes packed with this extra feature that monitors which of your registered users elected to opt-in to your e-mail list. It&#8217;s sort of pointless to track that natively in WordPress in my not-so-humble opinion, since you can track all of that in <a href="http://www.aweber.com/?334105">AWeber</a> (and most likely any other e-mail software).</p>
<p>Since I&#8217;m a such a perfectionist and I don&#8217;t like using plugins if I don&#8217;t have to, I decided to delve into the code of ARI and figure out exactly how it worked. Here&#8217;s the basic gist&#8230;</p>
<h4>How it Works</h4>
<p>Normally when you want somebody to sign up for your e-mail list, you have them fill out a form which includes name and e-mail input fields. I didn&#8217;t realize this until took a closer look at one of those forms, but basically all that happens when somebody clicks &#8220;submit&#8221; is that a unique URL is generated containing their name, e-mail, and some other parameters.</p>
<p>In essence, clicking submit is like clicking a URL they literally just created on the spot by filling out their name and e-mail. This is how somebody gets added to your list.</p>
<p>I personally use <a href="http://www.aweber.com/?334105">AWeber</a> for all my e-mail lists since it&#8217;s easy to manage and it flat-out WORKS. Conveniently, they have a <a href="http://www.aweber.com/faq/questions/396/Can+I+Use+My+Own+Form%3F">whole webpage</a> explaining all the parameters you need for generating their &#8220;add-user-to-list&#8221; URLs.</p>
<p>So for example, this URL would add a user with the name <strong>Fred</strong> and e-mail <strong>fred@email.com</strong> to our<strong> hotleads</strong> e-mail list:</p>
<blockquote><p>http://www.aweber.com/scripts/addlead.pl?listname=<strong>hotleads</strong>&amp;meta_adtracking=wpreg&amp;name=<strong>Fred</strong>&amp;email=<strong>fred@email.com<br />
</strong>&amp;meta_message=1&amp;redirect=http://www.aweber.com/form/thankyou_vo.html</p></blockquote>
<p>It&#8217;s honestly pretty simple once you break it down. It&#8217;s really just an &#8220;add lead&#8221; URL with some parameters to tell the software who to add to which list.</p>
<p>Getting back to the WordPress registration&#8230;</p>
<h4>Connecting the Dots</h4>
<p>Knowing what we now know about how new leads our added to AWeber, all we need to do is pass along a couple variables (name and e-mail) from our WordPress registration form to generate the add lead URL.</p>
<p>Once we have the proper URL in place, only one problem remains: <strong>How do we &#8220;click&#8221; it?</strong></p>
<p>Meaning that we need some way to have the add lead URL placed in a virtual browser and clicked so that it executes the add lead function. You catch my drift? Just generating the URL does nothing; it needs to be &#8220;clicked.&#8221;</p>
<p>Luckily I&#8217;ve fooled around with web scraping (pulling data from external websites) for <a href="http://tcgscans.com/">TcgScans</a>, so I knew it would be a pretty simple job with <a href="http://php.net/manual/en/function.curl-exec.php">CURL</a>. It basically mimics a user visiting a link (which is exactly what we&#8217;ve got to do here).</p>
<p>I looked back through the ARI code again and realized that this is precisely how it works, but for some reason the code is a lot more complex than I could comprehend. I&#8217;m not exactly sure why it does some of the things it does.</p>
<p>Anyway, I was able to pull out bits and pieces from the ARI code to help build my own functions. The biggest thing it helped with is making sure I was using the right WordPress hooks.</p>
<h4>The Code</h4>
<p>So without any further adieu, here&#8217;s the complete code (which you can plop in your theme&#8217;s functions.php):</p>
<pre>//
// Registration Form
//

// Show extra fields on registration form
add_action( 'register_form', 'show_extra_reg_fields', 1 );

function show_extra_reg_fields() { ?&gt;
	&lt;p&gt;
	&lt;label&gt;First Name&lt;br/&gt;
	&lt;input type="text" name="first_name" id="first_name" class="input" value="&lt;?php echo $_POST['first_name']; ?&gt;" size="25" tabindex="30" /&gt;
	&lt;/label&gt;
	&lt;/p&gt;

	&lt;p&gt;
	&lt;label&gt;Last Name&lt;br/&gt;
	&lt;input type="text" name="last_name" id="last_name" class="input" value="&lt;?php echo $_POST['last_name']; ?&gt;" size="25" tabindex="40" /&gt;
	&lt;/label&gt;
	&lt;/p&gt;
&lt;?php }

// Check if extra fields are filled out correctly
add_filter( 'registration_errors', 'check_fields', 10, 3 );

function check_fields($errors, $login, $email) {

	if ( $_POST['first_name'] == '' &amp;&amp; $_POST['last_name'] == '' ) {
		$errors-&gt;add('empty_realname', "&lt;strong&gt;ERROR&lt;/strong&gt;: Please enter your first and last name");
	}
	elseif ( $_POST['first_name'] == '' ) {
		$errors-&gt;add('empty_realname', "&lt;strong&gt;ERROR&lt;/strong&gt;: Please enter your first name");
	}
	elseif ($_POST['last_name'] == '') {
		$errors-&gt;add('empty_realname', "&lt;strong&gt;ERROR&lt;/strong&gt;: Please enter your last name");
	}

	return $errors;
}

// Update user profile
add_action( 'user_register', 'register_extra_fields' );

function register_extra_fields( $user_id ) {

	$userdata['ID'] = $user_id;
	$userdata['first_name'] = ucwords(strtolower($_POST['first_name']));
	$userdata['last_name'] = ucwords(strtolower($_POST['last_name']));

	wp_update_user($userdata);
}

//
// E-mail list MAGIC
//

// Checkbox to join list
add_action( 'register_form', 'email_opt_in' );

function email_opt_in() { ?&gt;
    &lt;p&gt;
    &lt;label style="font-size:13px;"&gt;
    &lt;input type="checkbox" name="email_opt_in" id="email_opt_in" class="input" checked="checked" value="1" &lt;?php checked( $_POST['email_opt_in'], 1 ); ?&gt; tabindex="99" style="width:12px;padding:0;margin:0 3px 0 0;font-size: 13px;" /&gt;
	Join our famous e-mail list
	&lt;/label&gt;
	&lt;/p&gt;
	&lt;br/&gt;&lt;?php
}

// Add Lead!
add_action( 'user_register', 'join_email_list' );

function join_email_list( $user_id ) {

	//
	// 0. First Check if they Opted In, otherwise kill
	//
	if ( empty($_POST['email_opt_in']) ) return;

	//
	// 1. Get WP Variables
	//
	$email = $_POST['user_email'];
	$firstname = ucwords(strtolower($_POST['first_name']));
	$lastname = ucwords(strtolower($_POST['last_name']));
	$fullname = $firstname . ' ' . $lastname;

	// Encode them for URL
	$email = urlencode( utf8_encode($email) );
	$fullname = urlencode( utf8_encode($fullname) );

	//
	// 2. Define Aweber Variables
	//
	$listname = 'somelist'; // YOUR LIST NAME
	$adtracking = 'wpreg'; // AD TRACKING

	//
	// 3. Build URL
	//
	$url = 'http://www.aweber.com/scripts/addlead.pl?listname=' . $listname . '&amp;meta_adtracking=' . $adtracking . '&amp;name=' . $fullname . '&amp;email=' . $email . '&amp;meta_message=1&amp;redirect=http://www.aweber.com/form/thankyou_vo.html';

	//
	// 4. Run the URL via CURL
	//

    // build the individual requests as above, but do not execute them
    $ch1 = curl_init( $url );

    // Options: http://se2.php.net/manual/en/function.curl-setopt.php
    $options = array(CURLOPT_RETURNTRANSFER =&gt; true,
	                 CURLOPT_USERAGENT =&gt; 'Mozilla/5.0',
	                 CURLOPT_HEADER =&gt; false,
	                 CURLOPT_FOLLOWLOCATION =&gt; true,
	                 CURLOPT_TIMEOUT =&gt; 10,
	                 CURLOPT_FAILONERROR =&gt; true,
	                 CURLOPT_AUTOREFERER =&gt; true,
	                );

	curl_setopt_array( $ch1, $options );

    // build the multi-curl handle, adding both $ch
    $mh = curl_multi_init();
    curl_multi_add_handle($mh, $ch1);

    // execute all queries simultaneously, and continue when all are complete
    $running = null;
    do {
        curl_multi_exec($mh, $running);
    } while ($running);

    // all of our requests are done, we can now access the results
    //$html = curl_multi_getcontent($ch1);

	// close
	curl_multi_remove_handle($mh, $ch1);
	curl_multi_close($mh);

}</pre>
<p>You can also download it <a href="http://pastebin.com/p2QkDHyG">here</a>.</p>
<h4>Confused?</h4>
<p>A couple notes&#8230;</p>
<p><strong>1. First, we add First Name and Last Name fields to the default WordPress registration form. </strong>You don&#8217;t have to do this, but I like to get a user&#8217;s full name since it can be pretty powerful to have that in your system.</p>
<pre>//
// Custom Registration Form
//

// Show extra fields on registration form
add_action( 'register_form', 'show_extra_reg_fields', 1 );

function show_extra_reg_fields() { ?&gt;
	&lt;p&gt;
	&lt;label&gt;First Name&lt;br/&gt;
	&lt;input type="text" name="first_name" id="first_name" class="input" value="&lt;?php echo $_POST['first_name']; ?&gt;" size="25" tabindex="30" /&gt;
	&lt;/label&gt;
	&lt;/p&gt;

	&lt;p&gt;
	&lt;label&gt;Last Name&lt;br/&gt;
	&lt;input type="text" name="last_name" id="last_name" class="input" value="&lt;?php echo $_POST['last_name']; ?&gt;" size="25" tabindex="40" /&gt;
	&lt;/label&gt;
	&lt;/p&gt;
&lt;?php }</pre>
<p>Think of how nice it would be to customize a sales page on your website if you had the prospect&#8217;s full name&#8230; I know you could REALLY grab my attention with a headline like&#8230;</p>
<h4>&#8220;Why Adam Capriola is Failing&#8221;</h4>
<p>Or you could do something as simple as say &#8220;Welcome back, Adam!&#8221; after I log in. Small customizations like that can go a long way. Sure, maybe a couple less people will register for your site because they don&#8217;t want to take 5 extra seconds to type out that info (or maybe they don&#8217;t want to share it), but I think the leverage you gain is well worth a few less leads.</p>
<p><strong>2. The code after the extra fields checks to make sure the user actually entered their first and last name, and then it saves that info to their profile.</strong></p>
<p>Pretty simple:</p>
<pre>// Check if extra fields are filled out correctly
add_filter( 'registration_errors', 'check_fields', 10, 3 );

function check_fields($errors, $login, $email) {

	if ( $_POST['first_name'] == '' &amp;&amp; $_POST['last_name'] == '' ) {
		$errors-&gt;add('empty_realname', "&lt;strong&gt;ERROR&lt;/strong&gt;: Please enter your first and last name");
	}
	elseif ( $_POST['first_name'] == '' ) {
		$errors-&gt;add('empty_realname', "&lt;strong&gt;ERROR&lt;/strong&gt;: Please enter your first name");
	}
	elseif ($_POST['last_name'] == '') {
		$errors-&gt;add('empty_realname', "&lt;strong&gt;ERROR&lt;/strong&gt;: Please enter your last name");
	}

	return $errors;
}

// Update user profile
add_action( 'user_register', 'register_extra_fields' );

function register_extra_fields( $user_id ) {

	$userdata['ID'] = $user_id;
	$userdata['first_name'] = ucwords(strtolower($_POST['first_name']));
	$userdata['last_name'] = ucwords(strtolower($_POST['last_name']));

	wp_update_user($userdata);
}</pre>
<p>If you were saving a custom data field to the user&#8217;s profile, you could need to save it like this:</p>
<p><code>update_usermeta( $user_id, 'CUSTOM_DATA', $_POST['CUSTOM_DATA'] );</code></p>
<p>A little more on that in a minute. Also, I&#8217;ve set up an auto-converter to make their first and last name capitalized via:</p>
<p><code>ucwords(strtolower($_POST['first_name']));</code></p>
<p>You don&#8217;t have to do that, but I put it there just incase the user types their name as &#8220;adam capriola&#8221; or &#8220;ADAM CAPRIOLA&#8221; and we want to make it look more proper.</p>
<p>Of course you may run into a slight issue if they have one of those names like DiCaprio, in which case this code will turn it into Dicaprio, so it&#8217;s totally up to you on this one.</p>
<p><strong>3. Finally we get to the good stuff&#8230; first we insert an opt-in checkbox so the user can decide whether or not they want to subscribe to our e-mail list.</strong> I have it checked by default via <code>checked="checked"</code>, but you don&#8217;t have to do that if you don&#8217;t want. I think it&#8217;s smart to do that though.</p>
<pre>//
// E-mail list MAGIC
//

// Checkbox to join list
add_action( 'register_form', 'email_opt_in' );

function email_opt_in() { ?&gt;
    &lt;p&gt;
    &lt;label style="font-size:13px;"&gt;
    &lt;input type="checkbox" name="email_opt_in" id="email_opt_in" class="input" checked="checked" value="1" &lt;?php checked( $_POST['email_opt_in'], 1 ); ?&gt; tabindex="99" style="width:12px;padding:0;margin:0 3px 0 0;font-size: 13px;" /&gt;
	Join our famous e-mail list
	&lt;/label&gt;
	&lt;/p&gt;
	&lt;br/&gt;&lt;?php
}</pre>
<p>If you want to be really on top of your stuff, you could try and get even more info from the user and adding them to a segmented list. For example, you could have them select their country, and create conditional statement for the next part of code to add them to a specific list.</p>
<p>Or ask for their gender&#8230; favorite food&#8230; stuff like that. Any info you can gather to send them specified e-mails is valuable. Think of how much information Facebook tries to gather and then market back to you. This information can then be saved to the user&#8217;s profile via <code>update_usermeta( $user_id, 'CUSTOM_DATA', $_POST['CUSTOM_DATA'] );</code> which I mentioned earlier.</p>
<p><strong>4. Lastly, we check to make sure the user opted-in to our list, then we build the &#8220;add lead&#8221; URL and &#8220;click&#8221; it with CURL.</strong> I will admit it&#8217;s not the perfect CURL code as I was running multi-CURL for another project and didn&#8217;t feel like changing it back to singular CURL. This shouldn&#8217;t have any effect on performance, but feel free to edit if you want.</p>
<pre>// Add Lead!
add_action( 'user_register', 'join_email_list' );

function join_email_list( $user_id ) {

	//
	// 0. First Check if they Opted In, otherwise kill
	//
	if ( empty($_POST['email_opt_in']) ) return;

	//
	// 1. Get WP Variables
	//
	$email = $_POST['user_email'];
	$firstname = ucwords(strtolower($_POST['first_name']));
	$lastname = ucwords(strtolower($_POST['last_name']));
	$fullname = $firstname . ' ' . $lastname;

	// Encode them for URL
	$email = urlencode( utf8_encode($email) );
	$fullname = urlencode( utf8_encode($fullname) );

	//
	// 2. Define Aweber Variables
	//
	$listname = 'somelist'; // YOUR LIST NAME
	$adtracking = 'wpreg'; // AD TRACKING

	//
	// 3. Build URL
	//
	$url = 'http://www.aweber.com/scripts/addlead.pl?listname=' . $listname . '&amp;meta_adtracking=' . $adtracking . '&amp;name=' . $fullname . '&amp;email=' . $email . '&amp;meta_message=1&amp;redirect=http://www.aweber.com/form/thankyou_vo.html';

	//
	// 4. Run the URL via CURL
	//

    // build the individual requests as above, but do not execute them
    $ch1 = curl_init( $url );

    // Options: http://se2.php.net/manual/en/function.curl-setopt.php
    $options = array(CURLOPT_RETURNTRANSFER =&gt; true,
	                 CURLOPT_USERAGENT =&gt; 'Mozilla/5.0',
	                 CURLOPT_HEADER =&gt; false,
	                 CURLOPT_FOLLOWLOCATION =&gt; true,
	                 CURLOPT_TIMEOUT =&gt; 10,
	                 CURLOPT_FAILONERROR =&gt; true,
	                 CURLOPT_AUTOREFERER =&gt; true,
	                );

	curl_setopt_array( $ch1, $options );

    // build the multi-curl handle, adding both $ch
    $mh = curl_multi_init();
    curl_multi_add_handle($mh, $ch1);

    // execute all queries simultaneously, and continue when all are complete
    $running = null;
    do {
        curl_multi_exec($mh, $running);
    } while ($running);

    // all of our requests are done, we can now access the results
    //$html = curl_multi_getcontent($ch1);

	// close
	curl_multi_remove_handle($mh, $ch1);
	curl_multi_close($mh);

}</pre>
<p>NOTE: Make sure to change <code>$listname</code> and <code>$adtracking</code> to suit your needs.</p>
<p>Again, you could customize this by adding conditionals and multiple lists depending on what kind of information you ask the user during registration.</p>
<h4>Bonus Tip!</h4>
<p>What I would do if you&#8217;re using AWeber is to create a main list, which we&#8217;ll call <strong>mainlist</strong>, and then sublists, which we&#8217;ll call <strong>sublist1</strong> and <strong>sublist2</strong>. You will want to add users to either <strong>sublist1</strong> or <strong>sublist2</strong> depending on whatever conditionals you make, but then I&#8217;d also add them to <strong>mainlist</strong> via AWeber automation tools.</p>
<p>This way you have a &#8220;master list&#8221; with all your leads, but also the targeted lists. You could alternatively just have 1 list and then create segments via AWeber custom fields, but I find it simpler to have separate lists. You gain a little more flexibility with lists and can do some cool things with them.</p>
<h4>Another Bonus Tip!</h4>
<p>You could also probably adapt this to get leads if someone comments on your site. I don&#8217;t know the proper hooks, but I&#8217;m sure it&#8217;s pretty simple to add a &#8220;Join my list!&#8221; checkbox to your commenting form (just like we do for the WordPress registration form here).</p>
<h4>Conclusion</h4>
<p>Anyway, I ain&#8217;t no perfect coder, so let me know if you see any mistakes or have any suggestions. This is pretty powerful stuff and I&#8217;m surprised it isn&#8217;t more well-known or used.</p>
<p>Catch you on the flip,</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://adamcap.com/2011/10/how-to-integrate-aweber-and-wordpress-registration-without-a-plugin/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.447 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-04-23 20:25:48 -->
<!-- Compression = gzip -->
