i need help here.
I have a wordpress web system with referral functions.It is linked to a referral link.

But the problem is, i do not know how to extract the EXACT referral link and duplicate it and put it to sharing buttons. So that it will force the sharing to link the URL referral link instead of main site.

Example :

I have created a user g3.
g3 referral link is www.domain.com/ref=g3
but when i put plugin to share buttons, it only shares www.domain.com, not www.domain.com/ref=g3

In the first place, i do not know where does www.domain.com/ref=g3 is generated.

Here is the PHP code : it is not program by me. It is done by a mean developer who ran away after doing the project half way. Pls help.

function mlmNetworkDetailsPage() {
    global $current_user, $wpdb;
    $user_id = get_current_userID();
    $personalSales = totalMyPersonalSales( $user_id );
    $activePersonalSales = activeUsersOnPersonalSales( $user_id );
    $fivePersonalUsers = myFivePersonalUsers( $user_id );
    $username = $current_user->ID;

    $user_info = get_userdata($current_user->ID);
    $_SESSION['ajax'] = 'ajax_check';

    $add_page_id = get_post_id('mlm_registration_page');
    $sponsor_name = $current_user->user_login;
    $mlm_settings = get_option('wp_mlm_general_settings');
    $affiliateURLold = site_url() . '?page_id=' . $add_page_id . '&sp_name=' . $sponsor_name;
    $affiliateURLnew = site_url() . '/ref/' . $sponsor_name;
    $permalink = get_permalink(empty($_GET['page_id']) ? '' : $_GET['page_id']);
    $postidparamalink = strstr($permalink, 'page_id');
    $affiliateURL = ($postidparamalink) ? $affiliateURLold : $affiliateURLnew;
    $view_memberpage_id = $wpdb->get_var("SELECT `id` FROM `{$wpdb->prefix}posts` WHERE `post_content` LIKE '%mlm-view-child-level-member%' AND `post_type` != 'revision'");
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $spon_name = $wpdb->get_var("SELECT `username` FROM ".MLM_USERS." WHERE `user_id` IN(SELECT `parent_id` FROM ".MLM_USERS." WHERE `user_id` = '".$current_user->ID."')");
    $payment_status = $wpdb->get_var("SELECT `payment_status` FROM ".MLM_USERS." WHERE `user_id` = '".$current_user->ID."'");
    $total_referal = $wpdb->get_var("SELECT COUNT(sponsor_id) FROM  ".MLM_USERS." WHERE sponsor_id ='".$current_user->ID."'");
    $active_member = $wpdb->get_var("SELECT COUNT(*) FROM  ".MLM_USERS." WHERE sponsor_id='".$current_user->ID."' AND payment_status='1'");
        $non_active_member = $wpdb->get_var("SELECT COUNT(*) FROM  ".MLM_USERS." WHERE sponsor_id='".$current_user->ID."' AND payment_status='0'");
        $total_downline = totalDownlineMembers( $current_user->ID );
        $total_paiddownline = totalDownlinepaidMembers( $current_user->ID );
        //$total_unpaiddownline = totalDownlineunpaidMembers( $current_user->ID );
        $total_unpaiddownline = $total_downline - $total_paiddownline;
    $(document).ready(function() {

    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
     $(document).on("click", '.whatsapp', function() {
            if( isMobile.any() ) {

                var text = $(this).attr("data-text");
                var url = $(this).attr("data-link");
                var message = encodeURIComponent(text) + " - " + encodeURIComponent(url);
                var whatsapp_url = "whatsapp://send?text=" + message;
                window.location.href = whatsapp_url;
            } else {
                alert("Please share this article in mobile device");

    if( $payment_status == 1 ) {
        $totalcommission = $wpdb->get_var("SELECT SUM(amount) FROM `{$wpdb->prefix}ume_commission` WHERE `parent_id` = '".$current_user->ID."' AND `eligibility` = '1' AND `payout_id` != '0'");
    } else {
        $totalcommission = $wpdb->get_var("SELECT SUM(amount) FROM `{$wpdb->prefix}ume_commission` WHERE `parent_id` = '".$current_user->ID."' AND `eligibility` = '0'");
    $closing_bal = $wpdb->get_var("SELECT `closing_bal` FROM ".MLM_TRANSACTION." WHERE `id` = (SELECT max(`id`) FROM ".MLM_TRANSACTION." WHERE `user_id` = '".$current_user->ID."')");

    <div class="affiliate_url">
        <h3 style="color: #ffffff !important;"><i>Affiliate URL:</i> <?php echo $affiliateURL; ?></h3>
        <a href="whatsapp://send?text=<?php echo $affiliateURL; ?>" class="whatsapp w3_whatsapp_btn w3_whatsapp_btn_medium"><i class="fa fa-whatsapp" aria-hidden="true"></i> Share on Whatsapp</a>

        <a href="http://www.facebook.com/sharer/sharer.php?u=<?php echo $affiliateURL; ?>&t=TITLE_HERE" target="_blank" class="share-popup whatsapp w3_whatsapp_btn w3_fb_btn_medium"><i class="fa fa-facebook" aria-hidden="true"></i> Share on Facebook</a>
<a href="http://www.twitter.com/intent/tweet?url=URL_HERE&via=TWITTER_HANDLE_HERE&text=TITLE_HERE" target="_blank" class="share-popup whatsapp w3_whatsapp_btn w3_twitter_btn_medium"><i class="fa fa-twitter" aria-hidden="true"></i> Share on Twitter</a>
<a href="http://plus.google.com/share?url=<?php echo $affiliateURL; ?>" target="_blank" class="share-popup whatsapp w3_whatsapp_btn w3_google_btn_medium"><i class="fa fa-plus" aria-hidden="true"></i> Share on Googleplus</a>

<script type="text/javascript">
    var window_size = "width=585,height=511";
    var url = this.href;
    var domain = url.split("/")[2];
    switch(domain) {
        case "www.facebook.com":
            window_size = "width=585,height=368";
        case "www.twitter.com":
            window_size = "width=585,height=261";
        case "plus.google.com":
            window_size = "width=517,height=511";
    window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' + window_size);
    return false;

Read more here: how to extract referral link from php to wordpress?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: