Using Gravity Forms ‘gform_post_process_async_notifications’ PHP filter

The gform_post_process_async_notifications action hook allows you to perform custom actions right after the background processor sends queued notifications.

Usage

To use the action hook for all notifications sent by the background processor:

add_action('gform_post_process_async_notifications', 'your_function_name', 10, 5);

Parameters

  • $event (string) – The event the notifications were sent for. Default is form_submission.
  • $notifications (array) – An array containing the IDs of processed notifications.
  • $form (Form Object) – The form that was processed.
  • $entry (Entry Object) – The entry that was processed.
  • $data (array) – An array of data which can be used in the notifications via the generic {object:property} merge tag. Defaults to an empty array.

More information

See Gravity Forms Docs: gform_post_process_async_notifications

This action hook was added in Gravity Forms v2.7.1.

The source code for this action hook is located in \Gravity_Forms\Gravity_Forms\Async\GF_Notifications_Processor::task() in /includes/async/class-gf-notifications-processor.php.

Examples

Log Notifications Sent

Log the sent notifications to a custom log file.

add_action('gform_post_process_async_notifications', 'log_sent_notifications', 10, 5);
function log_sent_notifications($event, $notifications, $form, $entry, $data) {
    // Log the sent notifications
    foreach ($notifications as $notification_id) {
        error_log("Notification ID: {$notification_id} sent for event: {$event}\n", 3, 'notifications_sent.log');
    }
}

Send Custom Email After Notifications

Send a custom email to the admin after notifications are sent.

add_action('gform_post_process_async_notifications', 'send_custom_email_after_notifications', 10, 5);
function send_custom_email_after_notifications($event, $notifications, $form, $entry, $data) {
    // Send custom email to admin
    $to = '[email protected]';
    $subject = "Notifications sent for event: {$event}";
    $message = 'The following notifications were sent:';
    foreach ($notifications as $notification_id) {
        $message .= "\nNotification ID: {$notification_id}";
    }
    wp_mail($to, $subject, $message);
}

Add Entry Note After Notifications

Add an entry note after notifications are sent.

add_action('gform_post_process_async_notifications', 'add_entry_note_after_notifications', 10, 5);
function add_entry_note_after_notifications($event, $notifications, $form, $entry, $data) {
    // Add entry note
    $note = "Notifications sent for event: {$event}\n";
    foreach ($notifications as $notification_id) {
        $note .= "Notification ID: {$notification_id}\n";
    }
    GFFormsModel::add_note($entry['id'], $form['id'], 0, $note);
}