Adding extra info via GET while registeration in wordpress

I’ve recently written an affiliate plugin where i had to do pretty much the same stuff. Here’s a chopup of the relevant parts:

To process the extra info you get from the registration form:

add_action('user_register', 'my_handle_signup', 10, 2);

function my_handle_signup($user_id, $data = null) {
    $reg_ip = $_REQUEST['reg_ip'];
    $referrer = $_REQUEST['referrer'];
    if (isset($reg_ip) && isset($referrer)) {
        add_user_meta($user_id, 'my_referrer', $referrer);
        add_user_meta($user_id, 'my_reg_ip', $reg_ip);
    }
}

And to add fields to the signup form:

add_action('register_form', 'my_add_signup_fields');

function my_add_signup_fields() {
    if (!empty($_GET['register_me'])) {
        ?>
        <input type="hidden" name="reg_ip" value="<?php echo esc_attr($_SERVER['REMOTE_ADDR']); ?>" />
        <input type="hidden" name="referrer" value="<?php echo esc_attr($_GET['register_me']); ?>" />
        <?php
    }
}

For my solution, i’m actually setting a cookie and then retrieving that on the registration form.

Leave a Comment