GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-merge-tags.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Enhance Gravity Forms' merge tag functionality by adding additional merge tags
5  * @since 1.8.4
6  */
8 
9  /**
10  * @since 1.8.4
11  */
12  public function __construct() {
13  $this->add_hooks();
14  }
15 
16  /**
17  * Tap in to gform_replace_merge_tags to add merge tags
18  * @since 1.8.4
19  */
20  private function add_hooks() {
21 
22  /** @see GFCommon::replace_variables_prepopulate **/
23  add_filter( 'gform_replace_merge_tags', array( 'GravityView_Merge_Tags', 'replace_gv_merge_tags' ), 10, 7 );
24 
25  // Process after 10 priority
26  add_filter( 'gform_merge_tag_filter', array( 'GravityView_Merge_Tags', 'process_modifiers' ), 20, 5 );
27 
28  }
29 
30  /**
31  * Process custom GravityView modifiers for Merge Tags
32  *
33  * Is not processed on `{all_fields}` Merge Tag.
34  *
35  * @since 1.17
36  *
37  * @param string $value The current merge tag value to be filtered.
38  * @param string $merge_tag 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).
39  * @param string $modifier 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}`.
40  * @param GF_Field $field The current field.
41  * @param mixed $raw_value The raw value submitted for this field.
42  *
43  * @return 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.
44  */
45  public static function process_modifiers( $value, $merge_tag, $modifier, $field, $raw_value ) {
46 
47  // No modifier was set or the raw value was empty
48  if ( 'all_fields' === $merge_tag || '' === $modifier || ! is_string( $raw_value ) || '' === $raw_value ) {
49  return $value;
50  }
51 
52  // matching regex => the value is the method to call to replace the value.
53  $gv_modifiers = array(
54  'maxwords:(\d+)' => 'modifier_maxwords', /** @see modifier_maxwords */
55  'timestamp' => 'modifier_timestamp', /** @see modifier_timestamp */
56  'explode' => 'modifier_explode', /** @see modifier_explode */
57 
58  /** @see modifier_strings */
59  'urlencode' => 'modifier_strings',
60  'wpautop' => 'modifier_strings',
61  'esc_html' => 'modifier_strings',
62  'sanitize_html_class' => 'modifier_strings',
63  'sanitize_title' => 'modifier_strings',
64  'strtolower' => 'modifier_strings',
65  'strtoupper' => 'modifier_strings',
66  'ucfirst' => 'modifier_strings',
67  'ucwords' => 'modifier_strings',
68  'wptexturize' => 'modifier_strings',
69  );
70 
71  $modifiers = explode( ',', $modifier );
72 
73  $return = $raw_value;
74 
75  $unserialized = maybe_unserialize( $raw_value );
76 
77  if ( method_exists( $field, 'get_value_merge_tag' ) && is_array( $unserialized ) ) {
78 
79  $non_gv_modifiers = array_diff( $modifiers, array_keys( $gv_modifiers ) );
80 
81  $return = $field->get_value_merge_tag( $value, '', array( 'currency' => '' ), array(), implode( '', $non_gv_modifiers ), $raw_value, false, false, 'text', false);
82  }
83 
84  foreach ( $modifiers as $passed_modifier ) {
85 
86  foreach( $gv_modifiers as $gv_modifier => $method ) {
87 
88  // Uses ^ to only match the first modifier, to enforce same order as passed by GF
89  preg_match( '/^' . $gv_modifier . '/ism', $passed_modifier, $matches );
90 
91  if ( empty( $matches ) ) {
92  continue;
93  }
94 
95  // The called method is passed the raw value and the full matches array
96  $return = self::$method( $return, $matches, $value, $field );
97  break;
98  }
99  }
100 
101  // No GravityView modifications were made; return the (default) original value
102  if ( $raw_value === $return ) {
103  return $value;
104  }
105 
106  /**
107  * @filter `gravityview/merge_tags/modifiers/value` Modify the merge tag modifier output
108  * @since 2.0
109  * @param string $return The current merge tag value to be filtered.
110  * @param string $raw_value The raw value submitted for this field. May be CSV or JSON-encoded.
111  * @param string $value The original merge tag value, passed from Gravity Forms
112  * @param string $merge_tag 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).
113  * @param string $modifier 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}`.
114  * @param GF_Field $field The current field.
115  */
116  $return = apply_filters( 'gravityview/merge_tags/modifiers/value', $return, $raw_value, $value, $merge_tag, $modifier, $field );
117 
118  return $return;
119  }
120 
121  /**
122  * Convert Date field values to timestamp int
123  *
124  * @since 1.17
125  *
126  * @uses strtotime()
127  *
128  * @param string $raw_value Value to filter
129  * @param array $matches Regex matches group
130  *
131  * @return int Timestamp value of date. `-1` if not a valid timestamp.
132  */
133  private static function modifier_timestamp( $raw_value, $matches ) {
134 
135  if( empty( $matches[0] ) ) {
136  return $raw_value;
137  }
138 
139  $timestamp = strtotime( $raw_value );
140 
141  // Can return false or -1, depending on PHP version.
142  return ( $timestamp && $timestamp > 0 ) ? $timestamp : -1;
143  }
144 
145  /**
146  * Trim the Merge Tag's length in words.
147  *
148  * Notes:
149  * - HTML tags are preserved
150  * - HTML entities are encoded, but if they are separated by word breaks, they will be counted as words
151  * Example: "one & two" will be counted as three words, but "one& two" will be counted as two words
152  *
153  * @since 1.17
154  * @since 2.0 Added $field param and support for urlencode
155  *
156  * @param string $raw_value Value to filter
157  * @param array $matches Regex matches group
158  * @param GF_Field|false $field
159  *
160  * @return string Modified value, if longer than the passed `maxwords` modifier
161  */
162  private static function modifier_maxwords( $raw_value, $matches, $field = null ) {
163 
164  if( ! is_string( $raw_value ) || empty( $matches[1] ) || ! function_exists( 'wp_trim_words' ) ) {
165  return $raw_value;
166  }
167 
168  $max = intval( $matches[1] );
169 
170  $more_placeholder = '[GVMORE]';
171 
172  /**
173  * Use htmlentities instead, so that entities are double-encoded, and decoding restores original values.
174  * @see https://core.trac.wordpress.org/ticket/29533#comment:3
175  */
176  $return = force_balance_tags( wp_specialchars_decode( wp_trim_words( htmlentities( $raw_value ), $max, $more_placeholder ) ) );
177 
178  $return = str_replace( $more_placeholder, '&hellip;', $return );
179 
180  return self::maybe_urlencode( $field, $return );
181  }
182 
183  /**
184  * GF 2.3 adds GF_Field::get_modifers(), which allows us to check if a field has urlencode applied to it
185  *
186  * @since 2.0
187  *
188  * @see GFCommon::replace_field_variable
189  *
190  * Here's the relevant code:
191  *
192  * <code>
193  * $modifier = strtolower( rgar( $match, $i ) );
194  * $modifiers = array_map( 'trim', explode( ',', $modifier ) );
195  * $field->set_modifiers( $modifiers );
196  * </code>
197  *
198  * @param GF_Field|false $field
199  * @param string $value
200  *
201  * @return mixed|string
202  */
203  private static function maybe_urlencode( $field = false, $value = '' ) {
204 
205  $return = $value;
206 
207  if ( $field && method_exists( $field, 'get_modifiers' ) ) {
208 
209  $modifiers = $field->get_modifiers();
210 
211  if ( in_array( 'urlencode', $modifiers ) ) {
212  $return = urlencode( $return );
213  }
214  }
215 
216  return $return;
217  }
218 
219 
220  /**
221  * Convert JSON or CSV values into space-separated string
222  *
223  * Useful for Multiple Select field data, like categories
224  *
225  * @since 2.0
226  *
227  * @param mixed $raw_value The raw value submitted for this field. May be CSV or JSON-encoded.
228  * @param array $matches Regex matches group
229  * @param string $value The value as passed by Gravity Forms
230  * @param GF_Field|false $field Gravity Forms field, if any
231  *
232  * @return string
233  */
234  private static function modifier_explode( $raw_value, $matches, $value, $field = null ) {
235 
236  // For JSON-encoded arrays
237  if( $json_array = json_decode( $raw_value, true ) ) {
238  return implode( ' ', $json_array );
239  }
240 
241  return implode( ' ', explode( ',', $raw_value ) );
242  }
243 
244  /**
245  * Process strings with common PHP string manipulations
246  *
247  * @since 2.0
248  *
249  * @param mixed $raw_value The raw value submitted for this field. May be CSV or JSON-encoded.
250  * @param array $matches Regex matches group
251  * @param string $value The value as passed by Gravity Forms
252  * @param GF_Field|false $field Gravity Forms field, if any
253  *
254  * @return string
255  */
256  private static function modifier_strings( $raw_value, $matches, $value = '', $field = null ) {
257 
258  if( empty( $matches[0] ) ) {
259  return $raw_value;
260  }
261 
262  $return = $raw_value;
263 
264  switch( $matches[0] ) {
265  case 'urlencode':
266  $return = urlencode( $raw_value );
267  break;
268  case 'wpautop':
269  $return = trim( wpautop( $raw_value ) );
270  break;
271  case 'esc_html':
272  $return = esc_html( $raw_value );
273  break;
274  case 'sanitize_html_class':
275  $return = function_exists( 'gravityview_sanitize_html_class' ) ? gravityview_sanitize_html_class( $raw_value ) : sanitize_html_class( $raw_value );
276  break;
277  case 'sanitize_title':
278  $return = sanitize_title( $raw_value, '', 'gravityview/merge-tags/modifier' );
279  break;
280  case 'strtoupper':
281  $return = function_exists( 'mb_strtoupper' ) ? mb_strtoupper( $raw_value ) : strtoupper( $raw_value );
282  break;
283  case 'strtolower':
284  $return = function_exists( 'mb_strtolower' ) ? mb_strtolower( $raw_value ) : strtolower( $raw_value );
285  break;
286  case 'ucwords':
287  $return = ucwords( $raw_value );
288  break;
289  case 'ucfirst':
290  $return = ucfirst( $raw_value );
291  break;
292  case 'wptexturize':
293  $return = wptexturize( $raw_value );
294  break;
295  }
296 
297  return $return;
298  }
299 
300  /**
301  * Alias for GFCommon::replace_variables()
302  *
303  * Before 1.15.3, it would check for merge tags before passing to Gravity Forms to improve speed.
304  *
305  * @since 1.15.3 - Now that Gravity Forms added speed improvements in 1.9.15, it's more of an alias with a filter
306  * to disable or enable replacements.
307  * @since 1.8.4 - Moved to GravityView_Merge_Tags
308  * @since 1.15.1 - Add support for $url_encode and $esc_html arguments
309  * @since 1.22.4 - Added $nl2br, $format, $aux_data args
310  *
311  * @param string $text Text to replace variables in
312  * @param array $form GF Form array
313  * @param array $entry GF Entry array
314  * @param bool $url_encode Pass return value through `url_encode()`
315  * @param bool $esc_html Pass return value through `esc_html()`
316  * @param bool $nl2br Convert newlines to <br> HTML tags
317  * @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
318  * @param array $aux_data Additional data to be used to replace merge tags {@see https://www.gravityhelp.com/documentation/article/gform_merge_tag_data/}
319  * @return string Text with variables maybe replaced
320  */
321  public static function replace_variables( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = true, $nl2br = true, $format = 'html', $aux_data = array() ) {
322 
323  if ( ! is_string( $text ) ) {
324  gravityview()->log->error( '$text is not a string.', array( 'data' => $text ) );
325  return $text;
326  }
327 
328  /**
329  * @filter `gravityview_do_replace_variables` Turn off merge tag variable replacements.\n
330  * Useful where you want to process variables yourself. We do this in the Math Extension.
331  * @since 1.13
332  *
333  * @param[in,out] boolean $do_replace_variables True: yes, replace variables for this text; False: do not replace variables.
334  * @param[in] string $text Text to replace variables in
335  * @param[in] array $form GF Form array
336  * @param[in] array $entry GF Entry array
337  */
338  $do_replace_variables = apply_filters( 'gravityview/merge_tags/do_replace_variables', true, $text, $form, $entry );
339 
340  if ( strpos( $text, '{' ) === false || ! $do_replace_variables ) {
341  return $text;
342  }
343 
344  /**
345  * Make sure the required keys are set for GFCommon::replace_variables
346  *
347  * @internal Reported to GF Support on 12/3/2016
348  * @internal Fixed $form['title'] in Gravity Forms
349  * @see https://github.com/gravityforms/gravityforms/pull/27/files
350  */
351  $form['title'] = isset( $form['title'] ) ? $form['title'] : '';
352  $form['id'] = isset( $form['id'] ) ? $form['id'] : '';
353  $form['fields'] = isset( $form['fields'] ) ? $form['fields'] : array();
354 
355  return GFCommon::replace_variables( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format, $aux_data );
356  }
357 
358  /**
359  * Run GravityView filters when using GFCommon::replace_variables()
360  *
361  * Instead of adding multiple hooks, add all hooks into this one method to improve speed
362  *
363  * @since 1.8.4
364  *
365  * @param string $text Text to replace
366  * @param array|bool $form Gravity Forms form array. When called inside {@see GFCommon::replace_variables()} (now deprecated), `false`
367  * @param array|bool $entry Entry array. When called inside {@see GFCommon::replace_variables()} (now deprecated), `false`
368  * @param bool $url_encode Whether to URL-encode output
369  * @param bool $esc_html Whether to apply `esc_html()` to output
370  *
371  * @return mixed
372  */
373  public static function replace_gv_merge_tags( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
374 
375  if ( '' === $text ) {
376  return $text;
377  }
378 
379  /**
380  * This prevents the gform_replace_merge_tags filter from being called twice, as defined in:
381  * @see GFCommon::replace_variables()
382  * @see GFCommon::replace_variables_prepopulate()
383  * @todo Remove eventually: Gravity Forms fixed this issue in 1.9.14
384  */
385  if ( false === $form ) {
386  return $text;
387  }
388 
389  $text = self::replace_get_variables( $text, $form, $entry, $url_encode );
390 
391  $text = self::replace_current_post( $text, $form, $entry, $url_encode, $esc_html );
392 
393  $text = self::replace_entry_link( $text, $form, $entry, $url_encode, $esc_html );
394 
395  return $text;
396  }
397 
398  /**
399  * Add a {gv_entry_link} Merge Tag, alias of [gv_entry_link] shortcode in {gv_entry_link:[post id]:[action]} format
400  *
401  * @param string $original_text Text to replace
402  * @param array $form Gravity Forms form array
403  * @param array $entry Entry array
404  * @param bool $url_encode Whether to URL-encode output
405  * @param bool $esc_html Indicates if the esc_html function should be applied.
406  *
407  * @return string Original text, if no {gv_entry_link} Merge Tags found, otherwise text with Merge Tags replaced
408  */
409  public static function replace_entry_link( $original_text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
410 
411  // Is there is {gv_entry_link} or {gv_entry_link:[post id]} or {gv_entry_link:[post id]:[action]} merge tag?
412  preg_match_all( "/{gv_entry_link(?:\:(\d+)\:?(.*?))?}/ism", $original_text, $matches, PREG_SET_ORDER );
413 
414  if( empty( $matches ) ) {
415  return $original_text;
416  }
417 
418  if ( ! class_exists( 'GravityView_Entry_Link_Shortcode' ) ) {
419  gravityview()->log->error( 'GravityView_Entry_Link_Shortcode not found' );
420  return $original_text;
421  }
422 
423  $Shortcode = new GravityView_Entry_Link_Shortcode;
424 
425  $return = $original_text;
426 
427  /**
428  * @param array $match {
429  * $match[0] Full tag
430  * $match[1] Post ID (optional)
431  * $match[2] Action (optional)
432  * }
433  */
434  foreach ( $matches as $match ) {
435  $full_tag = $match[0];
436 
437  $link_args = array(
438  'return' => 'url',
439  'entry_id' => $entry['id'],
440  'post_id' => \GV\Utils::get( $match, 1, null ),
441  'action' => \GV\Utils::get( $match, 2, 'read' ),
442  );
443 
444  $entry_link = $Shortcode->read_shortcode( $link_args, null, 'gv_entry_link_merge_tag' );
445 
446  if( $url_encode ) {
447  $entry_link = urlencode( $entry_link );
448  }
449 
450  if ( $esc_html ) {
451  $entry_link = esc_html( $entry_link );
452  }
453 
454  $return = str_replace( $full_tag, $entry_link, $return );
455  }
456 
457  return $return;
458  }
459 
460  /**
461  * Format Merge Tags using GVCommon::format_date()
462  *
463  * @uses GVCommon::format_date()
464  *
465  * @see https://docs.gravityview.co/article/331-date-created-merge-tag for documentation
466  *
467  * @param string $date_created The Gravity Forms date created format
468  * @param string $property Any modifiers for the merge tag (`human`, `format:m/d/Y`)
469  *
470  * @return int|string If timestamp requested, timestamp int. Otherwise, string output.
471  */
472  public static function format_date( $date_created = '', $property = '' ) {
473 
474  // Expand all modifiers, skipping escaped colons. str_replace worked better than preg_split( "/(?<!\\):/" )
475  $exploded = explode( ':', str_replace( '\:', '|COLON|', $property ) );
476 
477  $atts = array(
478  'format' => self::get_format_from_modifiers( $exploded, false ),
479  'human' => in_array( 'human', $exploded ), // {date_created:human}
480  'diff' => in_array( 'diff', $exploded ), // {date_created:diff}
481  'raw' => in_array( 'raw', $exploded ), // {date_created:raw}
482  'timestamp' => in_array( 'timestamp', $exploded ), // {date_created:timestamp}
483  'time' => in_array( 'time', $exploded ), // {date_created:time}
484  );
485 
486  $formatted_date = GVCommon::format_date( $date_created, $atts );
487 
488  return $formatted_date;
489  }
490 
491  /**
492  * If there is a `:format` modifier in a merge tag, grab the formatting
493  *
494  * The `:format` modifier should always have the format follow it; it's the next item in the array
495  * In `foo:format:bar`, "bar" will be the returned format
496  *
497  * @since 1.16
498  *
499  * @param array $exploded Array of modifiers with a possible `format` value
500  * @param string $backup The backup value to use, if not found
501  *
502  * @return string If format is found, the passed format. Otherwise, the backup.
503  */
504  private static function get_format_from_modifiers( $exploded, $backup = '' ) {
505 
506  $return = $backup;
507 
508  $format_key_index = array_search( 'format', $exploded );
509 
510  // If there's a "format:[php date format string]" date format, grab it
511  if ( false !== $format_key_index && isset( $exploded[ $format_key_index + 1 ] ) ) {
512  // Return escaped colons placeholder
513  $return = str_replace( '|COLON|', ':', $exploded[ $format_key_index + 1 ] );
514  }
515 
516  return $return;
517  }
518 
519  /**
520  * Add a {current_post} Merge Tag for information about the current post (in the loop or singular)
521  *
522  * {current_post} is replaced with the current post's permalink by default, when no modifiers are passed.
523  * Pass WP_Post properties as :modifiers to access.
524  *
525  * {current_post} is the same as {embed_post}, except:
526  *
527  * - Adds support for {current_post:permalink}
528  * - Works on post archives, as well as singular
529  *
530  * @see https://www.gravityhelp.com/documentation/article/merge-tags/#embed-post for examples
531  * @see GFCommon::replace_variables_prepopulate - Code is there for {custom_field} and {embed_post} Merge Tags
532  *
533  * @param string $original_text Text to replace
534  * @param array $form Gravity Forms form array
535  * @param array $entry Entry array
536  * @param bool $url_encode Whether to URL-encode output
537  * @param bool $esc_html Indicates if the esc_html function should be applied.
538  *
539  * @return string Original text, if no {current_post} Merge Tags found, otherwise text with Merge Tags replaced
540  */
541  public static function replace_current_post( $original_text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
542 
543  $return = $original_text;
544 
545  // Is there a {current_post} or {current_post:[xyz]} merge tag?
546  preg_match_all( "/{current_post(:(.*?))?}/ism", $original_text, $matches, PREG_SET_ORDER );
547 
548  // If there are no matches OR the Entry `created_by` isn't set or is 0 (no user)
549  if ( empty( $matches ) ) {
550  return $original_text;
551  }
552 
553  $current_post = get_post();
554 
555  // WP_Error, arrays and NULL aren't welcome here.
556  if ( ! $current_post || ! is_a( $current_post, 'WP_Post' ) ) {
557  return $original_text;
558  }
559 
560  foreach ( (array) $matches as $match ) {
561  $full_tag = $match[0];
562  $modifier = \GV\Utils::get( $match, 2, 'permalink' );
563 
564  $replacement = false;
565 
566  if ( 'permalink' === $modifier ) {
567  $replacement = get_permalink( $current_post );
568  } elseif ( isset( $current_post->{$modifier} ) ) {
569  /** @see WP_Post Post properties */
570  $replacement = $current_post->{$modifier};
571  }
572 
573  if ( $replacement ) {
574 
575  if ( $esc_html ) {
576  $replacement = esc_html( $replacement );
577  }
578 
579  if( $url_encode ) {
580  $replacement = urlencode( $replacement );
581  }
582 
583  $return = str_replace( $full_tag, $replacement, $return );
584  }
585  }
586 
587  return $return;
588  }
589 
590  /**
591  * Allow passing variables via URL to be displayed in Merge Tags
592  *
593  * Works with `[gvlogic]`:
594  * [gvlogic if="{get:example}" is="false"]
595  * ?example=false
596  * [else]
597  * ?example wasn't "false". It's {get:example}!
598  * [/gvlogic]
599  *
600  * Supports passing arrays:
601  * URL: `example[]=Example+One&example[]=Example+(with+comma)%2C+Two`
602  * Merge Tag: `{get:example}`
603  * Output: `Example One, Example (with comma), Two`
604  *
605  * @since 1.15
606  * @param string $text Text to replace
607  * @param array $form Gravity Forms form array
608  * @param array $entry Entry array
609  * @param bool $url_encode Whether to URL-encode output
610  *
611  * @return string Original text, if no Merge Tags found, otherwise text with Merge Tags replaced
612  */
613  public static function replace_get_variables( $text, $form = array(), $entry = array(), $url_encode = false ) {
614 
615  // Is there is {get:[xyz]} merge tag?
616  preg_match_all( "/{get:(.*?)}/ism", $text, $matches, PREG_SET_ORDER );
617 
618  // If there are no matches OR the Entry `created_by` isn't set or is 0 (no user)
619  if( empty( $matches ) ) {
620  return $text;
621  }
622 
623  foreach ( $matches as $match ) {
624 
625  $full_tag = $match[0];
626  $property = $match[1];
627 
628  $value = stripslashes_deep( \GV\Utils::_GET( $property ) );
629 
630  /**
631  * @filter `gravityview/merge_tags/get/glue/` Modify the glue used to convert an array of `{get}` values from an array to string
632  * @since 1.15
633  * @param[in,out] string $glue String used to `implode()` $_GET values Default: ', '
634  * @param[in] string $property The current name of the $_GET parameter being combined
635  */
636  $glue = apply_filters( 'gravityview/merge_tags/get/glue/', ', ', $property );
637 
638  $value = is_array( $value ) ? implode( $glue, $value ) : $value;
639 
640  $value = $url_encode ? urlencode( $value ) : $value;
641 
642  /**
643  * @filter `gravityview/merge_tags/get/esc_html/{url parameter name}` Disable esc_html() from running on `{get}` merge tag
644  * By default, all values passed through URLs will be escaped for security reasons. If for some reason you want to
645  * pass HTML in the URL, for example, you will need to return false on this filter. It is strongly recommended that you do
646  * not disable this filter.
647  * @since 1.15
648  * @param bool $esc_html Whether to esc_html() the value. Default: `true`
649  */
650  $esc_html = apply_filters('gravityview/merge_tags/get/esc_html/' . $property, true );
651 
652  $value = $esc_html ? esc_html( $value ) : $value;
653 
654  /**
655  * @filter `gravityview/merge_tags/get/esc_html/{url parameter name}` Modify the value of the `{get}` replacement before being used
656  * @param[in,out] string $value Value that will replace `{get}`
657  * @param[in] string $text Text that contains `{get}` (before replacement)
658  * @param[in] array $form Gravity Forms form array
659  * @param[in] array $entry Entry array
660  */
661  $value = apply_filters('gravityview/merge_tags/get/value/' . $property, $value, $text, $form, $entry );
662 
663  $text = str_replace( $full_tag, $value, $text );
664  }
665 
666  unset( $value, $glue, $matches );
667 
668  return $text;
669  }
670 }
671 
static replace_current_post( $original_text, $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
Add a {current_post} Merge Tag for information about the current post (in the loop or singular) ...
static replace_gv_merge_tags( $text, $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
Run GravityView filters when using GFCommon::replace_variables()
static get_format_from_modifiers( $exploded, $backup='')
If there is a :format modifier in a merge tag, grab the formatting.
if(gv_empty( $field['value'], false, false)) $format
Enhance Gravity Forms&#39; merge tag functionality by adding additional merge tags.
static modifier_strings( $raw_value, $matches, $value='', $field=null)
Process strings with common PHP string manipulations.
static replace_get_variables( $text, $form=array(), $entry=array(), $url_encode=false)
Allow passing variables via URL to be displayed in Merge Tags.
static replace_variables( $text, $form=array(), $entry=array(), $url_encode=false, $esc_html=true, $nl2br=true, $format='html', $aux_data=array())
Alias for GFCommon::replace_variables()
$merge_tag
Merge tag is already generated by the class.
Definition: widget-poll.php:14
gravityview()
Definition: _stubs.php:26
static maybe_urlencode( $field=false, $value='')
GF 2.3 adds GF_Field::get_modifers(), which allows us to check if a field has urlencode applied to it...
get( $key, $default=null)
Retrieve a setting.
static modifier_maxwords( $raw_value, $matches, $field=null)
Trim the Merge Tag&#39;s length in words.
static format_date( $date_string='', $args=array())
Allow formatting date and time based on GravityView standards.
static modifier_timestamp( $raw_value, $matches)
Convert Date field values to timestamp int.
static format_date( $date_created='', $property='')
Format Merge Tags using GVCommon::format_date()
static process_modifiers( $value, $merge_tag, $modifier, $field, $raw_value)
Process custom GravityView modifiers for Merge Tags.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
$entry
Definition: notes.php:27
static replace_entry_link( $original_text, $form=array(), $entry=array(), $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]:[acti...
add_hooks()
Tap in to gform_replace_merge_tags to add merge tags.
static modifier_explode( $raw_value, $matches, $value, $field=null)
Convert JSON or CSV values into space-separated string.
$field
Definition: gquiz_grade.php:11
new GravityView_Entry_Link_Shortcode