I'm searching for a way to mask a wordpress page url or create a one time url. I have a webshop which redirects to a signup form after sucessful payment but I don't want anyone to use the link more than once.
I found a solution here from cabrerahector with a javascript which I partly got working. WordPress: Mask page URL I could get it to redirect to the startpage, only problem was it does all the time even if id is correct. Any suggestions?
function mycustom_wp_head() {
$home_url = get_home_url();
$contact_page_ID = 22; // Change this to your "Contact" page ID
$thank_you_page_ID = 2; // Change this to your "Thank You" page ID
if ( is_page($thank_you_page_ID) ) :
?>
<script>
var allowed_referer_url = '<?php echo get_permalink( $contact_page_ID ); ?>';
// No referer, or referer isn't our Contact page,
// redirect to homepage
if ( ! document.referrer || allowed_referer_url != document.referrer ) {
window.location = '<?php echo $home_url; ?>';
}
</script>
<?php
endif;
}
add_action( 'wp_head', 'mycustom_wp_head' );