Skip to content

Commit df43d15

Browse files
authored
gw-advanced-merge-tags.php: Added support for base64 field merge tag modifier.
* Added support for `base64` field merge tag modifier. * Updated the header.
1 parent 80fa6c4 commit df43d15

File tree

1 file changed

+70
-28
lines changed

1 file changed

+70
-28
lines changed

gravity-forms/gw-advanced-merge-tags.php

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,82 @@
22
/**
33
* Gravity Wiz // Gravity Forms // Advanced Merge Tags
44
*
5-
* Adds support for several advanced merge tags:
5+
* Adds support for advanced Gravity Forms merge tags and field modifiers.
6+
*
7+
* Advanced merge tags:
68
* + post:id=xx&prop=xxx
7-
* retrieve the desired property of the specified post (by ID)
9+
* Retrieve the desired property of the specified post (by ID).
810
* + post_meta:id=xx&meta_key=xxx
9-
* retrieve the desired post meta value from the specified post and meta key
11+
* custom_field:id=xx&meta_key=xxx
12+
* Retrieve the desired post meta value from the specified post and meta key.
13+
* + source_post:xxx
14+
* Retrieve a property from the source post that displayed the form (when save_source_post_id is enabled).
15+
* + entry:id=xx&prop=xxx
16+
* Retrieve a core entry property (e.g. id, date_created, payment_status).
17+
* + entry_meta:id=xx&meta_key=xxx
18+
* Retrieve an entry meta value for the specified entry and meta key.
19+
*
20+
* Value helpers:
1021
* + get() modifier
11-
* retrieve the desired property from the query string ($_GET)
12-
* Example: post_meta:id=get(xx)&meta_key=xxx
22+
* Retrieve a value from the query string ($_GET).
23+
* Example: post_meta:id=get(pid)&meta_key=xxx
1324
* + post() modifier
14-
* retrieve the enclosed property from the $_POST
15-
* Example: post_meta:id=post(xx)&meta_key=xxx
16-
* + get:xxx
17-
* retrieve property from query string
18-
* + HTML fields
19-
* {HTML:3}
20-
* {all_fields:allowHtmlFields}
25+
* Retrieve a value from the current POST payload ($_POST).
26+
* Example: post_meta:id=post(pid)&meta_key=xxx
27+
*
28+
* GET merge tags:
29+
* + {get:foo}
30+
* Retrieve the "foo" query string parameter.
31+
* + {get:foo[whitelist=one,two,three]}
32+
* Only output the value when it matches the whitelist.
33+
*
34+
* Dynamic population:
35+
* + Supports using advanced merge tags in "Allow field to be populated dynamically" parameter names.
36+
* Example: a field with parameter name "{post:id=get(pid)&prop=post_title}" will be pre-populated accordingly.
2137
*
22-
* Coming soon...
23-
* + {Address:1}
24-
* Output values from all Address inputs.
25-
* + {Name:1}
26-
* Output values from all Name inputs.
27-
* + {Date:1:mdy}
28-
* Format date field output: https://gist.github.com/spivurno/f1fb2f0f3650d63acfb5ed644296abda
38+
* HTML fields:
39+
* + {HTML:3}
40+
* Output the content of HTML field ID 3.
41+
* + {all_fields:allowHtmlFields}
42+
* Include HTML field content when outputting {all_fields}.
2943
*
30-
* Use Cases
44+
* Field modifiers (used as :modifier on merge tags/fields):
45+
* + :wordcount
46+
* Return the word count for the field value.
47+
* + :urlencode
48+
* URL-encode the value.
49+
* + :rawurlencode
50+
* Raw URL-encode the value.
51+
* + :uppercase
52+
* Convert the value to uppercase.
53+
* + :lowercase
54+
* Convert the value to lowercase.
55+
* + :capitalize
56+
* Capitalize each word in the value.
57+
* + :mask
58+
* Mask the value, preserving only the first and last character. Special handling for email addresses.
59+
* + :abbr
60+
* For Address fields, return the two-letter country code of the selected country.
61+
* + :selected[0]
62+
* For Checkbox and Multi Select fields, return the selected choice at the given zero-based index.
63+
* + :gravatar[format=url,size=64,default=...]
64+
* For Email fields, output a Gravatar URL or image tag based on the email address.
65+
* + :base64
66+
* Return the base64-encoded value.
3167
*
32-
* + You have a multiple realtors each represented by their own WordPress page. On each page is a "Contact this Realtor"
33-
* link. The user clicks the link and is directed to a contact form. Rather than creating a host of different
34-
* contact forms for each realtor, you can use this snippet to populate a HTML field with a bit of text like:
35-
* "You are contacting realtor Bob Smith" except instead of Bob Smith, you would use "{post:id=pid&prop=post_title}.
36-
* In this example, "pid" would be passed via the query string from the contact link and "Bob Smith" would be the
37-
* "post_title" of the post the user is coming from.
68+
* Example use case:
69+
*
70+
* You have multiple realtors, each represented by their own WordPress page. On each page is a
71+
* "Contact this Realtor" link that passes the realtor page ID as "pid" in the query string. A
72+
* single contact form can then display:
73+
*
74+
* "You are contacting realtor {post:id=get(pid)&prop=post_title}."
75+
*
76+
* This retrieves the post_title (e.g. "Bob Smith") of the realtor page the visitor came from.
3877
*
3978
* Plugin Name: Gravity Forms Advanced Merge Tags
4079
* Plugin URI: https://gravitywiz.com
41-
* Description: Provides a host of new ways to work with Gravity Forms merge tags.
80+
* Description: Provides a host of new ways to work with Gravity Forms merge tags and field modifiers.
4281
* Version: 1.6
4382
* Author: Gravity Wiz
4483
* Author URI: https://gravitywiz.com/
@@ -512,6 +551,9 @@ public function handle_field_modifiers( $value, $input_id, $modifier, $field, $r
512551
}
513552

514553
return $this->generate_gravatar($value, $modifiers);
554+
case 'base64':
555+
return base64_encode( $value );
556+
break;
515557
}
516558
}
517559

@@ -527,7 +569,7 @@ public function mask_value( $value ) {
527569

528570
public function parse_modifiers( $modifiers_str ) {
529571

530-
preg_match_all( '/([a-z_]+)(?:(?:\[(.+?)\])|,?)/i', $modifiers_str, $modifiers, PREG_SET_ORDER );
572+
preg_match_all( '/([a-z0-9_]+)(?:(?:\[(.+?)\])|,?)/i', $modifiers_str, $modifiers, PREG_SET_ORDER );
531573
$parsed = array();
532574

533575
foreach ( $modifiers as $modifier ) {

0 commit comments

Comments
 (0)