WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
Do you really write user generated data unescaped into the table and the markup? Dangerous! – toscho Mar 5 '11 at 1:21
@Ayaz Malik See codex.wordpress.org/Data_Validation – toscho Mar 5 '11 at 13:49
@Ayaz Malik I’d rather use $wpdb->prepare() for DB inserts and esc_* for output. – toscho Mar 5 '11 at 14:06
@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
@wyrfel You’re right. prepare() is called in add_metadata(). – toscho Mar 5 '11 at 17:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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