pmpro_report_login_wp_visits

The Paid Memberships Pro pmpro report login wp visits function.

Description

pmpro_report_login_wp_visits(); 

Usage

  1. if ( !function_exists( 'pmpro_report_login_wp_visits' ) ) { 
  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_wp_visits(); 
  7.  

Defined (1)

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

/adminpages/reports/login.php  
  1. function pmpro_report_login_wp_visits() 
  2. //don't track admin 
  3. if(is_admin()) 
  4. return; 
  5.  
  6. //only track logged in users 
  7. if(!is_user_logged_in()) 
  8. return; 
  9.  
  10. //check for cookie 
  11. if(!empty($_COOKIE['pmpro_visit'])) 
  12. return; 
  13.  
  14. $now = current_time('timestamp'); 
  15.  
  16. //set cookie, then track 
  17. setcookie("pmpro_visit", "1", NULL, COOKIEPATH, COOKIE_DOMAIN, false);  
  18.  
  19. global $current_user; 
  20. //track for user 
  21. if(!empty($current_user->ID)) 
  22. {  
  23. $visits = $current_user->pmpro_visits;  
  24. if(empty($visits)) 
  25. $visits = array("last"=>"N/A", "thisdate"=>NULL, "month"=>0, "thismonth"=>NULL, "alltime"=>0); 
  26.  
  27. //track logins for user 
  28. $visits['last'] = date_i18n(get_option("date_format")); 
  29. $visits['alltime']++; 
  30. $thismonth = date_i18n("n", $now); 
  31. if($thismonth == $visits['thismonth']) 
  32. $visits['month']++; 
  33. else 
  34. $visits['month'] = 1; 
  35. $visits['thismonth'] = $thismonth; 
  36.  
  37. //update user data 
  38. update_user_meta($current_user->ID, "pmpro_visits", $visits); 
  39.  
  40. //track for all 
  41. $visits = get_option("pmpro_visits");  
  42. if(empty($visits)) 
  43. $visits = array("today"=>0, "thisdate"=>NULL, "month"=>0, "thismonth"=> NULL, "alltime"=>0); 
  44.  
  45. $visits['alltime']++; 
  46. $thisdate = date_i18n("Y-d-m", $now); 
  47. if($thisdate == $visits['thisdate']) 
  48. $visits['today']++; 
  49. else 
  50. $visits['today'] = 1; 
  51. $visits['thisdate'] = $thisdate; 
  52. if($thismonth == $visits['thismonth']) 
  53. $visits['month']++; 
  54. else 
  55. $visits['month'] = 1; 
  56. $visits['thismonth'] = $thismonth; 
  57.  
  58. update_option("pmpro_visits", $visits);