Skip to content

Instantly share code, notes, and snippets.

@spivurno
Created June 7, 2014 02:09
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 spivurno/c87eab3aa56a5c6bded1 to your computer and use it in GitHub Desktop.
Save spivurno/c87eab3aa56a5c6bded1 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Post Permalink Merge Tag
<?php
/**
* Gravity Wiz // Gravity Forms // Post Permalink Merge Tag
* http://gravitywiz.com
*/
class GWPostPermalink {
function __construct() {
add_filter('gform_custom_merge_tags', array($this, 'add_custom_merge_tag'), 10, 4);
add_filter('gform_replace_merge_tags', array($this, 'replace_merge_tag'), 10, 3);
}
function add_custom_merge_tag($merge_tags, $form_id, $fields, $element_id) {
if(!GFCommon::has_post_field($fields))
return $merge_tags;
$merge_tags[] = array('label' => 'Post Permalink', 'tag' => '{post_permalink}');
return $merge_tags;
}
function replace_merge_tag($text, $form, $entry) {
$custom_merge_tag = '{post_permalink}';
if(strpos($text, $custom_merge_tag) === false || !rgar($entry, 'post_id'))
return $text;
$post_permalink = get_permalink(rgar($entry, 'post_id'));
$text = str_replace($custom_merge_tag, $post_permalink, $text);
return $text;
}
}
new GWPostPermalink();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment