The gform_pre_process_async_notifications Gravity Forms action hook allows you to perform custom actions just before the background processor sends queued notifications.
Usage
Add the following code to use the action hook:
add_action('gform_pre_process_async_notifications', 'your_function_name', 10, 5);
Parameters
- $event (string): The event the notifications are to be sent for. Default is
form_submission
. - $notifications (array): An array containing the IDs of the notifications to be sent.
- $form (Form Object): The form currently being processed.
- $entry (Entry Object): The entry currently being processed.
- $data (array): An array of data which can be used in the notifications via the generic
{object:property}
merge tag. Defaults to empty array.
More information
See Gravity Forms Docs: gform_pre_process_async_notifications
This action hook was added in Gravity Forms v2.7.1.
Examples
Modify Notification Email Subject
To modify the notification email subject before it’s sent, use the following code:
function modify_email_subject($event, $notifications, $form, $entry, $data) { foreach ($notifications as $notification_id => $notification) { $notifications[$notification_id]['subject'] = 'Custom Subject: ' . $notification['subject']; } return $notifications; } add_action('gform_pre_process_async_notifications', 'modify_email_subject', 10, 5);
Add Custom Data to Notification
Add custom data to the notification that can be used as a merge tag:
function add_custom_data($event, $notifications, $form, $entry, $data) { $data['custom_data'] = 'Your custom data here.'; return $data; } add_action('gform_pre_process_async_notifications', 'add_custom_data', 10, 5);
Log Notifications Before Sending
Log notification details before they are sent:
function log_notifications($event, $notifications, $form, $entry, $data) { error_log(print_r($notifications, true)); } add_action('gform_pre_process_async_notifications', 'log_notifications', 10, 5);
Conditionally Send Notifications
Send notifications only if a specific condition is met:
function conditional_notifications($event, &$notifications, $form, $entry, $data) { if ($entry['1'] != 'send') { $notifications = array(); } } add_action('gform_pre_process_async_notifications', 'conditional_notifications', 10, 5);
Modify Notification Recipient
Change the recipient email address for notifications:
function modify_recipient($event, $notifications, $form, $entry, $data) { foreach ($notifications as $notification_id => $notification) { $notifications[$notification_id]['to'] = '[email protected]'; } return $notifications; } add_action('gform_pre_process_async_notifications', 'modify_recipient', 10, 5);