Guest User

Backend

a guest
Nov 4th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. <?php
  2. add_action("wp_ajax_get_json_users", "get_json_users");
  3. add_action("wp_ajax_nopriv_get_json_users", "get_json_users");
  4.  
  5.  
  6.  
  7. function get_json_users(){
  8.  
  9. $count = count_users();
  10. $totalUsers = $count['avail_roles']['pmpro_role_1'] + $count['avail_roles']['pmpro_role_2'] + $count['avail_roles']['pmpro_role_3'];
  11.  
  12. $orderVar = $_GET['order'];
  13.  
  14. switch ($orderVar[0]['column']) {
  15. case 0:
  16. $orderCol = 'last_name';
  17. break;
  18. case 1:
  19. $orderCol = 'last_name';
  20. break;
  21. case 2:
  22. $orderCol = 'qb_style';
  23. break;
  24. case 3:
  25. $orderCol = 'class_of';
  26. break;
  27. case 4:
  28. $orderCol = 'height_feet';
  29. break;
  30. case 5:
  31. $orderCol = 'weight';
  32. break;
  33. case 6:
  34. $orderCol = 'high_school';
  35. break;
  36. case 7:
  37. $orderCol = 'hometown'. ', '.'hometown_state';
  38. break;
  39. case 8:
  40. $orderCol = 'star_rating';
  41. break;
  42. case 9:
  43. $orderCol = 'player_score';
  44. break;
  45. default:
  46. $orderCol = 'last_name';
  47. break;
  48. }
  49.  
  50.  
  51.  
  52. $args = array (
  53. //Get Premium Users
  54. 'orderby' => 'meta_value',
  55. 'meta_key' => $orderCol,
  56. 'order' => strtoupper($orderVar[0]['dir']),
  57. 'number' => $_GET['length'],
  58. 'offset' => $_GET['start']
  59. );
  60.  
  61. // The User Query
  62. $user_query = new WP_User_Query( $args );
  63.  
  64. $players = array();
  65. $i=0;
  66. foreach ($user_query->results as $player) {
  67. $home = home_url().'/user-profile/';
  68. $with_query = add_query_arg('userid', $player->ID, $home);
  69. $player_name = $player->first_name . ' ' . $player->last_name;
  70.  
  71. if(!$player->image){
  72. update_user_meta($user->ID, 'image', get_template_directory_uri().'/assets/img/generic.png');
  73. }
  74.  
  75. if(!$player->star_rating){
  76. $player_stars = 'N/A';
  77. }
  78. else{
  79. $player_star_rating = $player->star_rating;
  80. if($player_star_rating <= 5 && $player_star_rating > 4){
  81. $player_stars = '<i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i>';
  82. }
  83. elseif($player_star_rating <= 4 && $player_star_rating > 3){
  84. $player_stars = '<i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i>';
  85. }
  86. elseif($player_star_rating <= 3 && $player_star_rating > 2){
  87. $player_stars = '<i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i>';
  88. }
  89. elseif($player_star_rating <= 2 && $player_star_rating > 1){
  90. $player_stars = '<i class="fa fa-star text-success"></i><i class="fa fa-star text-success"></i>';
  91. }
  92. elseif($player_star_rating <= 1 && $player_star_rating > 0){
  93. $player_stars = '<i class="fa fa-star text-success"></i>';
  94. }
  95. }
  96. if(!$player->player_score){
  97. $player_score = 'N/A';
  98. }
  99. else{
  100. $player_score = $player->player_score;
  101. }
  102. if($player->first_name != '' && $player->first_name != NULL){
  103. $players[] = array(
  104. '<a href="'.$with_query.'">'.$player_name.'</a>',
  105. '<a href="'.$player->image.'" rel="lightbox" title="'.$player_name.'"></a><img src="'.$player->image.'" alt="'.$player->last_name.' Quarterback Profile" height="75" width="75" class="img-thumbnail">',
  106. $player->qb_style,
  107. $player->class_of,
  108. $player->height_feet.'&#39; '.$player->height_inches.'"',
  109. $player->weight,
  110. $player->high_school,
  111. $player->hometown.' , '.$player->hometown_state,
  112. $player_stars,
  113. $player_score
  114. );
  115. }
  116. }
  117.  
  118.  
  119. //print_r($players);
  120. $output['recordsTotal'] = $totalUsers;
  121. $output['recordsFiltered'] = $totalUsers;
  122. $output['data'] = $players;
  123.  
  124. wp_send_json( $output );
  125. exit();
  126. //echo json_encode($output);
  127.  
  128. }
  129. ?>
Advertisement
Add Comment
Please, Sign In to add comment