gform_disable_notification

Description

Use this filter to disable admin and user notification emails.

Usage

add_filter( 'gform_disable_notification', 'your_function_name', 10, 4 );

You can also specify this per form by adding the form id after the hook name.

add_filter( 'gform_disable_notification_6', 'your_function_name', 10, 4 );

Parameters

  • $is_disabled bool

    Variable to be filtered. Set it to true to disable notifications

  • $notification array

    Current Notification array

  • $form Form Object

    Current form.

  • $entry Entry Object

    Current Entry array

  • $data array

    Array of data which can be used in the notifications via the generic {object:property} merge tag. Defaults to empty array. Since: 2.3.6.6.

Examples

1. Disable ALL Notifications

This example disables admin and user notifications for all forms

add_filter( 'gform_disable_notification', 'disable_notification', 10, 4 );
function disable_notification( $is_disabled, $notification, $form, $entry ) {
    return true;
}

2. Disable a notification based on a field

This example shows you how to disable a notification conditionally based on a field of the entry. This can help you in situations where conditional logic can’t be used (e.g. To send a notification only if an upload field was not used).

add_filter( 'gform_disable_notification', 'disable_notification_by_field', 10, 4 );
function disable_notification_by_field( $is_disabled, $notification, $form, $entry ) {

	$field_to_check = rgar( $entry, '1' ); // Replace 1 by your field id number

	// Replace User Notification by your notification name.
	if ( $notification['name'] == 'User Notification' && ! empty( $field_to_check ) ) { // Disable notification only if $filed_to_check is not empty.
		return true;
	}

	return $is_disabled;
}

3. Update from gform_disable_user_notification

This example shows you how to update your code from the deprecated gform_disable_user_notification hook

add_filter( 'gform_disable_notification', 'disable_notification', 10, 4 );
function disable_notification( $is_disabled, $notification, $form, $entry ) {

    //There is no concept of user notifications anymore, so we will need to disable notifications based on other criteria such as name
    if ( $notification['name'] == 'User Notification' ) {
        return true;
    }

    return $is_disabled;
}

4. Update from gform_disable_admin_notification

This example shows you how to update your code from the deprecated gform_disable_admin_notification hook

add_filter( 'gform_disable_notification', 'disable_notification', 10, 4 );
function disable_notification( $is_disabled, $notification, $form, $entry ) {

    //There is no concept of admin notifications anymore, so we will need to disable notifications based on other criteria such as name
    if ( $notification['name'] == 'Admin Notification' ) {
        return true;
    }

    return $is_disabled;
}

5. Disable based on payment/subscription event

This example shows how a notification assigned to a payment or subscription event could be disabled based on the event properties.

add_filter( 'gform_disable_notification', function( $is_disabled, $notification, $form, $entry, $data ) {
	if ( isset( $data['payment_action'] ) && empty( $data['payment_action']['amount'] ) ) {
		$is_disabled = true;
	}

	return $is_disabled;
}, 10, 5 );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GFAPI::send_notifications() in includes/api.php