Using Gravity Forms ‘gform_enable_shortcode_notification_message’ PHP action

The gform_enable_shortcode_notification_message filter in Gravity Forms allows you to disable the notification message defined in the shortcode.

Usage

add_filter('gform_enable_shortcode_notification_message', 'your_function_name', 10, 2);

Parameters

  • true (bool): Whether the notification message shortcode should be used.
  • $form (array): The Form Object.
  • $lead (array): The Entry Object.

More information

See Gravity Forms Docs: gform_enable_shortcode_notification_message

Examples

Disabling notification message

This example disables the notification message for a specific form with the ID 1:

function disable_notification_message($enabled, $form) {
    if ($form['id'] == 1) {
        return false;
    }
    return $enabled;
}
add_filter('gform_enable_shortcode_notification_message', 'disable_notification_message', 10, 2);

Enable notification message for specific lead status

This example enables the notification message only for leads with a specific status:

function enable_notification_message_for_status($enabled, $form, $lead) {
    if ($lead['status'] == 'approved') {
        return true;
    }
    return $enabled;
}
add_filter('gform_enable_shortcode_notification_message', 'enable_notification_message_for_status', 10, 3);

Disable notification message for specific form field value

This example disables the notification message if the value of a specific form field is “No”:

function disable_notification_message_for_field_value($enabled, $form, $lead) {
    if ($lead[2] == 'No') { // Field ID is 2
        return false;
    }
    return $enabled;
}
add_filter('gform_enable_shortcode_notification_message', 'disable_notification_message_for_field_value', 10, 3);

Enable notification message based on user role

This example enables the notification message only for users with the “administrator” role:

function enable_notification_message_for_user_role($enabled, $form, $lead) {
    $user = wp_get_current_user();
    if (in_array('administrator', $user->roles)) {
        return true;
    }
    return $enabled;
}
add_filter('gform_enable_shortcode_notification_message', 'enable_notification_message_for_user_role', 10, 3);

Disable notification message after a specific date

This example disables the notification message for form submissions after a specific date:

function disable_notification_message_after_date($enabled, $form, $lead) {
    $date_limit = '2023-01-01';
    if (strtotime($lead['date_created']) > strtotime($date_limit)) {
        return false;
    }
    return $enabled;
}
add_filter('gform_enable_shortcode_notification_message', 'disable_notification_message_after_date', 10, 3);