Created
April 25, 2018 16:45
-
-
Save douglaskarr/3e2d3278f29ed8750f6cd9752efc0a47 to your computer and use it in GitHub Desktop.
Gravity Forms Access Subpages
This file contains 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
<?php | |
/** | |
This code will go in your theme's functions.php file. Upon form submission, | |
it allows the user to access subpages. In this example, it's form ID 14 and the | |
registration page is 'product-tour' Once submitted, you may wish to redirect | |
the user to a page that has a TOC or something similar. | |
**/ | |
// Indicate whether or not the product tour form (14) was submitted via Cookie | |
add_action( 'gform_after_submission_14', 'dknm_set_submitted_cookie', 10, 2 ); | |
function dknm_set_submitted_cookie( $entry, $form ) { | |
// Set a session cookie that the form was submitted | |
setcookie( 'product_tour_registered', 'true' ); | |
} | |
// Redirect if the form hasn't been submitted | |
add_action( 'template_redirect', 'dknm_protect_confirmation_page' ); | |
function dknm_protect_confirmation_page() { | |
global $post; | |
$parent_id = $post->post_parent; | |
$post_parent_slug = get_post_field( 'post_name', $parent_id ); | |
if( ($post_parent_slug == 'product-tour') && ! isset( $_COOKIE['product_tour_registered'] ) ) { | |
wp_redirect( home_url( '/lp/product-tour/' ) ); | |
exit(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment