The gform_helpscout_conversation Gravity Forms PHP filter allows you to modify the Help Scout conversation before it’s created.
Usage
To apply this filter to all forms:
add_filter('gform_helpscout_conversation', 'your_function_name', 10, 4);
To target a specific form, append the form ID to the hook name:
add_filter('gform_helpscout_conversation_1', 'your_function_name', 10, 4);
Parameters
- $conversation (array): Help Scout Conversation object.
- $feed (Feed Object): Current feed.
- $entry (Entry Object): Current entry.
- $form (Form Object): Current form.
More information
See Gravity Forms Docs: gform_helpscout_conversation
Examples
Change the conversation subject
This example changes the conversation subject to “Test Subject”:
add_filter('gform_helpscout_conversation', 'change_conversation', 10, 4); function change_conversation($conversation, $feed, $entry, $form) { $conversation['subject'] = 'Test Subject'; return $conversation; }
Attach a file created from a Paragraph field value
This example attaches a file created from a Paragraph field value to the conversation:
add_filter('gform_helpscout_conversation', function($conversation, $feed, $entry) { $report = rgar($entry, '28'); // Get the field value. if (!empty($report)) { // Attach the file to the first thread (index 0 in the array). $conversation['threads'][0]['attachments'][] = array( 'fileName' => 'system-report.txt', 'mimeType' => 'text/plain', 'data' => base64_encode($report), ); } return $conversation; }, 10, 3);
Add custom field
This example adds a custom field to the Help Scout conversation:
add_filter('gform_helpscout_conversation', function($conversation, $feed, $entry, $form) { $conversation['fields'][] = array( 'id' => 19680, // Custom field ID from Help Scout. 'value' => gf_helpscout()->get_field_value($form, $entry, '4'), // Get value from form field ID 4. ); return $conversation; }, 10, 4);
Placement
Place this code in the functions.php
file of your active theme.
Since
This filter was added in the Gravity Forms HelpScout add-on version 1.6.
Source Code
This filter is located in GFHelpScout::process_feed() in class-gf-helpscout.php
.