Facebook
From yon, 2 Months ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 48
  1. add_action( 'wp_ajax_get_referrals', 'get_referrals_callback' );
  2. // add_action( 'wp_ajax_nopriv_get_referrals', 'get_referrals_callback' );  
  3. add_action( 'wp_ajax_nopriv_get_referrals', 'get_referrals_callback' );  
  4. function get_referrals_callback()
  5. {
  6.     global $wpdb;
  7.     $draw = $_POST['draw'];
  8.     $paged = $_POST['draw'];
  9.     $number = $_POST['length']; // Rows display per page
  10.     $offset = $_POST['start'];
  11.     $searchValue = $_POST['search']['value'];
  12.     $row = $_POST['start'];
  13.    
  14.     $current_user = wp_get_current_user();
  15.    
  16.     if($searchValue)
  17.     {
  18.         $current_user_login = $current_user->user_login;
  19.         $user_login = $searchValue;
  20.         // $args = array('search' => $user_login, 'offset' => $offset, 'number' => $number);
  21.         // $users_args = array('search' => $user_login);
  22.         $users = new WP_User_Query( array(
  23.             'search'         =>  esc_attr( $user_login ).'*',
  24.             'search_columns' => array(
  25.                 'user_login'
  26.             ),
  27.             'number' => $number,
  28.             'offset' => $offset
  29.         ) );
  30.         $users = $wpdb->get_results("SELECT users.* FROM ".$wpdb->prefix."users AS users LEFT JOIN ".$wpdb->prefix."usermeta AS umeta ON umeta.user_id = users.ID WHERE umeta.meta_key='referral' AND umeta.meta_value='$current_user_login' AND users.user_login LIKE '$user_login%' LIMIT $offset,$number");
  31.         // print_r($users); die("here");
  32.         // $users =  get_users($users_args);
  33.         $total_users = count($users);
  34.         $referrals = $users;
  35.     } else {
  36.         $user_login = $current_user->user_login;
  37.         $args = array('meta_key' => 'referral', 'meta_value'=> $user_login, 'meta_compare' => '=', 'offset' => $offset, 'number' => $number );
  38.         $users_args = array('meta_key' => 'referral', 'meta_value'=> $user_login, 'meta_compare' => '=');
  39.         $users =  get_users($users_args);
  40.         $total_users = count($users);
  41.         $referrals = get_users( $args );
  42.     }
  43.    
  44.  
  45.    
  46.     $data = array();
  47.     foreach ($referrals as $referral) {
  48.         $api = ms_api();
  49.         $subscribed = $api->get_subscription( $referral->ID );
  50.        
  51.          $data[] = array(
  52.                  "username" => $referral->user_login,
  53.                  "referral" => $current_user->user_login,
  54.                  "membership" => get_the_title($subscribed->membership_id),
  55.                  "startdate" => $subscribed->start_date,
  56.                  "enddate" => $subscribed->expire_date
  57.                  );
  58.        
  59.     }
  60.     $response = array(
  61.           "draw" => intval($draw),
  62.           "iTotalRecords" => $total_users,
  63.           "iTotalDisplayRecords" => $total_users,
  64.           "aaData" => $data,
  65.         );
  66.  
  67.    wp_send_json($response);
  68.    exit;
  69. }