Last active
February 20, 2016 05:35
-
-
Save RevConcept/bf617b9447877d16370f to your computer and use it in GitHub Desktop.
Page View Cookie
This file contains hidden or 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
/* =========================================== | |
Count LC Page Views | |
=============================================*/ | |
function non_member_view_count() { | |
if ( !is_user_logged_in() ) { | |
if ( !isset($_COOKIE['lc_page_view']) ) { | |
$value = 1; | |
setcookie('lc_page_view', $value, time()+3600*24*100, '/', 'cardiacmri.com', false); | |
} else { | |
$value = $_COOKIE['lc_page_view'] + 1; | |
setcookie('lc_page_view', $value, time()+3600*24*100, '/', 'cardiacmri.com', false); | |
} | |
} | |
} // function is called in the learning center template single-guides.php | |
/* =========================================== | |
LC View Count Maxed Out, Redirect to Login, Add Note | |
=============================================*/ | |
function non_member_redirect() { | |
if ( !is_user_logged_in() ) { | |
if ( isset($_COOKIE['lc_page_view']) && $_COOKIE['lc_page_view'] >= 5 ) { | |
setcookie('lc_login_note', 1, time()+10, '/', 'cardiacmri.com', false); | |
wp_redirect( home_url().'/user-login/' ); exit; | |
} | |
} | |
} // function is called in the learning center template single-guides.php | |
/* =========================================== | |
Clear LC Cookies on Login | |
=============================================*/ | |
function login_cookie_clear() { | |
if ( is_user_logged_in() ) { | |
setcookie('lc_page_view', '', time()-3600, '/', 'cardiacmri.com', false); | |
setcookie('lc_login_note', '', time()-3600, '/', 'cardiacmri.com', false); | |
} | |
} | |
add_action( 'init', 'login_cookie_clear' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment