Skip to main content

GravityView_Merge_Tags

Enhance Gravity Forms' merge tag functionality by adding additional merge tags

Since: 1.8.4

Source: includes/class-gravityview-merge-tags.php:8

Details

  • Kind: class
  • Namespace: (global)

Methods

MethodDescription
__construct()
cache_merge_tag_modifiers()Caches merge tag modifiers to preserve their case sensitivity.
process_modifiers()Process custom GravityView modifiers for Merge Tags
modifier_human()Converts date and time values to the human format modifier.
modifier_initials()Adds a modifier to convert a full name or string to initials.
replace_variables()Alias for GFCommon::replace_variables()
replace_gv_merge_tags()Run GravityView filters when using GFCommon::replace_variables()
replace_merge_tags_dates()Replaces relative date merge tags with formatted dates per the modifier.
replace_is_starred()Add a {is_starred} Merge Tag
replace_site_url()Add a {site_url} Merge Tag
replace_entry_link()Add a {gv_entry_link} Merge Tag, alias of [gv_entry_link] shortcode in {gv_entry_link:[post id]:[action]} format
format_date()Formats merge tag value using Merge Tags using GVCommon::format_date()
replace_current_post()Add a {current_post} Merge Tag for information about the current post (in the loop or singular)
replace_get_variables()Allow passing variables via URL to be displayed in Merge Tags

Method Reference

__construct()

public function __construct()

Since: 1.8.4

Source: includes/class-gravityview-merge-tags.php:21

cache_merge_tag_modifiers()

public function cache_merge_tag_modifiers( $text )

Caches merge tag modifiers to preserve their case sensitivity.

This is necessary because {@see GFCommon::replace_field_variable()) applies strtolower() to the modifier and causes issues where case is expected, such as date formatting (e.g., format:Y-m-d).

Parameters

NameTypeDefaultDescription
$textstringText with merge tags.

Returns

  • string

Since: 2.26

Source: includes/class-gravityview-merge-tags.php:52

process_modifiers()

public static function process_modifiers( $value, $merge_tag, $modifier, $field, $raw_value )

Process custom GravityView modifiers for Merge Tags

Is not processed on {all_fields} Merge Tag.

Parameters

NameTypeDefaultDescription
$valuestringThe current merge tag value to be filtered.
$merge_tagstringIf the merge tag being executed is an individual field merge tag (i.e. {Name:3}), this variable will contain the field's ID. If not, this variable will contain the name of the merge tag (i.e. all_fields).
$modifierstringThe string containing any modifiers for this merge tag. For example, "maxwords:10" would be the modifiers for the following merge tag: {Text:2:maxwords:10}.
$fieldGF_FieldThe current field.
$raw_valuemixedThe raw value submitted for this field.

Returns

  • string — If no modifiers passed, $raw_value is not a string, or {all_fields} Merge Tag is used, original value. Otherwise, output from modifier methods.

Since: 1.17

Source: includes/class-gravityview-merge-tags.php:91

modifier_human()

public static function modifier_human( $raw_value, $matches, $value='', $field=null, $modifier='' )

Converts date and time values to the human format modifier.

Parameters

NameTypeDefaultDescription
$raw_valuestringThe raw value to modify.
$matchesarrayArray of regex matches.
$valuestring''The original value.
$fieldarraynullThe field object.
$modifierstring''The modifier string.

Returns

  • string

Since: 2.29.0

Source: includes/class-gravityview-merge-tags.php:196

modifier_initials()

public static function modifier_initials( $raw_value )

Adds a modifier to convert a full name or string to initials.

Parameters

NameTypeDefaultDescription
$raw_valuestringThe full name or string to convert.

Returns

  • string — The initials.

Since: 2.33

Source: includes/class-gravityview-merge-tags.php:460

replace_variables()

public static function replace_variables( $text, $form=[], $entry=[], $url_encode=false, $esc_html=true, $nl2br=true, $format='html', $aux_data=[] )

Alias for GFCommon::replace_variables()

Before 1.15.3, it would check for merge tags before passing to Gravity Forms to improve speed.

Parameters

NameTypeDefaultDescription
$textstringText to replace variables in.
$formarray[]GF Form array
$entryarray[]GF Entry array
$url_encodeboolfalsePass return value through url_encode()
$esc_htmlbooltruePass return value through esc_html()
$nl2brbooltrueConvert newlines to <br> HTML tags
$formatstring'html'The format requested for the location the merge is being used. Possible values: html, text or url.
$aux_dataarray[]Additional data to be used to replace merge tags https://www.gravityhelp.com/documentation/article/gform_merge_tag_data/

Returns

  • string — Text with variables maybe replaced

Since:

  • 1.15.3 (- Now that Gravity Forms added speed improvements in 1.9.15, it's more of an alias with a filter to disable or enable replacements.)
  • 1.8.4 (- Moved to GravityView_Merge_Tags)
  • 1.15.1 (- Add support for $url_encode and $esc_html arguments)
  • 1.22.4 (- Added $nl2br, $format, $aux_data args)

Source: includes/class-gravityview-merge-tags.php:485

replace_gv_merge_tags()

public static function replace_gv_merge_tags( $text, $form=[], $entry=[], $url_encode=false, $esc_html=false )

Run GravityView filters when using GFCommon::replace_variables()

Instead of adding multiple hooks, add all hooks into this one method to improve speed

Parameters

NameTypeDefaultDescription
$textstringText to replace
$formarray | bool[]Gravity Forms form array. When called inside \GFCommon::replace_variables() (now deprecated), false
$entryarray | bool[]Entry array. When called inside \GFCommon::replace_variables() (now deprecated), false
$url_encodeboolfalseWhether to URL-encode output
$esc_htmlboolfalseWhether to apply esc_html() to output

Returns

  • mixed

Since: 1.8.4

Source: includes/class-gravityview-merge-tags.php:539

replace_merge_tags_dates()

public static function replace_merge_tags_dates( $text )

Replaces relative date merge tags with formatted dates per the modifier.

Parameters

NameTypeDefaultDescription
$textstringThe text containing merge tags.

Returns

  • string — The text with date merge tags replaced.

Since: 2.30.0

Source: includes/class-gravityview-merge-tags.php:569

replace_is_starred()

public static function replace_is_starred( $original_text, $form=[], $entry=[], $url_encode=false, $esc_html=false )

Add a {is_starred} Merge Tag

Parameters

NameTypeDefaultDescription
$original_textstringText to replace
$formarray[]Gravity Forms form array
$entryarray[]Entry array
$url_encodeboolfalseWhether to URL-encode output
$esc_htmlboolfalseIndicates if the esc_html function should be applied.

Returns

  • string — Original text, if no {site_url} Merge Tags found, otherwise text with Merge Tag replaced

Since: 2.14

Source: includes/class-gravityview-merge-tags.php:618

replace_site_url()

public static function replace_site_url( $original_text, $form=[], $entry=[], $url_encode=false, $esc_html=false )

Add a {site_url} Merge Tag

Parameters

NameTypeDefaultDescription
$original_textstringText to replace
$formarray[]Gravity Forms form array
$entryarray[]Entry array
$url_encodeboolfalseWhether to URL-encode output
$esc_htmlboolfalseIndicates if the esc_html function should be applied.

Returns

  • string — Original text, if no {site_url} Merge Tags found, otherwise text with Merge Tag replaced

Since: 2.10.1

Source: includes/class-gravityview-merge-tags.php:640

replace_entry_link()

public static function replace_entry_link( $original_text, $form=[], $entry=[], $url_encode=false, $esc_html=false )

Add a {gv_entry_link} Merge Tag, alias of [gv_entry_link] shortcode in {gv_entry_link:[post id]:[action]} format

Parameters

NameTypeDefaultDescription
$original_textstringText to replace
$formarray[]Gravity Forms form array
$entryarray[]Entry array
$url_encodeboolfalseWhether to URL-encode output
$esc_htmlboolfalseIndicates if the esc_html function should be applied.

Returns

  • string — Original text, if no {gv_entry_link} Merge Tags found, otherwise text with Merge Tags replaced

Source: includes/class-gravityview-merge-tags.php:670

format_date()

public static function format_date( $date_or_time_string='', $modifier='' )

Formats merge tag value using Merge Tags using GVCommon::format_date()

Parameters

NameTypeDefaultDescription
$date_or_time_stringstring''The Gravity Forms date or time string.
$modifierstring''Merge tag modifier (human, format:m/d/Y)

Returns

  • int | string — If timestamp requested, timestamp int. Otherwise, string output.

See Also

Since: 1.16

Source: includes/class-gravityview-merge-tags.php:736

replace_current_post()

public static function replace_current_post( $original_text, $form=[], $entry=[], $url_encode=false, $esc_html=false )

Add a {current_post} Merge Tag for information about the current post (in the loop or singular)

{current_post} is replaced with the current post's permalink by default, when no modifiers are passed. Pass WP_Post properties as :modifiers to access.

{current_post} is the same as {embed_post}, except:

  • Adds support for {current_post:permalink}
  • Works on post archives, as well as singular

Parameters

NameTypeDefaultDescription
$original_textstringText to replace
$formarray[]Gravity Forms form array
$entryarray[]Entry array
$url_encodeboolfalseWhether to URL-encode output
$esc_htmlboolfalseIndicates if the esc_html function should be applied.

Returns

  • string — Original text, if no {current_post} Merge Tags found, otherwise text with Merge Tags replaced

See Also

Source: includes/class-gravityview-merge-tags.php:792

replace_get_variables()

public static function replace_get_variables( $text, $form=[], $entry=[], $url_encode=false )

Allow passing variables via URL to be displayed in Merge Tags

Works with [gvlogic]: [gvlogic if="{get:example}" is="false"] ?example=false [else] ?example wasn't "false". It's {get:example}! [/gvlogic]

Supports passing arrays: URL: example[]=Example+One&example[]=Example+(with+comma)%2C+Two Merge Tag: {get:example} Output: Example One, Example (with comma), Two

Parameters

NameTypeDefaultDescription
$textstringText to replace
$formarray[]Gravity Forms form array
$entryarray[]Entry array
$url_encodeboolfalseWhether to URL-encode output

Returns

  • string — Original text, if no Merge Tags found, otherwise text with Merge Tags replaced

Since: 1.15

Source: includes/class-gravityview-merge-tags.php:864