i am trying to make a little referral sort of system for my site. so for that i settuped an extra parameter in the registeration url as :


and one is adding ip address while registeration, at first i thought it would be a simple form in wp-login.php but i just found out its all based on filters etc.. very complicated stuff.

I did setuped two extra fields in the wp_user table. called 'reg_ip' and 'referral' ..

now i need to understand how to add these two things in wp-login.php so they will be inserted in teh database while registeration.

Help is really really appreciated :) cheers Ayaz


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']); ?>" />

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

| improve this answer | |
  • 1
    Do you really write user generated data unescaped into the table and the markup? Dangerous! – fuxia Mar 5 '11 at 1:21
  • 2
    @Ayaz Malik See codex.wordpress.org/Data_Validation – fuxia Mar 5 '11 at 13:49
  • 1
    @Ayaz Malik I’d rather use $wpdb->prepare() for DB inserts and esc_* for output. – fuxia Mar 5 '11 at 14:06
  • 1
    @toscho: add_user_meta() uses $wpdb->prepare() implicitly (apart from the fact that the values get serialized), so if you recommend using $wpdb->prepare() in this context without mentioning that, it may get a bit confusing, don't you think? – wyrfel Mar 5 '11 at 17:21
  • 1
    @wyrfel You’re right. prepare() is called in add_metadata(). – fuxia Mar 5 '11 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.