Skip to content

Instantly share code, notes, and snippets.

@artpi
Created March 20, 2019 16:12
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 artpi/213ca0f7aa30ad9c1470c18bcfaede09 to your computer and use it in GitHub Desktop.
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 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' );
@artpi
Copy link
Author

artpi commented Mar 20, 2019

żeby było nie do obejścia, to można zamienic:
if ( empty( $_GET[ 'visitor_id' ] ) ) na if ( 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment