Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This page should be visible only for 48 hours since the first visit
- // Drop this in functions.php
- function make_the_page_visible_only_certain_time_after_first_visit() {
- $secret_page = PAGE_ID_HERE;
- $redirect_to_when_expired = URL_TO_REDIRECT;
- $time_to_visit = 48 * 3600; //48h
- if ( is_page( $secret_page ) && ! is_user_logged_in() ) {
- if ( empty( $_GET[ 'visitor_id' ] ) ) {
- wp_redirect( URL_OF_EXPIRED_PAGE );
- exit; // Stop scrip exec.
- }
- $visitor_email = $_GET[ 'visitor_id' ];
- $has_visited_before = get_post_meta( $secret_page, 'visited_' . $visitor_email, true );
- if ( ! $has_visited_before ) {
- // Log the time of the visit in post meta
- add_post_meta( $secret_page, 'visited_' . $visitor_email, time(), true );
- } else if ( intval( $has_visited_before ) + $time_to_visit < time() ) {
- wp_redirect( URL_OF_EXPIRED_PAGE );
- exit; // Stop scrip exec.
- }
- }
- }
- add_action( 'template_redirect', 'make_the_page_visible_only_certain_time_after_first_visit' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement