Description
Filter the conversation before it is created in Help Scout.
Usage
The following would apply 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. (format: gform_helpscout_conversation_FORMID)
add_filter( 'gform_helpscout_conversation_1', 'your_function_name', 10, 4 );
Parameters
- $conversation array
-
$feed Feed Object
Current feed.
-
$entry Entry Object
Current entry.
-
$form Form Object
Current form.
Examples
Change the conversation 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
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 which is located at 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
The following example shows how Help Scout custom fields can be added to the 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
This code should be placed 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.