pmpro_report_login_page

The Paid Memberships Pro pmpro report login page function.

Description

pmpro_report_login_page(); 

Usage

  1. if ( !function_exists( 'pmpro_report_login_page' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/adminpages/reports/login.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = pmpro_report_login_page(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/adminpages/reports/login.php  
  1. function pmpro_report_login_page() 
  2. global $wpdb; 
  3. $now = current_time('timestamp'); 
  4.  
  5. //vars 
  6. if(!empty($_REQUEST['s'])) 
  7. $s = $_REQUEST['s']; 
  8. else 
  9. $s = ""; 
  10.  
  11. if(!empty($_REQUEST['l'])) 
  12. $l = intval($_REQUEST['l']); 
  13. else 
  14. $l = ""; 
  15. ?> 
  16. <form id="posts-filter" method="get" action="">  
  17. <h1> 
  18. <?php _e('Visits, Views, and Logins Report', 'paid-memberships-pro' );?> 
  19. </h1>  
  20. <ul class="subsubsub"> 
  21. <li>  
  22. <?php _e('Show', 'paid-memberships-pro' )?> <select name="l" onchange="jQuery('#posts-filter').submit();"> 
  23. <option value="" <?php if(!$l) { ?>selected="selected"<?php } ?>><?php _e('All Users', 'paid-memberships-pro' )?></option> 
  24. <option value="all" <?php if($l == "all") { ?>selected="selected"<?php } ?>><?php _e('All Levels', 'paid-memberships-pro' )?></option> 
  25. <?php 
  26. $levels = $wpdb->get_results("SELECT id, name FROM $wpdb->pmpro_membership_levelsORDERBY name"); 
  27. foreach($levels as $level) 
  28. ?> 
  29. <option value="<?php echo $level->id?>" <?php if($l == $level->id) { ?>selected="selected"<?php } ?>><?php echo $level->name?></option> 
  30. <?php 
  31. ?> 
  32. </select>  
  33. </li> 
  34. </ul> 
  35. <p class="search-box"> 
  36. <label class="hidden" for="post-search-input"><?php _e('Search', 'paid-memberships-pro' )?> <?php if(empty($l)) echo "Users"; else echo "Members";?>:</label> 
  37. <input type="hidden" name="page" value="pmpro-reports" />  
  38. <input type="hidden" name="report" value="login" />  
  39. <input id="post-search-input" type="text" value="<?php echo esc_attr($s)?>" name="s"/> 
  40. <input class="button" type="submit" value="Search Members"/> 
  41. </p> 
  42. <?php  
  43. //some vars for the search  
  44. if(isset($_REQUEST['pn'])) 
  45. $pn = intval($_REQUEST['pn']); 
  46. else 
  47. $pn = 1; 
  48.  
  49. if(isset($_REQUEST['limit'])) 
  50. $limit = intval($_REQUEST['limit']); 
  51. else 
  52. $limit = 15; 
  53.  
  54. $end = $pn * $limit; 
  55. $start = $end - $limit;  
  56.  
  57. if($s) 
  58. $sqlQuery = "SELECT SQL_CALC_FOUND_ROWS u.ID, u.user_login, u.user_email, UNIX_TIMESTAMP(u.user_registered) as joindate, mu.membership_id, mu.initial_payment, mu.billing_amount, mu.cycle_period, mu.cycle_number, mu.billing_limit, mu.trial_amount, mu.trial_limit, UNIX_TIMESTAMP(mu.startdate) as startdate, UNIX_TIMESTAMP(mu.enddate) as enddate, m.name as membership FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id AND mu.status = 'active' LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id WHERE (u.user_login LIKE '%" . esc_sql($s) . "%' OR u.user_email LIKE '%" . esc_sql($s) . "%' OR um.meta_value LIKE '%" . esc_sql($s) . "%') "; 
  59.  
  60. if($l == "all") 
  61. $sqlQuery .= " AND mu.status = 'active' AND mu.membership_id > 0 "; 
  62. elseif($l) 
  63. $sqlQuery .= " AND mu.membership_id = '" . $l . "' ";  
  64.  
  65. $sqlQuery .= "GROUP BY u.IDORDERBY user_registered DESC LIMIT $start, $limit"; 
  66. else 
  67. $sqlQuery = "SELECT SQL_CALC_FOUND_ROWS u.ID, u.user_login, u.user_email, UNIX_TIMESTAMP(u.user_registered) as joindate, mu.membership_id, mu.initial_payment, mu.billing_amount, mu.cycle_period, mu.cycle_number, mu.billing_limit, mu.trial_amount, mu.trial_limit, UNIX_TIMESTAMP(mu.startdate) as startdate, UNIX_TIMESTAMP(mu.enddate) as enddate, m.name as membership FROM $wpdb->users u LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id AND mu.status = 'active' LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id"; 
  68. $sqlQuery .= " WHERE 1=1 "; 
  69.  
  70. if($l == "all") 
  71. $sqlQuery .= " AND mu.membership_id > 0 AND mu.status = 'active' "; 
  72. elseif($l) 
  73. $sqlQuery .= " AND mu.membership_id = '" . $l . "' "; 
  74. $sqlQuery .= "GROUP BY u.IDORDERBY user_registered DESC LIMIT $start, $limit"; 
  75.  
  76. $sqlQuery = apply_filters("pmpro_members_list_sql", $sqlQuery); 
  77.  
  78. $theusers = $wpdb->get_results($sqlQuery); 
  79. $totalrows = $wpdb->get_var("SELECT FOUND_ROWS() as found_rows"); 
  80.  
  81. if($theusers) 
  82. ?> 
  83. <p class="clear"><?php echo strval($totalrows)?> <?php if(empty($l)) echo "users"; else echo "members";?> found.  
  84. <?php  
  85. }  
  86. ?> 
  87. <table class="widefat"> 
  88. <thead> 
  89. <tr class="thead"> 
  90. <th><?php _e('ID', 'paid-memberships-pro' )?></th> 
  91. <th><?php _e('User', 'paid-memberships-pro' )?></th>  
  92. <th><?php _e('Name', 'paid-memberships-pro' )?></th> 
  93. <th><?php _e('Membership', 'paid-memberships-pro' )?></th>  
  94. <th><?php _e('Joined', 'paid-memberships-pro' )?></th> 
  95. <th><?php _e('Expires', 'paid-memberships-pro' )?></th> 
  96. <th><?php _e('Last Visit', 'paid-memberships-pro' )?></th> 
  97. <th><?php _e('Visits This Month', 'paid-memberships-pro' )?></th> 
  98. <th><?php _e('Total Visits', 'paid-memberships-pro' )?></th> 
  99. <th><?php _e('Views This Month', 'paid-memberships-pro' )?></th> 
  100. <th><?php _e('Total Views', 'paid-memberships-pro' )?></th> 
  101. <th><?php _e('Last Login', 'paid-memberships-pro' )?></th> 
  102. <th><?php _e('Logins This Month', 'paid-memberships-pro' )?></th> 
  103. <th><?php _e('Total Logins', 'paid-memberships-pro' )?></th>  
  104. </tr> 
  105. </thead> 
  106. <tbody id="users" class="list:user user-list">  
  107. <?php  
  108. $count = 0;  
  109. foreach($theusers as $auser) 
  110. //get meta  
  111. $theuser = get_userdata($auser->ID); 
  112. $visits = get_user_meta($auser->ID, "pmpro_visits", true); 
  113. $views = get_user_meta($auser->ID, "pmpro_views", true); 
  114. $logins = get_user_meta($auser->ID, "pmpro_logins", true); 
  115. if(empty($logins)) 
  116. $logins = array("last"=>"N/A", "month"=>"N/A", "alltime"=>"N/A"); 
  117. ?> 
  118. <tr <?php if($count++ % 2 == 0) { ?>class="alternate"<?php } ?>> 
  119. <td><?php echo $theuser->ID?></td> 
  120. <td> 
  121. <?php echo get_avatar($theuser->ID, 32)?> 
  122. <strong> 
  123. <?php 
  124. $userlink = '<a href="user-edit.php?user_id=' . $theuser->ID . '">' . $theuser->user_login . '</a>'; 
  125. $userlink = apply_filters("pmpro_members_list_user_link", $userlink, $theuser); 
  126. echo $userlink; 
  127. ?>  
  128. </strong> 
  129. </td>  
  130. <td> 
  131. <?php echo $theuser->display_name;?> 
  132. </td> 
  133. <td><?php echo $auser->membership?></td>  
  134. <td><?php echo date_i18n("m/d/Y", strtotime($theuser->user_registered, current_time("timestamp")))?></td> 
  135. <td> 
  136. <?php  
  137. if($auser->enddate)  
  138. echo date_i18n(get_option('date_format'), $auser->enddate); 
  139. else 
  140. echo "Never"; 
  141. ?> 
  142. </td> 
  143. <td><?php if(!empty($visits['last'])) echo $visits['last'];?></td> 
  144. <td><?php if(!empty($visits['month']) && pmpro_isDateThisMonth($visits['last'])) echo $visits['month'];?></td> 
  145. <td><?php if(!empty($visits['alltime'])) echo $visits['alltime'];?></td>  
  146. <td><?php if(!empty($views['month']) && pmpro_isDateThisMonth($views['last'])) echo $views['month'];?></td> 
  147. <td><?php if(!empty($views['alltime'])) echo $views['alltime'];?></td> 
  148. <td><?php if(!empty($logins['last'])) echo $logins['last'];?></td> 
  149. <td><?php if(!empty($logins['month']) && pmpro_isDateThisMonth($logins['last'])) echo $logins['month'];?></td> 
  150. <td><?php if(!empty($logins['alltime'])) echo $logins['alltime'];?></td> 
  151. </tr> 
  152. <?php 
  153.  
  154. if(!$theusers) 
  155. ?> 
  156. <tr> 
  157. <td colspan="9"><p><?php _e('No members found.', 'paid-memberships-pro' )?> <?php if($l) { ?><a href="?page=pmpro-memberslist&s=<?php echo esc_attr($s)?>"><?php _e('Search all levels', 'paid-memberships-pro' )?></a>.<?php } ?></p></td> 
  158. </tr> 
  159. <?php 
  160. ?>  
  161. </tbody> 
  162. </table> 
  163. </form> 
  164.  
  165. <?php 
  166. echo pmpro_getPaginationString($pn, $totalrows, $limit, 1, get_admin_url(NULL, "/admin.php?page=pmpro-reports&report=login&s=" . urlencode($s)), "&l=$l&limit=$limit&pn="); 
  167. ?> 
  168. <?php