Gravity Custom Merge Tags [closed]

You need to add the new merge tags with the gform_custom_merge_tags filter, and then replace them with the gform_replace_merge_tags filter, like this:

Edit: you need to use the gform_field_content filter to replace the field’s default value, see below.

add_filter('gform_custom_merge_tags', 'wpse_121476_custom_merge_tags', 10, 4);
add_filter('gform_replace_merge_tags', 'wpse_121476_replace_merge_tags', 10, 7);
add_filter('gform_field_content', 'wpse_121476_field_content', 10, 5);

/**
* add custom merge tags
* @param array $merge_tags
* @param int $form_id
* @param array $fields
* @param int $element_id
* @return array
*/
function wpse_121476_custom_merge_tags($merge_tags, $form_id, $fields, $element_id) {
    $merge_tags[] = array('label' => 'User Phone', 'tag' => '{user_phone}');

    return $merge_tags;
}

/**
* replace custom merge tags in notifications
* @param string $text
* @param array $form
* @param array $lead
* @param bool $url_encode
* @param bool $esc_html
* @param bool $nl2br
* @param string $format
* @return string
*/
function wpse_121476_replace_merge_tags($text, $form, $lead, $url_encode, $esc_html, $nl2br, $format) {
    $userid = get_current_user_id();
    $phone = $userid ? get_user_meta($userid, 'phone', true) : '';
    $text = str_replace('{user_phone}', $phone, $text);

    return $text;
}

/**
* replace custom merge tags in field content
* @param string $field_content
* @param array $field
* @param string $value
* @param int $lead_id
* @param int $form_id
* @return string
*/
function wpse_121476_field_content($field_content, $field, $value, $lead_id, $form_id) {
    if (strpos($field_content, '{user_phone}') !== false) {
        $userid = get_current_user_id();
        $phone = $userid ? get_user_meta($userid, 'phone', true) : '';
        $field_content = str_replace('{user_phone}', $phone, $field_content);
    }

    return $field_content;
}