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
| Method | Description |
|---|---|
__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
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Text 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
| Name | Type | Default | Description |
|---|---|---|---|
$value | string | The current merge tag value to be filtered. | |
$merge_tag | string | If 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). | |
$modifier | string | The 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}. | |
$field | GF_Field | The current field. | |
$raw_value | mixed | The 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
| Name | Type | Default | Description |
|---|---|---|---|
$raw_value | string | The raw value to modify. | |
$matches | array | Array of regex matches. | |
$value | string | '' | The original value. |
$field | array | null | The field object. |
$modifier | string | '' | 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
| Name | Type | Default | Description |
|---|---|---|---|
$raw_value | string | The 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
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Text to replace variables in. | |
$form | array | [] | GF Form array |
$entry | array | [] | GF Entry array |
$url_encode | bool | false | Pass return value through url_encode() |
$esc_html | bool | true | Pass return value through esc_html() |
$nl2br | bool | true | Convert newlines to <br> HTML tags |
$format | string | 'html' | The format requested for the location the merge is being used. Possible values: html, text or url. |
$aux_data | array | [] | 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
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Text to replace | |
$form | array | bool | [] | Gravity Forms form array. When called inside \GFCommon::replace_variables() (now deprecated), false |
$entry | array | bool | [] | Entry array. When called inside \GFCommon::replace_variables() (now deprecated), false |
$url_encode | bool | false | Whether to URL-encode output |
$esc_html | bool | false | Whether 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
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | The 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
| Name | Type | Default | Description |
|---|---|---|---|
$original_text | string | Text to replace | |
$form | array | [] | Gravity Forms form array |
$entry | array | [] | Entry array |
$url_encode | bool | false | Whether to URL-encode output |
$esc_html | bool | false | Indicates 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
| Name | Type | Default | Description |
|---|---|---|---|
$original_text | string | Text to replace | |
$form | array | [] | Gravity Forms form array |
$entry | array | [] | Entry array |
$url_encode | bool | false | Whether to URL-encode output |
$esc_html | bool | false | Indicates 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
| Name | Type | Default | Description |
|---|---|---|---|
$original_text | string | Text to replace | |
$form | array | [] | Gravity Forms form array |
$entry | array | [] | Entry array |
$url_encode | bool | false | Whether to URL-encode output |
$esc_html | bool | false | Indicates 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
| Name | Type | Default | Description |
|---|---|---|---|
$date_or_time_string | string | '' | The Gravity Forms date or time string. |
$modifier | string | '' | Merge tag modifier (human, format:m/d/Y) |
Returns
int|string— If timestamp requested, timestamp int. Otherwise, string output.
See Also
- https://docs.gravitykit.com/article/331-date-created-merge-tag for documentation
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
| Name | Type | Default | Description |
|---|---|---|---|
$original_text | string | Text to replace | |
$form | array | [] | Gravity Forms form array |
$entry | array | [] | Entry array |
$url_encode | bool | false | Whether to URL-encode output |
$esc_html | bool | false | Indicates 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
- https://www.gravityhelp.com/documentation/article/merge-tags/#embed-post for examples
GFCommon::replace_variables_prepopulate - Code is there for {custom_field} and {embed_post} Merge Tags
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
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Text to replace | |
$form | array | [] | Gravity Forms form array |
$entry | array | [] | Entry array |
$url_encode | bool | false | Whether 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