GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions
GravityView_Merge_Tags Class Reference

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

Public Member Functions

 __construct ()
 

Static Public Member Functions

static format_date ($date_created= '', $property= '')
 Format Merge Tags using GVCommon::format_date() More...
 
static process_modifiers ($value, $merge_tag, $modifier, $field, $raw_value)
 Process custom GravityView modifiers for Merge Tags. More...
 
static replace_get_variables ($text, $form=array(), $entry=array(), $url_encode=false)
 Allow passing variables via URL to be displayed in Merge Tags. More...
 
static replace_gv_merge_tags ($text, $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
 Run GravityView filters when using GFCommon::replace_variables() More...
 
static replace_variables ($text, $form=array(), $entry=array(), $url_encode=false, $esc_html=true)
 Alias for GFCommon::replace_variables() More...
 

Private Member Functions

 add_hooks ()
 Tap in to gform_replace_merge_tags to add merge tags. More...
 

Static Private Member Functions

static get_format_from_modifiers ($exploded, $backup= '')
 If there is a :format modifier in a merge tag, grab the formatting. More...
 
static modifier_maxwords ($raw_value, $matches)
 Trim the Merge Tag's length in words. More...
 
static modifier_timestamp ($raw_value, $matches)
 Convert Date field values to timestamp int. More...
 
static modifier_wpautop ($raw_value, $matches)
 Run the Merge Tag value through the wpautop function. More...
 

Detailed Description

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

Since
1.8.4

Definition at line 7 of file class-gravityview-merge-tags.php.

Constructor & Destructor Documentation

__construct ( )
Since
1.8.4

Definition at line 12 of file class-gravityview-merge-tags.php.

References add_hooks().

Member Function Documentation

add_hooks ( )
private

Tap in to gform_replace_merge_tags to add merge tags.

Since
1.8.4
See also
GFCommon::replace_variables_prepopulate

Definition at line 20 of file class-gravityview-merge-tags.php.

Referenced by __construct().

static format_date (   $date_created = '',
  $property = '' 
)
static

Format Merge Tags using GVCommon::format_date()

GVCommon::format_date()

See also
http://docs.gravityview.co/article/331-date-created-merge-tag for documentation
Parameters
string$date_createdThe Gravity Forms date created format
string$propertyAny modifiers for the merge tag (human, format:m/d/Y)
Returns
int|string If timestamp requested, timestamp int. Otherwise, string output.

Definition at line 249 of file class-gravityview-merge-tags.php.

References GVCommon\format_date().

Referenced by GravityView_Field_Date_Created\replace_merge_tag().

static get_format_from_modifiers (   $exploded,
  $backup = '' 
)
staticprivate

If there is a :format modifier in a merge tag, grab the formatting.

The :format modifier should always have the format follow it; it's the next item in the array In foo:format:bar, "bar" will be the returned format

Since
1.16
Parameters
array$explodedArray of modifiers with a possible format value
string$backupThe backup value to use, if not found
Returns
string If format is found, the passed format. Otherwise, the backup.

Definition at line 281 of file class-gravityview-merge-tags.php.

static modifier_maxwords (   $raw_value,
  $matches 
)
staticprivate

Trim the Merge Tag's length in words.

Notes:

  • HTML tags are preserved
  • HTML entities are encoded, but if they are separated by word breaks, they will be counted as words Example: "one & two" will be counted as three words, but "one& two" will be counted as two words
Since
1.17
Parameters
string$raw_valueValue to filter
array$matchesRegex matches group
Returns
string Modified value, if longer than the passed maxwords modifier

Use htmlentities instead, so that entities are double-encoded, and decoding restores original values.

See also
https://core.trac.wordpress.org/ticket/29533#comment:3

Definition at line 136 of file class-gravityview-merge-tags.php.

static modifier_timestamp (   $raw_value,
  $matches 
)
staticprivate

Convert Date field values to timestamp int.

Since
1.17

strtotime()

Parameters
string$raw_valueValue to filter
array$matchesRegex matches group
Returns
int Timestamp value of date. -1 if not a valid timestamp.

Definition at line 88 of file class-gravityview-merge-tags.php.

static modifier_wpautop (   $raw_value,
  $matches 
)
staticprivate

Run the Merge Tag value through the wpautop function.

Since
1.17

wpautop

Parameters
string$raw_valueValue to filter
array$matchesRegex matches group
Returns
string Modified value, if longer than the passed maxwords modifier

Definition at line 112 of file class-gravityview-merge-tags.php.

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

Process custom GravityView modifiers for Merge Tags.

Is not processed on {all_fields} Merge Tag.

Since
1.17
Parameters
string$valueThe current merge tag value to be filtered.
string$merge_tagIf 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).
string$modifierThe 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}.
GF_Field$fieldThe current field.
mixed$raw_valueThe 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.
See also
modifier_maxwords
modifier_wpautop
modifier_timestamp

Definition at line 45 of file class-gravityview-merge-tags.php.

References $merge_tag, and $value.

static replace_get_variables (   $text,
  $form = array(),
  $entry = array(),
  $url_encode = false 
)
static

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

Since
1.15
Parameters
string$textText to replace
array$formGravity Forms form array
array$entryEntry array
bool$url_encodeWhether to URL-encode output
Runs Filter:
gravityview/merge_tags/get/glue/ Modify the glue used to convert an array of {get} values from an array to string
Since
1.15
Parameters
[in,out]string$glueString used to implode() $_GET values Default: ', '
[in]string$propertyThe current name of the $_GET parameter being combined
Runs Filter:
gravityview/merge_tags/get/esc_html/{url parameter name} Disable esc_html() from running on {get} merge tag By default, all values passed through URLs will be escaped for security reasons. If for some reason you want to pass HTML in the URL, for example, you will need to return false on this filter. It is strongly recommended that you do not disable this filter.
Since
1.15
Parameters
bool$esc_htmlWhether to esc_html() the value. Default: true
Runs Filter:
gravityview/merge_tags/get/esc_html/{url parameter name} Modify the value of the {get} replacement before being used
Parameters
[in,out]string$valueValue that will replace {get}
[in]string$textText that contains {get} (before replacement)
[in]array$formGravity Forms form array
[in]array$entryEntry array

Definition at line 317 of file class-gravityview-merge-tags.php.

References $entry, $form, and $value.

static replace_gv_merge_tags (   $text,
  $form = array(),
  $entry = array(),
  $url_encode = false,
  $esc_html = false 
)
static

Run GravityView filters when using GFCommon::replace_variables()

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

Since
1.8.4
Parameters
string$textText to replace
array | bool$formGravity Forms form array. When called inside {
See also
GFCommon::replace_variables()} (now deprecated), false
Parameters
array | bool$entryEntry array. When called inside {
See also
GFCommon::replace_variables()} (now deprecated), false
Parameters
bool$url_encodeWhether to URL-encode output
bool$esc_htmlWhether to apply esc_html() to output
Returns
mixed

This prevents the gform_replace_merge_tags filter from being called twice, as defined in:

See also
GFCommon::replace_variables()
GFCommon::replace_variables_prepopulate()

Definition at line 220 of file class-gravityview-merge-tags.php.

References $entry, and $form.

static replace_variables (   $text,
  $form = array(),
  $entry = array(),
  $url_encode = false,
  $esc_html = true 
)
static

Alias for GFCommon::replace_variables()

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

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
Parameters
string$textText to replace variables in
array$formGF Form array
array$entryGF Entry array
bool$url_encodePass return value through url_encode()
bool$esc_htmlPass return value through esc_html()
Returns
string Text with variables maybe replaced
Runs Filter:
gravityview_do_replace_variables Turn off merge tag variable replacements.
Useful where you want to process variables yourself. We do this in the Math Extension.
Since
1.13
Parameters
[in,out]boolean$do_replace_variablesTrue: yes, replace variables for this text; False: do not replace variables.
[in]string$textText to replace variables in
[in]array$formGF Form array
[in]array$entryGF Entry array

Make sure the required keys are set for GFCommon::replace_variables

Definition at line 174 of file class-gravityview-merge-tags.php.

References $entry, and $form.

Referenced by GravityView_Shortcode\parse_and_sanitize_atts(), GravityView_Widget_Custom_Content\render_frontend(), GravityView_API\replace_variables(), and GravityView_Field_Custom\show_field_in_edit_entry().


The documentation for this class was generated from the following file: