Using Gravity Forms ‘gform_pre_notification_activated’ PHP action

The gform_pre_notification_activated action is triggered before a notification is activated, allowing further actions to be performed.

Usage

add_action('gform_pre_notification_activated', 'my_custom_function', 10, 2);

Parameters

  • $notification_id (int): The ID of the notification being activated.
  • $form (array): The form object.

More information

See Gravity Forms Docs: gform_pre_notification_activated

This action hook is located in forms_model.php.

Examples

Modify the notification email subject before activation

Explanation: Modify the email subject of a specific notification before it’s activated.

function modify_email_subject($notification_id, $form) {
    if ($notification_id == 5) { // Check for a specific notification ID
        $form['notifications'][$notification_id]['subject'] = "New custom subject";
    }
}
add_action('gform_pre_notification_activated', 'modify_email_subject', 10, 2);

Log notification activation

Explanation: Log the notification ID and form ID when a notification is activated.

function log_notification_activation($notification_id, $form) {
    error_log("Notification ID: {$notification_id} activated for Form ID: {$form['id']}");
}
add_action('gform_pre_notification_activated', 'log_notification_activation', 10, 2);

Disable a specific notification

Explanation: Prevent a specific notification from being activated.

function disable_specific_notification($notification_id, $form) {
    if ($notification_id == 7) { // Check for a specific notification ID
        remove_action('gform_pre_notification_activated', 'disable_specific_notification');
    }
}
add_action('gform_pre_notification_activated', 'disable_specific_notification', 10, 2);

Send a custom email before a notification is activated

Explanation: Send a custom email to the admin before the notification is activated.

function send_custom_email($notification_id, $form) {
    $to = get_option('admin_email');
    $subject = "Notification {$notification_id} about to be activated";
    $message = "Notification with ID {$notification_id} is about to be activated for Form ID {$form['id']}.";
    wp_mail($to, $subject, $message);
}
add_action('gform_pre_notification_activated', 'send_custom_email', 10, 2);

Change the notification “to” email address

Explanation: Change the “to” email address of a specific notification before it’s activated.

function change_to_email_address($notification_id, $form) {
    if ($notification_id == 6) { // Check for a specific notification ID
        $form['notifications'][$notification_id]['to'] = '[email protected]';
    }
}
add_action('gform_pre_notification_activated', 'change_to_email_address', 10, 2);