Replace field merge tags in administrative field’s default value
Advanced Merge Tags has a feature that allows replacement of field merge tags in the for text fields that have Administrative visibility after submission of the form.
This feature can be activated in the global plugin settings:
By default this works for Text fields only. The field merge tags should be added to the default value and the visibility should be administrative:
Modify the supported field types
The gwp_amt_replace_admin_field_variables
filter allows to modify the list of field types
The filter has the following parameters:
$field_types
(array): an array of field types that should have field merge tags replaced before being saved to the database. By default, it only includes thetext
field type.$value
(string): the input value of the field.$lead
(array): the current entry object.$field
(GF_Field): the current field object.$form
(array): the current form object.
Developers can use this filter to add or remove field types from the $field_types
array.
For example, you could add this snippet to your theme’s functions.php to add the textarea
field type to the list of field types that should have field merge tags replaced before being saved to the database:
add_filter( 'gwp_amt_replace_admin_field_variables', function( $field_types, $value, $lead, $field, $form ) {
$field_types[] = 'textarea';
return $field_types;
}, 10, 5 );