Created
March 20, 2019 16:12
-
-
Save artpi/213ca0f7aa30ad9c1470c18bcfaede09 to your computer and use it in GitHub Desktop.
This page should be visible only for 48 hours since the first visit
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
// 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
żeby było nie do obejścia, to można zamienic:
if ( empty( $_GET[ 'visitor_id' ] ) )
naif ( empty( $_GET[ 'visitor_id' ] ) || empty( $_GET[ 'hash' ] ) || md5( $_GET[ 'visitor_id' ]. 'potato' ) != $_GET[ 'hash' ]. )
Wtedy trzeba dawać linki z mailchimpa http://potato?visitor_id=*|EMAIL|*&hash=*|HASH|*
Ale trzeba HASH ustawić jako merge param w mailchimpie https://mailchimp.com/help/create-unique-urls-for-subscribers/#Unique_URL_Example
I musi być wygenerowane jako:
echo md5( $useremail. 'potato' )
;Tu sobie można phpa odpalać https://repl.it/languages/php