Title: Referral Link/Invite Code
Last modified: May 17, 2019

---

# Referral Link/Invite Code

 *  [octix](https://wordpress.org/support/users/octix/)
 * (@octix)
 * [7 years ago](https://wordpress.org/support/topic/referral-link-invite-code/)
 * Hello,
    I am wondering if it would be possible to generate a ‘referral link’,
   or ‘invite code’ for each user that registers. This way, whenever they invite
   a friend, they and their friend get a new ‘premium’ role. Thanks heaps.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Alex Human](https://wordpress.org/support/users/alexterrenas/)
 * (@alexterrenas)
 * [7 years ago](https://wordpress.org/support/topic/referral-link-invite-code/#post-11547404)
 * I did this by adding a hidden ref_id field. Users can now register on another
   user’s profile page, and ref_id will show who invited whom.
 * The page that is specified as a profile becomes a referral link. In this case,
   the profile form may not be on this page, which allows you to create any content
   as the site of the inviting user.
 * And for the profile to have a separate page with a separate form.
 *  Thread Starter [octix](https://wordpress.org/support/users/octix/)
 * (@octix)
 * [7 years ago](https://wordpress.org/support/topic/referral-link-invite-code/#post-11547434)
 * Hey, could you go into some more detail on this? It sounds awesome!
 *  [Alex Human](https://wordpress.org/support/users/alexterrenas/)
 * (@alexterrenas)
 * [7 years ago](https://wordpress.org/support/topic/referral-link-invite-code/#post-11547466)
 * It works for me so:
 * 1. Create a field in the registration form ref_id
    2. I place the shortcode of
   the form on the page that is listed as the profile page. 3. I got the site.loc/
   user/userlogin 4. Create a php file such as refsite.php and its code
 * PHP
 *     ```
       <?php
       // absolute URI in multisite aware environment
       $uParts = parse_url( home_url() );
       $url = "{$uParts['scheme']}://{$uParts['host']}" . add_query_arg( NULL, NULL );
       /*
       $url = $_SERVER['REQUEST_URI']; // получаем логин для сборки без multisite
       */
       $uParts=explode('/', $url);
       $login = $uParts[4];
   
       // get user id by login
   
       global $wpdb;
       $query = "SELECT * FROM wp_usermeta where meta_key = 'nickname' and meta_value = '{$login}'";
       $sponsor = $wpdb->get_row( $query );	
       $sponsorID = $sponsor->user_id;
       if(!$sponsorID){
       	$sponsorID = 1;
       }
       // Take out the field user
   
       $fields = array('first_name', 'last_name', 'city_user', 'country', 'mobile_number', 'skype' ,);
       $user_fields = array();
       for($i=0; $i<count($fields); $i++){
       	$query = $wpdb->get_row( "SELECT * FROM wp_usermeta where meta_key = '{$fields[$i]}' and user_id = '{$sponsorID}'");	
       	$user_fields[$fields[$i]] = $query->meta_value;
       }
       $user_id = get_current_user_id();
       ?>
       ```
   
 * JS
 *     ```
       <script type="text/javascript">
   
       jq = jQuery.noConflict();
       jq(document).ready(function(){
       	jq('.um-field-ref_id input').val('<?php echo $sponsorID; ?>');
       	jq('.um-field-ref_id input').attr('readonly','readonly');
       }
       ```
   
 * 5. I connect this plugin in php profile page template
    `<?php require_once(__DIR__.'/
   php/lp.php'); ?>` 6. Now in the field ref_id substitutes the id of the owner 
   of the profile. 7. After registration, the user in the submitted field is specified
   and our ref_id 8. I see on the page of all who registered through my page (Here’s
   another code but I’ll show you what it looks like) [https://drive.google.com/file/d/1_C4nbpncYIfGUv8CezffJdddts1hpX3J/view?usp=sharing](https://drive.google.com/file/d/1_C4nbpncYIfGUv8CezffJdddts1hpX3J/view?usp=sharing)
 *  [Alex Human](https://wordpress.org/support/users/alexterrenas/)
 * (@alexterrenas)
 * [7 years ago](https://wordpress.org/support/topic/referral-link-invite-code/#post-11547475)
 * If you want more detail send me an email alexgminfo.dev @ gmail.com

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Referral Link/Invite Code’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Alex Human](https://wordpress.org/support/users/alexterrenas/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/referral-link-invite-code/#post-11547475)
 * Status: not resolved