Skip to content

Instantly share code, notes, and snippets.

@benmay
Last active December 14, 2015 11:38
Show Gist options
  • Save benmay/5080137 to your computer and use it in GitHub Desktop.
Save benmay/5080137 to your computer and use it in GitHub Desktop.
Add WP_login merge tag to gravity forms
<?php
class extraGravityMergeTags
{
function __construct()
{
add_filter( 'gform_custom_merge_tags', array( $this, 'add_merge_tags' ), 10, 4 );
add_filter( 'gform_replace_merge_tags', array( $this, 'run_merge_tags' ) , 10, 7);
}
function add_merge_tags($merge_tags, $form_id, $fields, $element_id)
{
$merge_tags[] = array( 'label' => 'WordPress Login URL', 'tag' => '{wp_login}' );
return $merge_tags;
}
function run_merge_tags($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format)
{
$custom_merge_tag = '{wp_login}';
if( strpos( $text, $custom_merge_tag ) === false )
return $text;
$login_link = get_bloginfo( 'url' ) . '/login/';
$text = str_replace( $custom_merge_tag, $login_link, $text );
return $text;
}
}
new extraGravityMergeTags();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment