//
// Registration Form
//
// Show extra fields on registration form
add_action( 'register_form', 'show_extra_reg_fields', 1 );
function show_extra_reg_fields() { ?>
<p>
<label>First Name<br/>
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo $_POST['first_name']; ?>" size="25" tabindex="30" />
</label>
</p>
<p>
<label>Last Name<br/>
<input type="text" name="last_name" id="last_name" class="input" value="<?php echo $_POST['last_name']; ?>" size="25" tabindex="40" />
</label>
</p>
<?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'] == '' && $_POST['last_name'] == '' ) {
$errors->add('empty_realname', "<strong>ERROR</strong>: Please enter your first and last name");
}
elseif ( $_POST['first_name'] == '' ) {
$errors->add('empty_realname', "<strong>ERROR</strong>: Please enter your first name");
}
elseif ($_POST['last_name'] == '') {
$errors->add('empty_realname', "<strong>ERROR</strong>: 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() { ?>
<p>
<label style="font-size:13px;">
<input type="checkbox" name="email_opt_in" id="email_opt_in" class="input" checked="checked" value="1" <?php checked( $_POST['email_opt_in'], 1 ); ?> tabindex="99" style="width:12px;padding:0;margin:0 3px 0 0;font-size: 13px;" />
Join our famous e-mail list
</label>
</p>
<br/><?php
}
// Join to e-mail list
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 . '&meta_adtracking=' . $adtracking . '&name=' . $fullname . '&email=' . $email . '&meta_message=1&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 => true,
CURLOPT_USERAGENT => 'Mozilla/5.0',
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_FAILONERROR => true,
CURLOPT_AUTOREFERER => 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);
}