Last active
June 1, 2016 23:29
-
-
Save maarten00/e8adeb69dc212be3634a to your computer and use it in GitHub Desktop.
Gravity forms referrer url fix
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
function populate_posts($form){ | |
foreach($form['fields'] as &$field){ | |
if($field['defaultValue'] != '{referer}') | |
continue; | |
//Check referrer field, if exists and HTTP referrer not set, try to fill it manually | |
if($field['defaultValue'] == '{referer}' && ! isset($_SERVER['HTTP_REFERER'])) | |
{ | |
$field['defaultValue'] = _getReferrerUrl(); | |
continue; | |
} | |
} | |
return $form; | |
} | |
function _getReferrerUrl() | |
{ | |
$url = 'Referrer niet beschikbaar'; | |
if(isset($_GET['occ_id'])) | |
$url = get_option('home') . '/occasion/' . $_GET['occ_id']; | |
if(isset($_GET['post_id'])) | |
$url = get_permalink($_GET['post_id']); | |
return $url; | |
} | |
//Add these for each form, where the last number is the form id | |
add_filter('gform_pre_render_1', 'populate_posts'); | |
add_action("gform_admin_pre_render_1", "populate_posts"); |
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
//Occasion version of URL: | |
<a href="<?= get_option('home') ?>/aanvragen/?occ_id=<?= $o->voertuignr_hexon ?>">Offerte aanvragen</a> | |
//Post version of URL | |
<a href="<?=get_option('home')?>/aanvragen/?post_id=<?= $post->ID ?>">Offerte aanvragen</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment