title: how to extract referral link from php to wordpress?
body: <p>i need help here.
  I have a wordpress web system with referral functions.It is linked to a referral link.</p>
  
  <p>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.</p>
  
  <p>Example :</p>
  
  <p>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</p>
  
  <p>In the first place, i do not know where does www.domain.com/ref=g3 is generated.</p>
  
  <p>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.</p>
  
  <pre><code>&lt;?php
  function mlmNetworkDetailsPage() {
      global $current_user, $wpdb;
      $user_id = get_current_userID();
      $personalSales = totalMyPersonalSales( $user_id );
      $activePersonalSales = activeUsersOnPersonalSales( $user_id );
      $fivePersonalUsers = myFivePersonalUsers( $user_id );
      wp_get_current_user();
      $username = $current_user-&gt;ID;
  
      $user_info = get_userdata($current_user-&gt;ID);
      $_SESSION['ajax'] = 'ajax_check';
  
      $add_page_id = get_post_id('mlm_registration_page');
      $sponsor_name = $current_user-&gt;user_login;
      $mlm_settings = get_option('wp_mlm_general_settings');
      $affiliateURLold = site_url() . '?page_id=' . $add_page_id . '&amp;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-&gt;get_var("SELECT `id` FROM `{$wpdb-&gt;prefix}posts` WHERE `post_content` LIKE '%mlm-view-child-level-member%' AND `post_type` != 'revision'");
      $mlm_general_settings = get_option('wp_mlm_general_settings');
      $mlm_no_of_level=$mlm_general_settings['mlm-level'];
      $spon_name = $wpdb-&gt;get_var("SELECT `username` FROM ".MLM_USERS." WHERE `user_id` IN(SELECT `parent_id` FROM ".MLM_USERS." WHERE `user_id` = '".$current_user-&gt;ID."')");
      $payment_status = $wpdb-&gt;get_var("SELECT `payment_status` FROM ".MLM_USERS." WHERE `user_id` = '".$current_user-&gt;ID."'");
      $total_referal = $wpdb-&gt;get_var("SELECT COUNT(sponsor_id) FROM  ".MLM_USERS." WHERE sponsor_id ='".$current_user-&gt;ID."'");
      $active_member = $wpdb-&gt;get_var("SELECT COUNT(*) FROM  ".MLM_USERS." WHERE sponsor_id='".$current_user-&gt;ID."' AND payment_status='1'");
          $non_active_member = $wpdb-&gt;get_var("SELECT COUNT(*) FROM  ".MLM_USERS." WHERE sponsor_id='".$current_user-&gt;ID."' AND payment_status='0'");
          $total_downline = totalDownlineMembers( $current_user-&gt;ID );
          $total_paiddownline = totalDownlinepaidMembers( $current_user-&gt;ID );
          //$total_unpaiddownline = totalDownlineunpaidMembers( $current_user-&gt;ID );
          $total_unpaiddownline = $total_downline - $total_paiddownline;
      ?&gt;
      &lt;script&gt;
      $(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;
      //console.log(whatsapp_url);
                  window.location.href = whatsapp_url;
              } else {
                  alert("Please share this article in mobile device");
              }
  
          });
      });
      &lt;/script&gt;
      &lt;?php   
      if( $payment_status == 1 ) {
          $totalcommission = $wpdb-&gt;get_var("SELECT SUM(amount) FROM `{$wpdb-&gt;prefix}ume_commission` WHERE `parent_id` = '".$current_user-&gt;ID."' AND `eligibility` = '1' AND `payout_id` != '0'");
      } else {
          $totalcommission = $wpdb-&gt;get_var("SELECT SUM(amount) FROM `{$wpdb-&gt;prefix}ume_commission` WHERE `parent_id` = '".$current_user-&gt;ID."' AND `eligibility` = '0'");
      }
      $closing_bal = $wpdb-&gt;get_var("SELECT `closing_bal` FROM ".MLM_TRANSACTION." WHERE `id` = (SELECT max(`id`) FROM ".MLM_TRANSACTION." WHERE `user_id` = '".$current_user-&gt;ID."')");
      ?&gt;
  
      &lt;div class="affiliate_url"&gt;
          &lt;h3 style="color: #ffffff !important;"&gt;&lt;i&gt;Affiliate URL:&lt;/i&gt; &lt;?php echo $affiliateURL; ?&gt;&lt;/h3&gt;
          &lt;a href="whatsapp://send?text=&lt;?php echo $affiliateURL; ?&gt;" class="whatsapp w3_whatsapp_btn w3_whatsapp_btn_medium"&gt;&lt;i class="fa fa-whatsapp" aria-hidden="true"&gt;&lt;/i&gt; Share on Whatsapp&lt;/a&gt;
  
          &lt;a href="http://www.facebook.com/sharer/sharer.php?u=&lt;?php echo $affiliateURL; ?&gt;&amp;t=TITLE_HERE" target="_blank" class="share-popup whatsapp w3_whatsapp_btn w3_fb_btn_medium"&gt;&lt;i class="fa fa-facebook" aria-hidden="true"&gt;&lt;/i&gt; Share on Facebook&lt;/a&gt;
  &lt;a href="http://www.twitter.com/intent/tweet?url=URL_HERE&amp;via=TWITTER_HANDLE_HERE&amp;text=TITLE_HERE" target="_blank" class="share-popup whatsapp w3_whatsapp_btn w3_twitter_btn_medium"&gt;&lt;i class="fa fa-twitter" aria-hidden="true"&gt;&lt;/i&gt; Share on Twitter&lt;/a&gt;
  &lt;a href="http://plus.google.com/share?url=&lt;?php echo $affiliateURL; ?&gt;" target="_blank" class="share-popup whatsapp w3_whatsapp_btn w3_google_btn_medium"&gt;&lt;i class="fa fa-plus" aria-hidden="true"&gt;&lt;/i&gt; Share on Googleplus&lt;/a&gt;
      &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  $(".share-popup").click(function(){
      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";
              break;
          case "www.twitter.com":
              window_size = "width=585,height=261";
              break;
          case "plus.google.com":
              window_size = "width=517,height=511";
              break;
      }
      window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' + window_size);
      return false;
  });
  </code></pre>