Created
June 3, 2014 17:55
-
-
Save trepmal/9d27995a6ea5af0749a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//track views | |
function pmpro_report_login_wp_views() | |
{ | |
//don't track admin | |
if(is_admin()) | |
return; | |
global $current_user; | |
//track for user | |
if(!empty($current_user->ID)) | |
{ | |
$views = $current_user->pmpro_views; | |
if(empty($views)) | |
$views = array("last"=>"N/A", "month"=>0, "alltime"=>0); | |
//track logins for user | |
$views['last'] = date(get_option("date_format")); | |
$views['alltime']++; | |
$thismonth = date("n"); | |
if(isset($views['thismonth']) && $thismonth == $views['thismonth']) | |
$views['month']++; | |
else | |
{ | |
$views['month'] = 1; | |
$views['thismonth'] = $thismonth; | |
} | |
//update user data | |
update_user_meta($current_user->ID, "pmpro_views", $views); | |
} | |
//track for all | |
$views = get_option("pmpro_views"); | |
if(empty($views)) | |
$views = array("today"=>0, "thisdate"=> NULL, "month"=>0, "thismonth"=> NULL, "alltime"=>0); | |
$views['alltime']++; | |
$thisdate = date("Y-d-m"); | |
if($thisdate == $views['thisdate']) | |
$views['today']++; | |
else | |
{ | |
$views['today'] = 1; | |
$views['thisdate'] = $thisdate; | |
} | |
$thismonth = date("n"); | |
if(isset($views['thismonth']) && $thismonth == $views['thismonth']) | |
$views['month']++; | |
else | |
{ | |
$views['month'] = 1; | |
$views['thismonth'] = $thismonth; | |
} | |
update_option("pmpro_views", $views); | |
} | |
add_action("wp", "pmpro_report_login_wp_views"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment