Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RevConcept
Last active February 20, 2016 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RevConcept/bf617b9447877d16370f to your computer and use it in GitHub Desktop.
Save RevConcept/bf617b9447877d16370f to your computer and use it in GitHub Desktop.
Page View Cookie
/* ===========================================
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